@@ -755,6 +755,7 @@ def __init__(
755
755
ws_shutdown_timer: how long after the last connection your websocket should close
756
756
757
757
"""
758
+ super ().__init__ (type_registry , type_registry_preset , use_remote_preset )
758
759
self .max_retries = max_retries
759
760
self .retry_timeout = retry_timeout
760
761
self .chain_endpoint = url
@@ -923,6 +924,7 @@ async def decode_scale(
923
924
_attempt = 1 ,
924
925
_retries = 3 ,
925
926
return_scale_obj : bool = False ,
927
+ block_hash : Optional [str ] = None ,
926
928
runtime : Optional [Runtime ] = None ,
927
929
) -> Union [ScaleObj , Any ]:
928
930
"""
@@ -936,8 +938,9 @@ async def decode_scale(
936
938
_attempt: the number of attempts to pull the registry before timing out
937
939
_retries: the number of retries to pull the registry before timing out
938
940
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)
941
944
942
945
Returns:
943
946
Decoded object
@@ -949,8 +952,8 @@ async def decode_scale(
949
952
return ss58_encode (scale_bytes , SS58_FORMAT )
950
953
else :
951
954
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
954
957
else :
955
958
runtime_registry = runtime .registry
956
959
obj = decode_by_type_string (type_string , runtime_registry , scale_bytes )
@@ -2949,13 +2952,17 @@ async def runtime_call(
2949
2952
2950
2953
# RPC request
2951
2954
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 ,
2953
2958
)
2954
2959
output_type_string = f"scale_info::{ runtime_call_def ['output' ]} "
2955
2960
2956
2961
# Decode result
2957
2962
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
+ )
2959
2966
2960
2967
return result_obj
2961
2968
@@ -3317,7 +3324,7 @@ async def query_map(
3317
3324
self .last_block_hash = block_hash
3318
3325
runtime = await self .init_runtime (block_hash = block_hash )
3319
3326
3320
- metadata_pallet = self . runtime .metadata .get_metadata_pallet (module )
3327
+ metadata_pallet = runtime .metadata .get_metadata_pallet (module )
3321
3328
if not metadata_pallet :
3322
3329
raise ValueError (f'Pallet "{ module } " not found' )
3323
3330
storage_item = metadata_pallet .get_storage_function (storage_function )
@@ -3344,8 +3351,8 @@ async def query_map(
3344
3351
module ,
3345
3352
storage_item .value ["name" ],
3346
3353
params ,
3347
- runtime_config = self .runtime_config ,
3348
- metadata = self . runtime .metadata ,
3354
+ runtime_config = runtime .runtime_config ,
3355
+ metadata = runtime .metadata ,
3349
3356
)
3350
3357
prefix = storage_key .to_hex ()
3351
3358
@@ -3360,6 +3367,7 @@ async def query_map(
3360
3367
response = await self .rpc_request (
3361
3368
method = "state_getKeysPaged" ,
3362
3369
params = [prefix , page_size , start_key , block_hash ],
3370
+ runtime = runtime ,
3363
3371
)
3364
3372
3365
3373
if "error" in response :
@@ -3375,7 +3383,9 @@ async def query_map(
3375
3383
3376
3384
# Retrieve corresponding value
3377
3385
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 ,
3379
3389
)
3380
3390
3381
3391
if "error" in response :
0 commit comments