@@ -966,7 +966,6 @@ def load_runtime(self, runtime):
966
966
# Update type registry
967
967
runtime .reload_type_registry (use_remote_preset = False , auto_discover = True )
968
968
969
- runtime .runtime_config .set_active_spec_version_id (runtime .runtime_version )
970
969
runtime .runtime_config .set_active_spec_version_id (runtime .runtime_version )
971
970
if runtime .implements_scaleinfo :
972
971
logger .debug ("Adding PortableRegistry from metadata to type registry" )
@@ -1032,7 +1031,7 @@ async def init_runtime(
1032
1031
if self .ss58_format is None :
1033
1032
# Check and apply runtime constants
1034
1033
ss58_prefix_constant = await self .get_constant (
1035
- "System" , "SS58Prefix" , block_hash = block_hash
1034
+ "System" , "SS58Prefix" , block_hash = block_hash , runtime = runtime
1036
1035
)
1037
1036
1038
1037
if ss58_prefix_constant :
@@ -1458,8 +1457,8 @@ async def decode_block(block_data, block_data_hash=None) -> dict[str, Any]:
1458
1457
try :
1459
1458
extrinsic_decoder = extrinsic_cls (
1460
1459
data = ScaleBytes (extrinsic_data ),
1461
- metadata = self . runtime .metadata ,
1462
- runtime_config = self .runtime_config ,
1460
+ metadata = runtime .metadata ,
1461
+ runtime_config = runtime .runtime_config ,
1463
1462
)
1464
1463
extrinsic_decoder .decode (check_remaining = True )
1465
1464
block_data ["extrinsics" ][idx ] = extrinsic_decoder
@@ -2299,17 +2298,24 @@ async def rpc_request(
2299
2298
params + [block_hash ] if block_hash else params ,
2300
2299
)
2301
2300
]
2302
- result = await self ._make_rpc_request (payloads , result_handler = result_handler )
2301
+ result = await self ._make_rpc_request (
2302
+ payloads , result_handler = result_handler , runtime = runtime
2303
+ )
2303
2304
if "error" in result [payload_id ][0 ]:
2304
2305
if "Failed to get runtime version" in (
2305
2306
err_msg := result [payload_id ][0 ]["error" ]["message" ]
2306
2307
):
2307
2308
logger .warning (
2308
2309
"Failed to get runtime. Re-fetching from chain, and retrying."
2309
2310
)
2310
- await self .init_runtime (block_hash = block_hash )
2311
+ runtime = await self .init_runtime (block_hash = block_hash )
2311
2312
return await self .rpc_request (
2312
- method , params , result_handler , block_hash , reuse_block_hash
2313
+ method ,
2314
+ params ,
2315
+ result_handler ,
2316
+ block_hash ,
2317
+ reuse_block_hash ,
2318
+ runtime = runtime ,
2313
2319
)
2314
2320
elif (
2315
2321
"Client error: Api called for an unknown Block: State already discarded"
@@ -3036,7 +3042,13 @@ async def get_metadata_constants(self, block_hash=None) -> list[dict]:
3036
3042
3037
3043
return constant_list
3038
3044
3039
- async def get_metadata_constant (self , module_name , constant_name , block_hash = None ):
3045
+ async def get_metadata_constant (
3046
+ self ,
3047
+ module_name ,
3048
+ constant_name ,
3049
+ block_hash = None ,
3050
+ runtime : Optional [Runtime ] = None ,
3051
+ ):
3040
3052
"""
3041
3053
Retrieves the details of a constant for given module name, call function name and block_hash
3042
3054
(or chaintip if block_hash is omitted)
@@ -3045,13 +3057,15 @@ async def get_metadata_constant(self, module_name, constant_name, block_hash=Non
3045
3057
module_name: name of the module you are querying
3046
3058
constant_name: name of the constant you are querying
3047
3059
block_hash: hash of the block at which to make the runtime API call
3060
+ runtime: Runtime whose metadata you are querying.
3048
3061
3049
3062
Returns:
3050
3063
MetadataModuleConstants
3051
3064
"""
3052
- await self .init_runtime (block_hash = block_hash )
3065
+ if not runtime :
3066
+ runtime = await self .init_runtime (block_hash = block_hash )
3053
3067
3054
- for module in self . runtime .metadata .pallets :
3068
+ for module in runtime .metadata .pallets :
3055
3069
if module_name == module .name and module .constants :
3056
3070
for constant in module .constants :
3057
3071
if constant_name == constant .value ["name" ]:
@@ -3063,6 +3077,7 @@ async def get_constant(
3063
3077
constant_name : str ,
3064
3078
block_hash : Optional [str ] = None ,
3065
3079
reuse_block_hash : bool = False ,
3080
+ runtime : Optional [Runtime ] = None ,
3066
3081
) -> Optional [ScaleObj ]:
3067
3082
"""
3068
3083
Returns the decoded `ScaleType` object of the constant for given module name, call function name and block_hash
@@ -3073,18 +3088,22 @@ async def get_constant(
3073
3088
constant_name: Name of the constant to query
3074
3089
block_hash: Hash of the block at which to make the runtime API call
3075
3090
reuse_block_hash: Reuse last-used block hash if set to true
3091
+ runtime: Runtime to use for querying the constant
3076
3092
3077
3093
Returns:
3078
3094
ScaleType from the runtime call
3079
3095
"""
3080
3096
block_hash = await self ._get_current_block_hash (block_hash , reuse_block_hash )
3081
3097
constant = await self .get_metadata_constant (
3082
- module_name , constant_name , block_hash = block_hash
3098
+ module_name , constant_name , block_hash = block_hash , runtime = runtime
3083
3099
)
3084
3100
if constant :
3085
3101
# Decode to ScaleType
3086
3102
return await self .decode_scale (
3087
- constant .type , bytes (constant .constant_value ), return_scale_obj = True
3103
+ constant .type ,
3104
+ bytes (constant .constant_value ),
3105
+ return_scale_obj = True ,
3106
+ runtime = runtime ,
3088
3107
)
3089
3108
else :
3090
3109
return None
0 commit comments