@@ -1407,7 +1407,8 @@ async def retrieve_pending_extrinsics(self) -> list:
14071407 runtime = await self .init_runtime ()
14081408
14091409 result_data = await self .rpc_request ("author_pendingExtrinsics" , [])
1410-
1410+ if "error" in result_data :
1411+ raise SubstrateRequestException (result_data ["error" ]["message" ])
14111412 extrinsics = []
14121413
14131414 for extrinsic_data in result_data ["result" ]:
@@ -2141,6 +2142,8 @@ async def get_parent_block_hash(self, block_hash) -> str:
21412142
21422143 async def _get_parent_block_hash (self , block_hash ) -> str :
21432144 block_header = await self .rpc_request ("chain_getHeader" , [block_hash ])
2145+ if "error" in block_header :
2146+ raise SubstrateRequestException (block_header ["error" ]["message" ])
21442147
21452148 if block_header ["result" ] is None :
21462149 raise SubstrateRequestException (f'Block not found for "{ block_hash } "' )
@@ -2172,15 +2175,7 @@ async def get_storage_by_key(self, block_hash: str, storage_key: str) -> Any:
21722175 response = await self .rpc_request (
21732176 "state_getStorage" , [storage_key , block_hash ]
21742177 )
2175-
2176- if "result" in response :
2177- return response .get ("result" )
2178- elif "error" in response :
2179- raise SubstrateRequestException (response ["error" ]["message" ])
2180- else :
2181- raise SubstrateRequestException (
2182- "Unknown error occurred during retrieval of events"
2183- )
2178+ return response .get ("result" )
21842179
21852180 @cached_fetcher (max_size = SUBSTRATE_RUNTIME_CACHE_SIZE )
21862181 async def get_block_runtime_info (self , block_hash : str ) -> dict :
@@ -2236,9 +2231,6 @@ async def get_block_metadata(
22362231 params = [block_hash ]
22372232 response = await self .rpc_request ("state_getMetadata" , params )
22382233
2239- if "error" in response :
2240- raise SubstrateRequestException (response ["error" ]["message" ])
2241-
22422234 if (result := response .get ("result" )) and decode :
22432235 metadata_decoder = runtime_config .create_scale_object (
22442236 "MetadataVersioned" , data = ScaleBytes (result )
@@ -2562,6 +2554,8 @@ async def get_chain_head(self) -> str:
25622554 )
25632555 ]
25642556 )
2557+ if "error" in result [0 ]:
2558+ raise SubstrateRequestException (result [0 ]["error" ]["message" ])
25652559 self .last_block_hash = result ["rpc_request" ][0 ]["result" ]
25662560 return result ["rpc_request" ][0 ]["result" ]
25672561
@@ -2690,9 +2684,6 @@ async def query_multi(
26902684 runtime = runtime ,
26912685 )
26922686
2693- if "error" in response :
2694- raise SubstrateRequestException (response ["error" ]["message" ])
2695-
26962687 result = []
26972688
26982689 storage_key_map = {s .to_hex (): s for s in storage_keys }
@@ -3044,12 +3035,7 @@ async def get_chain_finalised_head(self):
30443035
30453036 """
30463037 response = await self .rpc_request ("chain_getFinalizedHead" , [])
3047-
3048- if response is not None :
3049- if "error" in response :
3050- raise SubstrateRequestException (response ["error" ]["message" ])
3051-
3052- return response .get ("result" )
3038+ return response ["result" ]
30533039
30543040 async def _do_runtime_call_old (
30553041 self ,
@@ -3092,6 +3078,8 @@ async def _do_runtime_call_old(
30923078 [f"{ api } _{ method } " , param_data .hex (), block_hash ],
30933079 runtime = runtime ,
30943080 )
3081+ if "error" in result_data :
3082+ raise SubstrateRequestException (result_data ["error" ]["message" ])
30953083 result_vec_u8_bytes = hex_to_bytes (result_data ["result" ])
30963084 result_bytes = await self .decode_scale (
30973085 "Vec<u8>" , result_vec_u8_bytes , runtime = runtime
@@ -3185,6 +3173,8 @@ async def runtime_call(
31853173 [f"{ api } _{ method } " , param_data .hex (), block_hash ],
31863174 runtime = runtime ,
31873175 )
3176+ if "error" in result_data :
3177+ raise SubstrateRequestException (result_data ["error" ]["message" ])
31883178 output_type_string = f"scale_info::{ runtime_call_def ['output' ]} "
31893179
31903180 # Decode result
@@ -3237,6 +3227,8 @@ async def get_account_next_index(self, account_address: str) -> int:
32373227 nonce_obj = await self .rpc_request (
32383228 "account_nextIndex" , [account_address ]
32393229 )
3230+ if "error" in nonce_obj :
3231+ raise SubstrateRequestException (nonce_obj ["error" ]["message" ])
32403232 self ._nonces [account_address ] = nonce_obj ["result" ]
32413233 else :
32423234 self ._nonces [account_address ] += 1
@@ -3622,9 +3614,6 @@ async def query_map(
36223614 method = "state_getKeys" , params = [prefix , block_hash ], runtime = runtime
36233615 )
36243616
3625- if "error" in response :
3626- raise SubstrateRequestException (response ["error" ]["message" ])
3627-
36283617 result_keys = response .get ("result" )
36293618
36303619 result = []
@@ -3640,8 +3629,6 @@ async def query_map(
36403629 params = [result_keys , block_hash ],
36413630 runtime = runtime ,
36423631 )
3643- if "error" in response :
3644- raise SubstrateRequestException (response ["error" ]["message" ])
36453632 for result_group in response ["result" ]:
36463633 result = decode_query_map (
36473634 result_group ["changes" ],
@@ -3680,8 +3667,6 @@ async def query_map(
36803667 )
36813668 )
36823669 for response in all_responses :
3683- if "error" in response :
3684- raise SubstrateRequestException (response ["error" ]["message" ])
36853670 for result_group in response ["result" ]:
36863671 changes .extend (result_group ["changes" ])
36873672
@@ -3905,9 +3890,6 @@ async def result_handler(message: dict, subscription_id) -> tuple[dict, bool]:
39053890 "author_submitExtrinsic" , [str (extrinsic .data )]
39063891 )
39073892
3908- if "result" not in response :
3909- raise SubstrateRequestException (response .get ("error" ))
3910-
39113893 result = AsyncExtrinsicReceipt (
39123894 substrate = self , extrinsic_hash = response ["result" ]
39133895 )
@@ -3994,12 +3976,8 @@ async def get_block_number(self, block_hash: Optional[str] = None) -> int:
39943976 """Async version of `substrateinterface.base.get_block_number` method."""
39953977 response = await self .rpc_request ("chain_getHeader" , [block_hash ])
39963978
3997- if "error" in response :
3998- raise SubstrateRequestException (response ["error" ]["message" ])
3999-
4000- elif "result" in response :
4001- if response ["result" ]:
4002- return int (response ["result" ]["number" ], 16 )
3979+ if response ["result" ]:
3980+ return int (response ["result" ]["number" ], 16 )
40033981 raise SubstrateRequestException (
40043982 f"Unable to retrieve block number for { block_hash } "
40053983 )
0 commit comments