@@ -822,7 +822,7 @@ def subscription_handler(storage_key, obj, subscription_id):
822
822
823
823
Args:
824
824
storage_keys: StorageKey list of storage keys to subscribe to
825
- subscription_handler: coroutine function to handle value changes of subscription
825
+ subscription_handler: function to handle value changes of subscription
826
826
827
827
"""
828
828
self .init_runtime ()
@@ -1040,6 +1040,41 @@ def get_metadata_runtime_call_function(
1040
1040
1041
1041
return runtime_call_def_obj
1042
1042
1043
+ def get_metadata_runtime_call_function (
1044
+ self , api : str , method : str
1045
+ ) -> GenericRuntimeCallDefinition :
1046
+ """
1047
+ Get details of a runtime API call
1048
+
1049
+ Args:
1050
+ api: Name of the runtime API e.g. 'TransactionPaymentApi'
1051
+ method: Name of the method e.g. 'query_fee_details'
1052
+
1053
+ Returns:
1054
+ GenericRuntimeCallDefinition
1055
+ """
1056
+ self .init_runtime ()
1057
+
1058
+ try :
1059
+ runtime_call_def = self .runtime_config .type_registry ["runtime_api" ][api ][
1060
+ "methods"
1061
+ ][method ]
1062
+ runtime_call_def ["api" ] = api
1063
+ runtime_call_def ["method" ] = method
1064
+ runtime_api_types = self .runtime_config .type_registry ["runtime_api" ][
1065
+ api
1066
+ ].get ("types" , {})
1067
+ except KeyError :
1068
+ raise ValueError (f"Runtime API Call '{ api } .{ method } ' not found in registry" )
1069
+
1070
+ # Add runtime API types to registry
1071
+ self .runtime_config .update_type_registry_types (runtime_api_types )
1072
+
1073
+ runtime_call_def_obj = self .create_scale_object ("RuntimeCallDefinition" )
1074
+ runtime_call_def_obj .encode (runtime_call_def )
1075
+
1076
+ return runtime_call_def_obj
1077
+
1043
1078
def _get_block_handler (
1044
1079
self ,
1045
1080
block_hash : str ,
@@ -1510,6 +1545,21 @@ def convert_event_data(data):
1510
1545
events .append (convert_event_data (item ))
1511
1546
return events
1512
1547
1548
+ def get_metadata (self , block_hash = None ):
1549
+ """
1550
+ Returns `MetadataVersioned` object for given block_hash or chaintip if block_hash is omitted
1551
+
1552
+
1553
+ Args:
1554
+ block_hash
1555
+
1556
+ Returns:
1557
+ MetadataVersioned
1558
+ """
1559
+ runtime = self .init_runtime (block_hash = block_hash )
1560
+
1561
+ return runtime .metadata
1562
+
1513
1563
@functools .lru_cache (maxsize = 512 )
1514
1564
def get_parent_block_hash (self , block_hash ):
1515
1565
block_header = self .rpc_request ("chain_getHeader" , [block_hash ])
@@ -2428,6 +2478,29 @@ def get_account_next_index(self, account_address: str) -> int:
2428
2478
nonce_obj = self .rpc_request ("account_nextIndex" , [account_address ])
2429
2479
return nonce_obj ["result" ]
2430
2480
2481
+ def get_metadata_constants (self , block_hash = None ) -> list [dict ]:
2482
+ """
2483
+ Retrieves a list of all constants in metadata active at given block_hash (or chaintip if block_hash is omitted)
2484
+
2485
+ Args:
2486
+ block_hash: hash of the block
2487
+
2488
+ Returns:
2489
+ list of constants
2490
+ """
2491
+
2492
+ runtime = self .init_runtime (block_hash = block_hash )
2493
+
2494
+ constant_list = []
2495
+
2496
+ for module_idx , module in enumerate (self .metadata .pallets ):
2497
+ for constant in module .constants or []:
2498
+ constant_list .append (
2499
+ self .serialize_constant (constant , module , runtime .runtime_version )
2500
+ )
2501
+
2502
+ return constant_list
2503
+
2431
2504
def get_metadata_constant (self , module_name , constant_name , block_hash = None ):
2432
2505
"""
2433
2506
Retrieves the details of a constant for given module name, call function name and block_hash
@@ -2926,6 +2999,55 @@ def get_metadata_call_function(
2926
2999
return call
2927
3000
return None
2928
3001
3002
+ def get_metadata_events (self , block_hash = None ) -> list [dict ]:
3003
+ """
3004
+ Retrieves a list of all events in metadata active for given block_hash (or chaintip if block_hash is omitted)
3005
+
3006
+ Args:
3007
+ block_hash
3008
+
3009
+ Returns:
3010
+ list of module events
3011
+ """
3012
+
3013
+ runtime = self .init_runtime (block_hash = block_hash )
3014
+
3015
+ event_list = []
3016
+
3017
+ for event_index , (module , event ) in self .metadata .event_index .items ():
3018
+ event_list .append (
3019
+ self .serialize_module_event (
3020
+ module , event , runtime .runtime_version , event_index
3021
+ )
3022
+ )
3023
+
3024
+ return event_list
3025
+
3026
+ def get_metadata_event (
3027
+ self , module_name , event_name , block_hash = None
3028
+ ) -> Optional [Any ]:
3029
+ """
3030
+ Retrieves the details of an event for given module name, call function name and block_hash
3031
+ (or chaintip if block_hash is omitted)
3032
+
3033
+ Args:
3034
+ module_name: name of the module to call
3035
+ event_name: name of the event
3036
+ block_hash: hash of the block
3037
+
3038
+ Returns:
3039
+ Metadata event
3040
+
3041
+ """
3042
+
3043
+ runtime = self .init_runtime (block_hash = block_hash )
3044
+
3045
+ for pallet in runtime .metadata .pallets :
3046
+ if pallet .name == module_name and pallet .events :
3047
+ for event in pallet .events :
3048
+ if event .name == event_name :
3049
+ return event
3050
+
2929
3051
def get_block_number (self , block_hash : Optional [str ] = None ) -> int :
2930
3052
"""Async version of `substrateinterface.base.get_block_number` method."""
2931
3053
response = self .rpc_request ("chain_getHeader" , [block_hash ])
0 commit comments