@@ -689,7 +689,7 @@ async def _start_receiving(self):
689689 except ConnectionClosed :
690690 await self .connect (force = True )
691691
692- async def send (self , payload : dict ) -> int :
692+ async def send (self , payload : dict ) -> str :
693693 """
694694 Sends a payload to the websocket connection.
695695
@@ -714,6 +714,7 @@ async def send(self, payload: dict) -> int:
714714 return original_id
715715 except (ConnectionClosed , ssl .SSLError , EOFError ):
716716 await self .connect (force = True )
717+ return await self .send (payload )
717718
718719 async def retrieve (self , item_id : int ) -> Optional [dict ]:
719720 """
@@ -911,7 +912,7 @@ async def name(self):
911912 return self ._name
912913
913914 async def get_storage_item (
914- self , module : str , storage_function : str , block_hash : str = None
915+ self , module : str , storage_function : str , block_hash : Optional [ str ] = None
915916 ):
916917 runtime = await self .init_runtime (block_hash = block_hash )
917918 metadata_pallet = runtime .metadata .get_metadata_pallet (module )
@@ -1154,7 +1155,7 @@ async def create_storage_key(
11541155 pallet : str ,
11551156 storage_function : str ,
11561157 params : Optional [list ] = None ,
1157- block_hash : str = None ,
1158+ block_hash : Optional [ str ] = None ,
11581159 ) -> StorageKey :
11591160 """
11601161 Create a `StorageKey` instance providing storage function details. See `subscribe_storage()`.
@@ -1169,7 +1170,7 @@ async def create_storage_key(
11691170 StorageKey
11701171 """
11711172 runtime = await self .init_runtime (block_hash = block_hash )
1172-
1173+ params = params or []
11731174 return StorageKey .create_from_storage_function (
11741175 pallet ,
11751176 storage_function ,
@@ -1424,7 +1425,7 @@ async def get_metadata_error(
14241425 return error
14251426
14261427 async def get_metadata_runtime_call_functions (
1427- self , block_hash : str = None , runtime : Optional [Runtime ] = None
1428+ self , block_hash : Optional [ str ] = None , runtime : Optional [Runtime ] = None
14281429 ) -> list [GenericRuntimeCallDefinition ]:
14291430 """
14301431 Get a list of available runtime API calls
@@ -1763,7 +1764,7 @@ async def get_block_header(
17631764 ignore_decoding_errors : bool = False ,
17641765 include_author : bool = False ,
17651766 finalized_only : bool = False ,
1766- ) -> dict :
1767+ ) -> Optional [ dict ] :
17671768 """
17681769 Retrieves a block header and decodes its containing log digest items. If `block_hash` and `block_number`
17691770 is omitted the chain tip will be retrieved, or the finalized head if `finalized_only` is set to true.
@@ -1790,7 +1791,7 @@ async def get_block_header(
17901791 block_hash = await self .get_block_hash (block_number )
17911792
17921793 if block_hash is None :
1793- return
1794+ return None
17941795
17951796 if block_hash and finalized_only :
17961797 raise ValueError (
@@ -1820,7 +1821,7 @@ async def get_block_header(
18201821
18211822 async def subscribe_block_headers (
18221823 self ,
1823- subscription_handler : callable ,
1824+ subscription_handler : Callable ,
18241825 ignore_decoding_errors : bool = False ,
18251826 include_author : bool = False ,
18261827 finalized_only = False ,
@@ -1902,7 +1903,7 @@ def retrieve_extrinsic_by_hash(
19021903 )
19031904
19041905 async def get_extrinsics (
1905- self , block_hash : str = None , block_number : int = None
1906+ self , block_hash : Optional [ str ] = None , block_number : Optional [ int ] = None
19061907 ) -> Optional [list ["AsyncExtrinsicReceipt" ]]:
19071908 """
19081909 Return all extrinsics for given block_hash or block_number
@@ -2780,7 +2781,7 @@ async def create_signed_extrinsic(
27802781 self ,
27812782 call : GenericCall ,
27822783 keypair : Keypair ,
2783- era : Optional [dict ] = None ,
2784+ era : Optional [Union [ dict , str ] ] = None ,
27842785 nonce : Optional [int ] = None ,
27852786 tip : int = 0 ,
27862787 tip_asset_id : Optional [int ] = None ,
@@ -2932,12 +2933,12 @@ async def _do_runtime_call_old(
29322933 params : Optional [Union [list , dict ]] = None ,
29332934 block_hash : Optional [str ] = None ,
29342935 runtime : Optional [Runtime ] = None ,
2935- ) -> ScaleType :
2936+ ) -> ScaleObj :
29362937 logger .debug (
29372938 f"Decoding old runtime call: { api } .{ method } with params: { params } at block hash: { block_hash } "
29382939 )
29392940 runtime_call_def = _TYPE_REGISTRY ["runtime_api" ][api ]["methods" ][method ]
2940-
2941+ params = params or []
29412942 # Encode params
29422943 param_data = b""
29432944
@@ -3245,7 +3246,7 @@ async def get_payment_info(
32453246 return result .value
32463247
32473248 async def get_type_registry (
3248- self , block_hash : str = None , max_recursion : int = 4
3249+ self , block_hash : Optional [ str ] = None , max_recursion : int = 4
32493250 ) -> dict :
32503251 """
32513252 Generates an exhaustive list of which RUST types exist in the runtime specified at given block_hash (or
@@ -3284,7 +3285,7 @@ async def get_type_registry(
32843285 return type_registry
32853286
32863287 async def get_type_definition (
3287- self , type_string : str , block_hash : str = None
3288+ self , type_string : str , block_hash : Optional [ str ] = None
32883289 ) -> str :
32893290 """
32903291 Retrieves SCALE encoding specifications of given type_string
@@ -3589,11 +3590,11 @@ async def create_multisig_extrinsic(
35893590 keypair : Keypair ,
35903591 multisig_account : MultiAccountId ,
35913592 max_weight : Optional [Union [dict , int ]] = None ,
3592- era : dict = None ,
3593- nonce : int = None ,
3593+ era : Optional [ dict ] = None ,
3594+ nonce : Optional [ int ] = None ,
35943595 tip : int = 0 ,
3595- tip_asset_id : int = None ,
3596- signature : Union [bytes , str ] = None ,
3596+ tip_asset_id : Optional [ int ] = None ,
3597+ signature : Optional [ Union [bytes , str ] ] = None ,
35973598 ) -> GenericExtrinsic :
35983599 """
35993600 Create a Multisig extrinsic that will be signed by one of the signatories. Checks on-chain if the threshold
@@ -3878,6 +3879,9 @@ async def get_block_number(self, block_hash: Optional[str] = None) -> int:
38783879 elif "result" in response :
38793880 if response ["result" ]:
38803881 return int (response ["result" ]["number" ], 16 )
3882+ raise SubstrateRequestException (
3883+ f"Unable to retrieve block number for { block_hash } "
3884+ )
38813885
38823886 async def close (self ):
38833887 """
@@ -3973,14 +3977,14 @@ async def get_async_substrate_interface(
39733977 """
39743978 substrate = AsyncSubstrateInterface (
39753979 url ,
3976- use_remote_preset ,
3977- auto_discover ,
3978- ss58_format ,
3979- type_registry ,
3980- chain_name ,
3981- max_retries ,
3982- retry_timeout ,
3983- _mock ,
3980+ use_remote_preset = use_remote_preset ,
3981+ auto_discover = auto_discover ,
3982+ ss58_format = ss58_format ,
3983+ type_registry = type_registry ,
3984+ chain_name = chain_name ,
3985+ max_retries = max_retries ,
3986+ retry_timeout = retry_timeout ,
3987+ _mock = _mock ,
39843988 )
39853989 await substrate .initialize ()
39863990 return substrate
0 commit comments