@@ -585,7 +585,7 @@ def connect(self, init=False):
585585
586586 def get_storage_item (self , module : str , storage_function : str , block_hash : str = None ):
587587 self .init_runtime (block_hash = block_hash )
588- metadata_pallet = self ._metadata .get_metadata_pallet (module )
588+ metadata_pallet = self .runtime . metadata .get_metadata_pallet (module )
589589 storage_item = metadata_pallet .get_storage_function (storage_function )
590590 return storage_item
591591
@@ -611,9 +611,9 @@ def _load_registry_at_block(self, block_hash: Optional[str]) -> MetadataV15:
611611 metadata_option_hex_str = metadata_rpc_result ["result" ]
612612 metadata_option_bytes = bytes .fromhex (metadata_option_hex_str [2 :])
613613 metadata = MetadataV15 .decode_from_metadata_option (metadata_option_bytes )
614- self . registry = PortableRegistry .from_metadata_v15 (metadata )
615- self ._load_registry_type_map ()
616- return metadata
614+ registry = PortableRegistry .from_metadata_v15 (metadata )
615+ self ._load_registry_type_map (registry )
616+ return metadata , registry
617617
618618 def decode_scale (
619619 self ,
@@ -638,25 +638,22 @@ def decode_scale(
638638 # Decode AccountId bytes to SS58 address
639639 return ss58_encode (scale_bytes , SS58_FORMAT )
640640 else :
641- obj = decode_by_type_string (type_string , self .registry , scale_bytes )
641+ obj = decode_by_type_string (type_string , self .runtime . registry , scale_bytes )
642642 if return_scale_obj :
643643 return ScaleObj (obj )
644644 else :
645645 return obj
646646
647- def load_runtime (self ,runtime_info = None , metadata = None , metadata_v15 = None , registry = None ):
647+ def load_runtime (self ,runtime ):
648648 # Update type registry
649649 self .reload_type_registry (use_remote_preset = False , auto_discover = True )
650650
651- self .metadata_v15 = metadata_v15
652- self .registry = registry
653- self .runtime_version = runtime_info .get ("specVersion" )
654- self ._metadata = metadata
655- self .runtime_config .set_active_spec_version_id (self .runtime_version )
656- self .transaction_version = runtime_info .get ("transactionVersion" )
651+ self .runtime = runtime
652+
653+ self .runtime_config .set_active_spec_version_id (runtime .runtime_version )
657654 if self .implements_scaleinfo :
658655 logger .debug ("Add PortableRegistry from metadata to type registry" )
659- self .runtime_config .add_portable_registry (metadata )
656+ self .runtime_config .add_portable_registry (runtime . metadata )
660657 # Set runtime compatibility flags
661658 try :
662659 _ = self .runtime_config .create_scale_object ("sp_weights::weight_v2::Weight" )
@@ -702,7 +699,7 @@ def init_runtime(
702699 f"No runtime information for block '{ block_hash } '"
703700 )
704701
705- if runtime_version == self .runtime_version :
702+ if self . runtime and runtime_version == self . runtime .runtime_version :
706703 return
707704
708705 runtime = self .runtime_cache .retrieve (runtime_version = runtime_version )
@@ -727,7 +724,7 @@ def init_runtime(
727724 )
728725 )
729726
730- metadata_v15 = self ._load_registry_at_block (
727+ metadata_v15 , registry = self ._load_registry_at_block (
731728 block_hash = runtime_block_hash
732729 )
733730 logger .debug (
@@ -743,16 +740,11 @@ def init_runtime(
743740 type_registry = self .type_registry ,
744741 metadata_v15 = metadata_v15 ,
745742 runtime_info = runtime_info ,
746- registry = self . registry ,
743+ registry = registry ,
747744 )
748745 self .runtime_cache .add_item (runtime_version = runtime_version , runtime = runtime )
749746
750- self .load_runtime (
751- runtime_info = runtime .runtime_info ,
752- metadata = runtime .metadata ,
753- metadata_v15 = runtime .metadata_v15 ,
754- registry = runtime .registry ,
755- )
747+ self .load_runtime (runtime )
756748
757749 if self .ss58_format is None :
758750 # Check and apply runtime constants
@@ -789,7 +781,7 @@ def create_storage_key(
789781 storage_function ,
790782 params ,
791783 runtime_config = self .runtime_config ,
792- metadata = self ._metadata ,
784+ metadata = self .runtime . metadata ,
793785 )
794786
795787 def get_metadata_storage_functions (self , block_hash = None ) -> list :
@@ -814,7 +806,7 @@ def get_metadata_storage_functions(self, block_hash=None) -> list:
814806 self .serialize_storage_item (
815807 storage_item = storage ,
816808 module = module ,
817- spec_version_id = self .runtime_version ,
809+ spec_version_id = self .runtime . runtime_version ,
818810 )
819811 )
820812
@@ -853,14 +845,14 @@ def get_metadata_errors(self, block_hash=None) -> list[dict[str, Optional[str]]]
853845
854846 error_list = []
855847
856- for module_idx , module in enumerate (self ._metadata .pallets ):
848+ for module_idx , module in enumerate (self .runtime . metadata .pallets ):
857849 if module .errors :
858850 for error in module .errors :
859851 error_list .append (
860852 self .serialize_module_error (
861853 module = module ,
862854 error = error ,
863- spec_version = self .runtime_version ,
855+ spec_version = self .runtime . runtime_version ,
864856 )
865857 )
866858
@@ -881,7 +873,7 @@ def get_metadata_error(self, module_name, error_name, block_hash=None):
881873 """
882874 self .init_runtime (block_hash = block_hash )
883875
884- for module_idx , module in enumerate (self ._metadata .pallets ):
876+ for module_idx , module in enumerate (self .runtime . metadata .pallets ):
885877 if module .name == module_name and module .errors :
886878 for error in module .errors :
887879 if error_name == error .name :
@@ -974,7 +966,7 @@ def decode_block(block_data, block_data_hash=None) -> dict[str, Any]:
974966 try :
975967 extrinsic_decoder = extrinsic_cls (
976968 data = ScaleBytes (extrinsic_data ),
977- metadata = self ._metadata ,
969+ metadata = self .runtime . metadata ,
978970 runtime_config = self .runtime_config ,
979971 )
980972 extrinsic_decoder .decode (check_remaining = True )
@@ -1496,7 +1488,7 @@ def _preprocess(
14961488 """
14971489 params = query_for if query_for else []
14981490 # Search storage call in metadata
1499- metadata_pallet = self ._metadata .get_metadata_pallet (module )
1491+ metadata_pallet = self .runtime . metadata .get_metadata_pallet (module )
15001492
15011493 if not metadata_pallet :
15021494 raise SubstrateRequestException (f'Pallet "{ module } " not found' )
@@ -1531,7 +1523,7 @@ def _preprocess(
15311523 storage_item .value ["name" ],
15321524 params ,
15331525 runtime_config = self .runtime_config ,
1534- metadata = self ._metadata ,
1526+ metadata = self .runtime . metadata ,
15351527 )
15361528 method = "state_getStorageAt"
15371529 return Preprocessed (
@@ -1778,7 +1770,7 @@ def compose_call(
17781770 self .init_runtime (block_hash = block_hash )
17791771
17801772 call = self .runtime_config .create_scale_object (
1781- type_string = "Call" , metadata = self ._metadata
1773+ type_string = "Call" , metadata = self .runtime . metadata
17821774 )
17831775
17841776 call .encode (
@@ -1947,12 +1939,12 @@ def generate_signature_payload(
19471939 )
19481940
19491941 # Process signed extensions in metadata
1950- if "signed_extensions" in self ._metadata [1 ][1 ]["extrinsic" ]:
1942+ if "signed_extensions" in self .runtime . metadata [1 ][1 ]["extrinsic" ]:
19511943 # Base signature payload
19521944 signature_payload .type_mapping = [["call" , "CallBytes" ]]
19531945
19541946 # Add signed extensions to payload
1955- signed_extensions = self ._metadata .get_signed_extensions ()
1947+ signed_extensions = self .runtime . metadata .get_signed_extensions ()
19561948
19571949 if "CheckMortality" in signed_extensions :
19581950 signature_payload .type_mapping .append (
@@ -2041,10 +2033,10 @@ def generate_signature_payload(
20412033 "era" : era ,
20422034 "nonce" : nonce ,
20432035 "tip" : tip ,
2044- "spec_version" : self .runtime_version ,
2036+ "spec_version" : self .runtime . runtime_version ,
20452037 "genesis_hash" : genesis_hash ,
20462038 "block_hash" : block_hash ,
2047- "transaction_version" : self .transaction_version ,
2039+ "transaction_version" : self .runtime . transaction_version ,
20482040 "asset_id" : {"tip" : tip , "asset_id" : tip_asset_id },
20492041 "metadata_hash" : None ,
20502042 "mode" : "Disabled" ,
@@ -2093,9 +2085,9 @@ def create_signed_extrinsic(
20932085 raise TypeError ("'call' must be of type Call" )
20942086
20952087 # Check if extrinsic version is supported
2096- if self ._metadata [1 ][1 ]["extrinsic" ]["version" ] != 4 : # type: ignore
2088+ if self .runtime . metadata [1 ][1 ]["extrinsic" ]["version" ] != 4 : # type: ignore
20972089 raise NotImplementedError (
2098- f"Extrinsic version { self ._metadata [1 ][1 ]['extrinsic' ]['version' ]} not supported" # type: ignore
2090+ f"Extrinsic version { self .runtime . metadata [1 ][1 ]['extrinsic' ]['version' ]} not supported" # type: ignore
20992091 )
21002092
21012093 # Retrieve nonce
@@ -2135,7 +2127,7 @@ def create_signed_extrinsic(
21352127
21362128 # Create extrinsic
21372129 extrinsic = self .runtime_config .create_scale_object (
2138- type_string = "Extrinsic" , metadata = self ._metadata
2130+ type_string = "Extrinsic" , metadata = self .runtime . metadata
21392131 )
21402132
21412133 value = {
@@ -2249,7 +2241,7 @@ def runtime_call(
22492241 params = {}
22502242
22512243 try :
2252- metadata_v15_value = self .metadata_v15 .value ()
2244+ metadata_v15_value = self .runtime . metadata_v15 .value ()
22532245
22542246 apis = {entry ["name" ]: entry for entry in metadata_v15_value ["apis" ]}
22552247 api_entry = apis [api ]
@@ -2348,7 +2340,7 @@ def get_metadata_constant(self, module_name, constant_name, block_hash=None):
23482340 """
23492341 self .init_runtime (block_hash = block_hash )
23502342
2351- for module in self ._metadata .pallets :
2343+ for module in self .runtime . metadata .pallets :
23522344 if module_name == module .name and module .constants :
23532345 for constant in module .constants :
23542346 if constant_name == constant .value ["name" ]:
@@ -2491,7 +2483,7 @@ def get_metadata_modules(self, block_hash=None) -> list[dict[str, Any]]:
24912483 "metadata_index" : idx ,
24922484 "module_id" : module .get_identifier (),
24932485 "name" : module .name ,
2494- "spec_version" : self .runtime_version ,
2486+ "spec_version" : self .runtime . runtime_version ,
24952487 "count_call_functions" : len (module .calls or []),
24962488 "count_storage_functions" : len (module .storage or []),
24972489 "count_events" : len (module .events or []),
@@ -2608,7 +2600,7 @@ def query_map(
26082600 self .last_block_hash = block_hash
26092601 self .init_runtime (block_hash = block_hash )
26102602
2611- metadata_pallet = self ._metadata .get_metadata_pallet (module )
2603+ metadata_pallet = self .runtime . metadata .get_metadata_pallet (module )
26122604 if not metadata_pallet :
26132605 raise ValueError (f'Pallet "{ module } " not found' )
26142606 storage_item = metadata_pallet .get_storage_function (storage_function )
@@ -2637,7 +2629,7 @@ def query_map(
26372629 storage_item .value ["name" ],
26382630 params ,
26392631 runtime_config = self .runtime_config ,
2640- metadata = self ._metadata ,
2632+ metadata = self .runtime . metadata ,
26412633 )
26422634 prefix = storage_key .to_hex ()
26432635
0 commit comments