@@ -689,7 +689,7 @@ async def _start_receiving(self):
689
689
except ConnectionClosed :
690
690
await self .connect (force = True )
691
691
692
- async def send (self , payload : dict ) -> int :
692
+ async def send (self , payload : dict ) -> str :
693
693
"""
694
694
Sends a payload to the websocket connection.
695
695
@@ -714,6 +714,7 @@ async def send(self, payload: dict) -> int:
714
714
return original_id
715
715
except (ConnectionClosed , ssl .SSLError , EOFError ):
716
716
await self .connect (force = True )
717
+ return await self .send (payload )
717
718
718
719
async def retrieve (self , item_id : int ) -> Optional [dict ]:
719
720
"""
@@ -911,7 +912,7 @@ async def name(self):
911
912
return self ._name
912
913
913
914
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
915
916
):
916
917
runtime = await self .init_runtime (block_hash = block_hash )
917
918
metadata_pallet = runtime .metadata .get_metadata_pallet (module )
@@ -1014,7 +1015,7 @@ async def decode_scale(
1014
1015
# Decode AccountId bytes to SS58 address
1015
1016
return ss58_encode (scale_bytes , self .ss58_format )
1016
1017
else :
1017
- if not runtime :
1018
+ if runtime is None :
1018
1019
runtime = await self .init_runtime (block_hash = block_hash )
1019
1020
if runtime .metadata_v15 is not None and force_legacy is False :
1020
1021
obj = decode_by_type_string (type_string , runtime .registry , scale_bytes )
@@ -1154,7 +1155,7 @@ async def create_storage_key(
1154
1155
pallet : str ,
1155
1156
storage_function : str ,
1156
1157
params : Optional [list ] = None ,
1157
- block_hash : str = None ,
1158
+ block_hash : Optional [ str ] = None ,
1158
1159
) -> StorageKey :
1159
1160
"""
1160
1161
Create a `StorageKey` instance providing storage function details. See `subscribe_storage()`.
@@ -1169,7 +1170,7 @@ async def create_storage_key(
1169
1170
StorageKey
1170
1171
"""
1171
1172
runtime = await self .init_runtime (block_hash = block_hash )
1172
-
1173
+ params = params or []
1173
1174
return StorageKey .create_from_storage_function (
1174
1175
pallet ,
1175
1176
storage_function ,
@@ -1317,7 +1318,7 @@ async def get_metadata_storage_functions(
1317
1318
Returns:
1318
1319
list of storage functions
1319
1320
"""
1320
- if not runtime :
1321
+ if runtime is None :
1321
1322
runtime = await self .init_runtime (block_hash = block_hash )
1322
1323
1323
1324
storage_list = []
@@ -1355,7 +1356,7 @@ async def get_metadata_storage_function(
1355
1356
Returns:
1356
1357
Metadata storage function
1357
1358
"""
1358
- if not runtime :
1359
+ if runtime is None :
1359
1360
runtime = await self .init_runtime (block_hash = block_hash )
1360
1361
1361
1362
pallet = runtime .metadata .get_metadata_pallet (module_name )
@@ -1376,7 +1377,7 @@ async def get_metadata_errors(
1376
1377
Returns:
1377
1378
list of errors in the metadata
1378
1379
"""
1379
- if not runtime :
1380
+ if runtime is None :
1380
1381
runtime = await self .init_runtime (block_hash = block_hash )
1381
1382
1382
1383
error_list = []
@@ -1414,7 +1415,7 @@ async def get_metadata_error(
1414
1415
error
1415
1416
1416
1417
"""
1417
- if not runtime :
1418
+ if runtime is None :
1418
1419
runtime = await self .init_runtime (block_hash = block_hash )
1419
1420
1420
1421
for module_idx , module in enumerate (runtime .metadata .pallets ):
@@ -1424,15 +1425,15 @@ async def get_metadata_error(
1424
1425
return error
1425
1426
1426
1427
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
1428
1429
) -> list [GenericRuntimeCallDefinition ]:
1429
1430
"""
1430
1431
Get a list of available runtime API calls
1431
1432
1432
1433
Returns:
1433
1434
list of runtime call functions
1434
1435
"""
1435
- if not runtime :
1436
+ if runtime is None :
1436
1437
runtime = await self .init_runtime (block_hash = block_hash )
1437
1438
call_functions = []
1438
1439
@@ -1466,7 +1467,7 @@ async def get_metadata_runtime_call_function(
1466
1467
Returns:
1467
1468
GenericRuntimeCallDefinition
1468
1469
"""
1469
- if not runtime :
1470
+ if runtime is None :
1470
1471
runtime = await self .init_runtime (block_hash = block_hash )
1471
1472
1472
1473
try :
@@ -1763,7 +1764,7 @@ async def get_block_header(
1763
1764
ignore_decoding_errors : bool = False ,
1764
1765
include_author : bool = False ,
1765
1766
finalized_only : bool = False ,
1766
- ) -> dict :
1767
+ ) -> Optional [ dict ] :
1767
1768
"""
1768
1769
Retrieves a block header and decodes its containing log digest items. If `block_hash` and `block_number`
1769
1770
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(
1790
1791
block_hash = await self .get_block_hash (block_number )
1791
1792
1792
1793
if block_hash is None :
1793
- return
1794
+ return None
1794
1795
1795
1796
if block_hash and finalized_only :
1796
1797
raise ValueError (
@@ -1820,7 +1821,7 @@ async def get_block_header(
1820
1821
1821
1822
async def subscribe_block_headers (
1822
1823
self ,
1823
- subscription_handler : callable ,
1824
+ subscription_handler : Callable ,
1824
1825
ignore_decoding_errors : bool = False ,
1825
1826
include_author : bool = False ,
1826
1827
finalized_only = False ,
@@ -1902,7 +1903,7 @@ def retrieve_extrinsic_by_hash(
1902
1903
)
1903
1904
1904
1905
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
1906
1907
) -> Optional [list ["AsyncExtrinsicReceipt" ]]:
1907
1908
"""
1908
1909
Return all extrinsics for given block_hash or block_number
@@ -2141,7 +2142,7 @@ async def _preprocess(
2141
2142
"""
2142
2143
params = query_for if query_for else []
2143
2144
# Search storage call in metadata
2144
- if not runtime :
2145
+ if runtime is None :
2145
2146
runtime = self .runtime
2146
2147
metadata_pallet = runtime .metadata .get_metadata_pallet (module )
2147
2148
@@ -2503,7 +2504,7 @@ async def query_multiple(
2503
2504
block_hash = await self ._get_current_block_hash (block_hash , reuse_block_hash )
2504
2505
if block_hash :
2505
2506
self .last_block_hash = block_hash
2506
- if not runtime :
2507
+ if runtime is None :
2507
2508
runtime = await self .init_runtime (block_hash = block_hash )
2508
2509
preprocessed : tuple [Preprocessed ] = await asyncio .gather (
2509
2510
* [
@@ -2561,7 +2562,7 @@ async def query_multi(
2561
2562
Returns:
2562
2563
list of `(storage_key, scale_obj)` tuples
2563
2564
"""
2564
- if not runtime :
2565
+ if runtime is None :
2565
2566
runtime = await self .init_runtime (block_hash = block_hash )
2566
2567
2567
2568
# Retrieve corresponding value
@@ -2616,7 +2617,7 @@ async def create_scale_object(
2616
2617
Returns:
2617
2618
The created Scale Type object
2618
2619
"""
2619
- if not runtime :
2620
+ if runtime is None :
2620
2621
runtime = await self .init_runtime (block_hash = block_hash )
2621
2622
if "metadata" not in kwargs :
2622
2623
kwargs ["metadata" ] = runtime .metadata
@@ -2780,7 +2781,7 @@ async def create_signed_extrinsic(
2780
2781
self ,
2781
2782
call : GenericCall ,
2782
2783
keypair : Keypair ,
2783
- era : Optional [dict ] = None ,
2784
+ era : Optional [Union [ dict , str ] ] = None ,
2784
2785
nonce : Optional [int ] = None ,
2785
2786
tip : int = 0 ,
2786
2787
tip_asset_id : Optional [int ] = None ,
@@ -2932,12 +2933,12 @@ async def _do_runtime_call_old(
2932
2933
params : Optional [Union [list , dict ]] = None ,
2933
2934
block_hash : Optional [str ] = None ,
2934
2935
runtime : Optional [Runtime ] = None ,
2935
- ) -> ScaleType :
2936
+ ) -> ScaleObj :
2936
2937
logger .debug (
2937
2938
f"Decoding old runtime call: { api } .{ method } with params: { params } at block hash: { block_hash } "
2938
2939
)
2939
2940
runtime_call_def = _TYPE_REGISTRY ["runtime_api" ][api ]["methods" ][method ]
2940
-
2941
+ params = params or []
2941
2942
# Encode params
2942
2943
param_data = b""
2943
2944
@@ -3159,7 +3160,7 @@ async def get_metadata_constant(
3159
3160
Returns:
3160
3161
MetadataModuleConstants
3161
3162
"""
3162
- if not runtime :
3163
+ if runtime is None :
3163
3164
runtime = await self .init_runtime (block_hash = block_hash )
3164
3165
3165
3166
for module in runtime .metadata .pallets :
@@ -3245,7 +3246,7 @@ async def get_payment_info(
3245
3246
return result .value
3246
3247
3247
3248
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
3249
3250
) -> dict :
3250
3251
"""
3251
3252
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(
3284
3285
return type_registry
3285
3286
3286
3287
async def get_type_definition (
3287
- self , type_string : str , block_hash : str = None
3288
+ self , type_string : str , block_hash : Optional [ str ] = None
3288
3289
) -> str :
3289
3290
"""
3290
3291
Retrieves SCALE encoding specifications of given type_string
@@ -3360,7 +3361,7 @@ async def query(
3360
3361
block_hash = await self ._get_current_block_hash (block_hash , reuse_block_hash )
3361
3362
if block_hash :
3362
3363
self .last_block_hash = block_hash
3363
- if not runtime :
3364
+ if runtime is None :
3364
3365
runtime = await self .init_runtime (block_hash = block_hash )
3365
3366
preprocessed : Preprocessed = await self ._preprocess (
3366
3367
params ,
@@ -3589,11 +3590,11 @@ async def create_multisig_extrinsic(
3589
3590
keypair : Keypair ,
3590
3591
multisig_account : MultiAccountId ,
3591
3592
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 ,
3594
3595
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 ,
3597
3598
) -> GenericExtrinsic :
3598
3599
"""
3599
3600
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:
3878
3879
elif "result" in response :
3879
3880
if response ["result" ]:
3880
3881
return int (response ["result" ]["number" ], 16 )
3882
+ raise SubstrateRequestException (
3883
+ f"Unable to retrieve block number for { block_hash } "
3884
+ )
3881
3885
3882
3886
async def close (self ):
3883
3887
"""
@@ -3973,14 +3977,14 @@ async def get_async_substrate_interface(
3973
3977
"""
3974
3978
substrate = AsyncSubstrateInterface (
3975
3979
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 ,
3984
3988
)
3985
3989
await substrate .initialize ()
3986
3990
return substrate
0 commit comments