@@ -2547,6 +2547,7 @@ async def generate_signature_payload(
2547
2547
) -> ScaleBytes :
2548
2548
# Retrieve genesis hash
2549
2549
genesis_hash = await self .get_block_hash (0 )
2550
+ runtime = await self .init_runtime (block_hash = None )
2550
2551
2551
2552
if not era :
2552
2553
era = "00"
@@ -2556,7 +2557,7 @@ async def generate_signature_payload(
2556
2557
block_hash = genesis_hash
2557
2558
else :
2558
2559
# Determine mortality of extrinsic
2559
- era_obj = self .runtime_config .create_scale_object ("Era" )
2560
+ era_obj = runtime .runtime_config .create_scale_object ("Era" )
2560
2561
2561
2562
if isinstance (era , dict ) and "current" not in era and "phase" not in era :
2562
2563
raise ValueError (
@@ -2569,17 +2570,17 @@ async def generate_signature_payload(
2569
2570
)
2570
2571
2571
2572
# Create signature payload
2572
- signature_payload = self .runtime_config .create_scale_object (
2573
+ signature_payload = runtime .runtime_config .create_scale_object (
2573
2574
"ExtrinsicPayloadValue"
2574
2575
)
2575
2576
2576
2577
# Process signed extensions in metadata
2577
- if "signed_extensions" in self . runtime .metadata [1 ][1 ]["extrinsic" ]:
2578
+ if "signed_extensions" in runtime .metadata [1 ][1 ]["extrinsic" ]:
2578
2579
# Base signature payload
2579
2580
signature_payload .type_mapping = [["call" , "CallBytes" ]]
2580
2581
2581
2582
# Add signed extensions to payload
2582
- signed_extensions = self . runtime .metadata .get_signed_extensions ()
2583
+ signed_extensions = runtime .metadata .get_signed_extensions ()
2583
2584
2584
2585
if "CheckMortality" in signed_extensions :
2585
2586
signature_payload .type_mapping .append (
@@ -2668,10 +2669,10 @@ async def generate_signature_payload(
2668
2669
"era" : era ,
2669
2670
"nonce" : nonce ,
2670
2671
"tip" : tip ,
2671
- "spec_version" : self . runtime .runtime_version ,
2672
+ "spec_version" : runtime .runtime_version ,
2672
2673
"genesis_hash" : genesis_hash ,
2673
2674
"block_hash" : block_hash ,
2674
- "transaction_version" : self . runtime .transaction_version ,
2675
+ "transaction_version" : runtime .transaction_version ,
2675
2676
"asset_id" : {"tip" : tip , "asset_id" : tip_asset_id },
2676
2677
"metadata_hash" : None ,
2677
2678
"mode" : "Disabled" ,
@@ -2713,16 +2714,16 @@ async def create_signed_extrinsic(
2713
2714
The signed Extrinsic
2714
2715
"""
2715
2716
# only support creating extrinsics for current block
2716
- await self . init_runtime ( block_id = await self .get_block_number () )
2717
+ runtime = await self .init_runtime ( )
2717
2718
2718
2719
# Check requirements
2719
2720
if not isinstance (call , GenericCall ):
2720
2721
raise TypeError ("'call' must be of type Call" )
2721
2722
2722
2723
# Check if extrinsic version is supported
2723
- if self . runtime .metadata [1 ][1 ]["extrinsic" ]["version" ] != 4 : # type: ignore
2724
+ if runtime .metadata [1 ][1 ]["extrinsic" ]["version" ] != 4 : # type: ignore
2724
2725
raise NotImplementedError (
2725
- f"Extrinsic version { self . runtime .metadata [1 ][1 ]['extrinsic' ]['version' ]} not supported" # type: ignore
2726
+ f"Extrinsic version { runtime .metadata [1 ][1 ]['extrinsic' ]['version' ]} not supported" # type: ignore
2726
2727
)
2727
2728
2728
2729
# Retrieve nonce
@@ -2766,7 +2767,7 @@ async def create_signed_extrinsic(
2766
2767
2767
2768
# Create extrinsic
2768
2769
extrinsic = self .runtime_config .create_scale_object (
2769
- type_string = "Extrinsic" , metadata = self . runtime .metadata
2770
+ type_string = "Extrinsic" , metadata = runtime .metadata
2770
2771
)
2771
2772
2772
2773
value = {
@@ -2783,8 +2784,8 @@ async def create_signed_extrinsic(
2783
2784
}
2784
2785
2785
2786
# Check if ExtrinsicSignature is MultiSignature, otherwise omit signature_version
2786
- signature_cls = self .runtime_config .get_decoder_class ("ExtrinsicSignature" )
2787
- if issubclass (signature_cls , self .runtime_config .get_decoder_class ("Enum" )):
2787
+ signature_cls = runtime .runtime_config .get_decoder_class ("ExtrinsicSignature" )
2788
+ if issubclass (signature_cls , runtime .runtime_config .get_decoder_class ("Enum" )):
2788
2789
value ["signature_version" ] = signature_version
2789
2790
2790
2791
extrinsic .encode (value )
@@ -3029,7 +3030,7 @@ async def get_metadata_constants(self, block_hash=None) -> list[dict]:
3029
3030
3030
3031
constant_list = []
3031
3032
3032
- for module_idx , module in enumerate (self .metadata .pallets ):
3033
+ for module_idx , module in enumerate (runtime .metadata .pallets ):
3033
3034
for constant in module .constants or []:
3034
3035
constant_list .append (
3035
3036
self .serialize_constant (constant , module , runtime .runtime_version )
@@ -3158,14 +3159,14 @@ async def get_type_registry(
3158
3159
Returns:
3159
3160
dict mapping the type strings to the type decompositions
3160
3161
"""
3161
- await self .init_runtime (block_hash = block_hash )
3162
+ runtime = await self .init_runtime (block_hash = block_hash )
3162
3163
3163
- if not self .implements_scaleinfo :
3164
+ if not runtime .implements_scaleinfo :
3164
3165
raise NotImplementedError ("MetadataV14 or higher runtimes is required" )
3165
3166
3166
3167
type_registry = {}
3167
3168
3168
- for scale_info_type in self .metadata .portable_registry ["types" ]:
3169
+ for scale_info_type in runtime .metadata .portable_registry ["types" ]:
3169
3170
if (
3170
3171
"path" in scale_info_type .value ["type" ]
3171
3172
and len (scale_info_type .value ["type" ]["path" ]) > 0
@@ -3207,21 +3208,21 @@ async def get_metadata_modules(self, block_hash=None) -> list[dict[str, Any]]:
3207
3208
Returns:
3208
3209
List of metadata modules
3209
3210
"""
3210
- await self .init_runtime (block_hash = block_hash )
3211
+ runtime = await self .init_runtime (block_hash = block_hash )
3211
3212
3212
3213
return [
3213
3214
{
3214
3215
"metadata_index" : idx ,
3215
3216
"module_id" : module .get_identifier (),
3216
3217
"name" : module .name ,
3217
- "spec_version" : self . runtime .runtime_version ,
3218
+ "spec_version" : runtime .runtime_version ,
3218
3219
"count_call_functions" : len (module .calls or []),
3219
3220
"count_storage_functions" : len (module .storage or []),
3220
3221
"count_events" : len (module .events or []),
3221
3222
"count_constants" : len (module .constants or []),
3222
3223
"count_errors" : len (module .errors or []),
3223
3224
}
3224
- for idx , module in enumerate (self .metadata .pallets )
3225
+ for idx , module in enumerate (runtime .metadata .pallets )
3225
3226
]
3226
3227
3227
3228
async def get_metadata_module (self , name , block_hash = None ) -> ScaleType :
@@ -3235,9 +3236,9 @@ async def get_metadata_module(self, name, block_hash=None) -> ScaleType:
3235
3236
Returns:
3236
3237
MetadataModule
3237
3238
"""
3238
- await self .init_runtime (block_hash = block_hash )
3239
+ runtime = await self .init_runtime (block_hash = block_hash )
3239
3240
3240
- return self .metadata .get_metadata_pallet (name )
3241
+ return runtime .metadata .get_metadata_pallet (name )
3241
3242
3242
3243
async def query (
3243
3244
self ,
@@ -3655,9 +3656,9 @@ async def get_metadata_call_function(
3655
3656
Returns:
3656
3657
list of call functions
3657
3658
"""
3658
- await self .init_runtime (block_hash = block_hash )
3659
+ runtime = await self .init_runtime (block_hash = block_hash )
3659
3660
3660
- for pallet in self . runtime .metadata .pallets :
3661
+ for pallet in runtime .metadata .pallets :
3661
3662
if pallet .name == module_name and pallet .calls :
3662
3663
for call in pallet .calls :
3663
3664
if call .name == call_function_name :
@@ -3679,7 +3680,7 @@ async def get_metadata_events(self, block_hash=None) -> list[dict]:
3679
3680
3680
3681
event_list = []
3681
3682
3682
- for event_index , (module , event ) in self .metadata .event_index .items ():
3683
+ for event_index , (module , event ) in runtime .metadata .event_index .items ():
3683
3684
event_list .append (
3684
3685
self .serialize_module_event (
3685
3686
module , event , runtime .runtime_version , event_index
0 commit comments