@@ -13,6 +13,7 @@ use runtime::starknet::context::BlockInfo;
13
13
use sierra_casm:: compile;
14
14
use starknet:: core:: types:: {
15
15
BlockId , ContractClass as ContractClassStarknet , FieldElement , MaybePendingBlockWithTxHashes ,
16
+ StarknetError ,
16
17
} ;
17
18
use starknet:: providers:: jsonrpc:: HttpTransport ;
18
19
use starknet:: providers:: { JsonRpcClient , Provider , ProviderError } ;
@@ -53,6 +54,19 @@ impl ForkStateReader {
53
54
}
54
55
}
55
56
57
+ #[ macro_export]
58
+ macro_rules! other_provider_error {
59
+ ( $boxed: expr ) => { {
60
+ let err_str = $boxed. deref( ) . to_string( ) ;
61
+ if err_str. contains( "error sending request for url" ) {
62
+ return Err ( StateReadError (
63
+ "Unable to reach the node. Check your internet connection and node url" . to_string( ) ,
64
+ ) ) ;
65
+ }
66
+ Err ( StateReadError ( format!( "JsonRpc provider error: {err_str}" ) ) )
67
+ } } ;
68
+ }
69
+
56
70
impl BlockInfoReader for ForkStateReader {
57
71
fn get_block_info ( & mut self ) -> StateResult < BlockInfo > {
58
72
if let Some ( cache_hit) = self . cache . get_block_info ( ) {
@@ -77,30 +91,14 @@ impl BlockInfoReader for ForkStateReader {
77
91
Ok ( MaybePendingBlockWithTxHashes :: PendingBlock ( _) ) => {
78
92
unreachable ! ( "Pending block is not be allowed at the configuration level" )
79
93
}
94
+ Err ( ProviderError :: Other ( boxed) ) => other_provider_error ! ( boxed) ,
80
95
Err ( err) => Err ( StateReadError ( format ! (
81
- "Unable to get block with tx hashes from fork, err: {err:?} "
96
+ "Unable to get block with tx hashes from fork ( {err}) "
82
97
) ) ) ,
83
98
}
84
99
}
85
100
}
86
101
87
- #[ macro_export]
88
- macro_rules! other_provider_error {
89
- ( $boxed: expr ) => { {
90
- let err_str = $boxed. deref( ) . to_string( ) ;
91
- if err_str. contains( "error sending request for url" ) {
92
- return node_connection_error( ) ;
93
- }
94
- Err ( StateReadError ( format!( "JsonRpc provider error: {err_str}" ) ) )
95
- } } ;
96
- }
97
-
98
- fn node_connection_error < T > ( ) -> StateResult < T > {
99
- Err ( StateReadError (
100
- "Unable to reach the node. Check your internet connection and node url" . to_string ( ) ,
101
- ) )
102
- }
103
-
104
102
impl StateReader for ForkStateReader {
105
103
fn get_storage_at (
106
104
& mut self ,
@@ -123,8 +121,9 @@ impl StateReader for ForkStateReader {
123
121
Ok ( value_sf)
124
122
}
125
123
Err ( ProviderError :: Other ( boxed) ) => other_provider_error ! ( boxed) ,
126
- Err ( _) => Err ( StateReadError ( format ! (
127
- "Unable to get storage at address: {contract_address:?} and key: {key:?} from fork"
124
+ Err ( ProviderError :: StarknetError ( StarknetError :: ContractNotFound ) ) => Ok ( Default :: default ( ) ) ,
125
+ Err ( x) => Err ( StateReadError ( format ! (
126
+ "Unable to get storage at address: {contract_address:?} and key: {key:?} from fork ({x})"
128
127
) ) ) ,
129
128
}
130
129
}
@@ -144,8 +143,11 @@ impl StateReader for ForkStateReader {
144
143
Ok ( nonce)
145
144
}
146
145
Err ( ProviderError :: Other ( boxed) ) => other_provider_error ! ( boxed) ,
147
- Err ( _) => Err ( StateReadError ( format ! (
148
- "Unable to get nonce at {contract_address:?} from fork"
146
+ Err ( ProviderError :: StarknetError ( StarknetError :: ContractNotFound ) ) => {
147
+ Ok ( Default :: default ( ) )
148
+ }
149
+ Err ( x) => Err ( StateReadError ( format ! (
150
+ "Unable to get nonce at {contract_address:?} from fork ({x})"
149
151
) ) ) ,
150
152
}
151
153
}
@@ -165,9 +167,12 @@ impl StateReader for ForkStateReader {
165
167
. cache_get_class_hash_at ( contract_address, class_hash) ;
166
168
Ok ( class_hash)
167
169
}
170
+ Err ( ProviderError :: StarknetError ( StarknetError :: ContractNotFound ) ) => {
171
+ Ok ( Default :: default ( ) )
172
+ }
168
173
Err ( ProviderError :: Other ( boxed) ) => other_provider_error ! ( boxed) ,
169
- Err ( _ ) => Err ( StateReadError ( format ! (
170
- "Unable to get class hash at {contract_address:?} from fork"
174
+ Err ( x ) => Err ( StateReadError ( format ! (
175
+ "Unable to get class hash at {contract_address:?} from fork ({x}) "
171
176
) ) ) ,
172
177
}
173
178
}
@@ -190,8 +195,13 @@ impl StateReader for ForkStateReader {
190
195
191
196
Ok ( contract_class)
192
197
}
198
+ Err ( ProviderError :: StarknetError ( StarknetError :: ClassHashNotFound ) ) => {
199
+ Err ( UndeclaredClassHash ( * class_hash) )
200
+ }
193
201
Err ( ProviderError :: Other ( boxed) ) => other_provider_error ! ( boxed) ,
194
- Err ( _) => Err ( UndeclaredClassHash ( * class_hash) ) ,
202
+ Err ( x) => Err ( StateReadError ( format ! (
203
+ "Unable to get compiled class at {class_hash} from fork ({x})"
204
+ ) ) ) ,
195
205
}
196
206
} ;
197
207
0 commit comments