@@ -755,6 +755,7 @@ def __init__(
755755 ws_shutdown_timer: how long after the last connection your websocket should close
756756
757757 """
758+ super ().__init__ (type_registry , type_registry_preset , use_remote_preset )
758759 self .max_retries = max_retries
759760 self .retry_timeout = retry_timeout
760761 self .chain_endpoint = url
@@ -923,6 +924,7 @@ async def decode_scale(
923924 _attempt = 1 ,
924925 _retries = 3 ,
925926 return_scale_obj : bool = False ,
927+ block_hash : Optional [str ] = None ,
926928 runtime : Optional [Runtime ] = None ,
927929 ) -> Union [ScaleObj , Any ]:
928930 """
@@ -936,8 +938,9 @@ async def decode_scale(
936938 _attempt: the number of attempts to pull the registry before timing out
937939 _retries: the number of retries to pull the registry before timing out
938940 return_scale_obj: Whether to return the decoded value wrapped in a SCALE-object-like wrapper, or raw.
939- runtime: Optional Runtime object whose registry to use for decoding. If not specified, the currently-loaded
940- `self.runtime` will be used.
941+ block_hash: Hash of the block where the desired runtime is located. Ignored if supplying `runtime`
942+ runtime: Optional Runtime object whose registry to use for decoding. If not specified, runtime will be
943+ loaded based on the block hash specified (or latest block if no block_hash is specified)
941944
942945 Returns:
943946 Decoded object
@@ -949,8 +952,8 @@ async def decode_scale(
949952 return ss58_encode (scale_bytes , SS58_FORMAT )
950953 else :
951954 if not runtime :
952- await self ._wait_for_registry ( _attempt , _retries )
953- runtime_registry = self . runtime .registry
955+ runtime = await self .init_runtime ( block_hash = block_hash )
956+ runtime_registry = runtime .registry
954957 else :
955958 runtime_registry = runtime .registry
956959 obj = decode_by_type_string (type_string , runtime_registry , scale_bytes )
@@ -2949,13 +2952,17 @@ async def runtime_call(
29492952
29502953 # RPC request
29512954 result_data = await self .rpc_request (
2952- "state_call" , [f"{ api } _{ method } " , param_data .hex (), block_hash ]
2955+ "state_call" ,
2956+ [f"{ api } _{ method } " , param_data .hex (), block_hash ],
2957+ runtime = runtime ,
29532958 )
29542959 output_type_string = f"scale_info::{ runtime_call_def ['output' ]} "
29552960
29562961 # Decode result
29572962 result_bytes = hex_to_bytes (result_data ["result" ])
2958- result_obj = ScaleObj (await self .decode_scale (output_type_string , result_bytes ))
2963+ result_obj = ScaleObj (
2964+ await self .decode_scale (output_type_string , result_bytes , runtime = runtime )
2965+ )
29592966
29602967 return result_obj
29612968
@@ -3317,7 +3324,7 @@ async def query_map(
33173324 self .last_block_hash = block_hash
33183325 runtime = await self .init_runtime (block_hash = block_hash )
33193326
3320- metadata_pallet = self . runtime .metadata .get_metadata_pallet (module )
3327+ metadata_pallet = runtime .metadata .get_metadata_pallet (module )
33213328 if not metadata_pallet :
33223329 raise ValueError (f'Pallet "{ module } " not found' )
33233330 storage_item = metadata_pallet .get_storage_function (storage_function )
@@ -3344,8 +3351,8 @@ async def query_map(
33443351 module ,
33453352 storage_item .value ["name" ],
33463353 params ,
3347- runtime_config = self .runtime_config ,
3348- metadata = self . runtime .metadata ,
3354+ runtime_config = runtime .runtime_config ,
3355+ metadata = runtime .metadata ,
33493356 )
33503357 prefix = storage_key .to_hex ()
33513358
@@ -3360,6 +3367,7 @@ async def query_map(
33603367 response = await self .rpc_request (
33613368 method = "state_getKeysPaged" ,
33623369 params = [prefix , page_size , start_key , block_hash ],
3370+ runtime = runtime ,
33633371 )
33643372
33653373 if "error" in response :
@@ -3375,7 +3383,9 @@ async def query_map(
33753383
33763384 # Retrieve corresponding value
33773385 response = await self .rpc_request (
3378- method = "state_queryStorageAt" , params = [result_keys , block_hash ]
3386+ method = "state_queryStorageAt" ,
3387+ params = [result_keys , block_hash ],
3388+ runtime = runtime ,
33793389 )
33803390
33813391 if "error" in response :
0 commit comments