Skip to content

Commit b1408a2

Browse files
authored
Merge branch 'staging' into feat/thewhaleking/improve-disk-cache
2 parents 66fe45d + 0671f33 commit b1408a2

File tree

9 files changed

+377
-420
lines changed

9 files changed

+377
-420
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ jobs:
124124
os:
125125
- ubuntu-latest
126126
test-file: ${{ fromJson(needs.find-tests.outputs.test-files) }}
127-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
127+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
128128
steps:
129129
- name: Check-out repository
130130
uses: actions/checkout@v4

.github/workflows/unit-and-integration-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
fail-fast: false
1616
max-parallel: 5
1717
matrix:
18-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
18+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
1919

2020
steps:
2121
- name: Checkout repository

async_substrate_interface/async_substrate.py

Lines changed: 41 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
cast,
2424
)
2525

26+
import scalecodec
2627
import websockets.exceptions
2728
from bt_decode import MetadataV15, PortableRegistry, decode as decode_by_type_string
2829
from scalecodec import GenericVariant
@@ -1591,7 +1592,7 @@ async def retrieve_pending_extrinsics(self) -> list:
15911592

15921593
async def get_metadata_storage_functions(
15931594
self, block_hash: Optional[str] = None, runtime: Optional[Runtime] = None
1594-
) -> list:
1595+
) -> list[dict[str, Any]]:
15951596
"""
15961597
Retrieves a list of all storage functions in metadata active at given block_hash (or chaintip if
15971598
block_hash and runtime are omitted)
@@ -1606,21 +1607,7 @@ async def get_metadata_storage_functions(
16061607
if runtime is None:
16071608
runtime = await self.init_runtime(block_hash=block_hash)
16081609

1609-
storage_list = []
1610-
1611-
for module_idx, module in enumerate(runtime.metadata.pallets):
1612-
if module.storage:
1613-
for storage in module.storage:
1614-
storage_list.append(
1615-
self.serialize_storage_item(
1616-
storage_item=storage,
1617-
module=module,
1618-
spec_version_id=runtime.runtime_version,
1619-
runtime=runtime,
1620-
)
1621-
)
1622-
1623-
return storage_list
1610+
return self._get_metadata_storage_functions(runtime=runtime)
16241611

16251612
async def get_metadata_storage_function(
16261613
self,
@@ -1665,28 +1652,15 @@ async def get_metadata_errors(
16651652
if runtime is None:
16661653
runtime = await self.init_runtime(block_hash=block_hash)
16671654

1668-
error_list = []
1669-
1670-
for module_idx, module in enumerate(runtime.metadata.pallets):
1671-
if module.errors:
1672-
for error in module.errors:
1673-
error_list.append(
1674-
self.serialize_module_error(
1675-
module=module,
1676-
error=error,
1677-
spec_version=runtime.runtime_version,
1678-
)
1679-
)
1680-
1681-
return error_list
1655+
return self._get_metadata_errors(runtime=runtime)
16821656

16831657
async def get_metadata_error(
16841658
self,
16851659
module_name: str,
16861660
error_name: str,
16871661
block_hash: Optional[str] = None,
16881662
runtime: Optional[Runtime] = None,
1689-
):
1663+
) -> Optional[scalecodec.GenericVariant]:
16901664
"""
16911665
Retrieves the details of an error for given module name, call function name and block_hash
16921666
@@ -1702,16 +1676,13 @@ async def get_metadata_error(
17021676
"""
17031677
if runtime is None:
17041678
runtime = await self.init_runtime(block_hash=block_hash)
1705-
1706-
for module_idx, module in enumerate(runtime.metadata.pallets):
1707-
if module.name == module_name and module.errors:
1708-
for error in module.errors:
1709-
if error_name == error.name:
1710-
return error
1679+
return self._get_metadata_error(
1680+
module_name=module_name, error_name=error_name, runtime=runtime
1681+
)
17111682

17121683
async def get_metadata_runtime_call_functions(
17131684
self, block_hash: Optional[str] = None, runtime: Optional[Runtime] = None
1714-
) -> list[GenericRuntimeCallDefinition]:
1685+
) -> list[scalecodec.GenericRuntimeCallDefinition]:
17151686
"""
17161687
Get a list of available runtime API calls
17171688
@@ -1720,25 +1691,15 @@ async def get_metadata_runtime_call_functions(
17201691
"""
17211692
if runtime is None:
17221693
runtime = await self.init_runtime(block_hash=block_hash)
1723-
call_functions = []
1724-
1725-
for api, methods in runtime.runtime_config.type_registry["runtime_api"].items():
1726-
for method in methods["methods"].keys():
1727-
call_functions.append(
1728-
await self.get_metadata_runtime_call_function(
1729-
api, method, runtime=runtime
1730-
)
1731-
)
1732-
1733-
return call_functions
1694+
return self._get_metadata_runtime_call_functions(runtime=runtime)
17341695

17351696
async def get_metadata_runtime_call_function(
17361697
self,
17371698
api: str,
17381699
method: str,
17391700
block_hash: Optional[str] = None,
17401701
runtime: Optional[Runtime] = None,
1741-
) -> GenericRuntimeCallDefinition:
1702+
) -> scalecodec.GenericRuntimeCallDefinition:
17421703
"""
17431704
Get details of a runtime API call. If not supplying `block_hash` or `runtime`, the runtime of the current block
17441705
will be used.
@@ -1754,28 +1715,7 @@ async def get_metadata_runtime_call_function(
17541715
"""
17551716
if runtime is None:
17561717
runtime = await self.init_runtime(block_hash=block_hash)
1757-
1758-
try:
1759-
runtime_call_def = runtime.runtime_config.type_registry["runtime_api"][api][
1760-
"methods"
1761-
][method]
1762-
runtime_call_def["api"] = api
1763-
runtime_call_def["method"] = method
1764-
runtime_api_types = runtime.runtime_config.type_registry["runtime_api"][
1765-
api
1766-
].get("types", {})
1767-
except KeyError:
1768-
raise ValueError(f"Runtime API Call '{api}.{method}' not found in registry")
1769-
1770-
# Add runtime API types to registry
1771-
runtime.runtime_config.update_type_registry_types(runtime_api_types)
1772-
1773-
runtime_call_def_obj = await self.create_scale_object(
1774-
"RuntimeCallDefinition", runtime=runtime
1775-
)
1776-
runtime_call_def_obj.encode(runtime_call_def)
1777-
1778-
return runtime_call_def_obj
1718+
return self._get_metadata_runtime_call_function(api, method, runtime)
17791719

17801720
async def _get_block_handler(
17811721
self,
@@ -3424,24 +3364,15 @@ async def get_metadata_constants(self, block_hash=None) -> list[dict]:
34243364
"""
34253365

34263366
runtime = await self.init_runtime(block_hash=block_hash)
3427-
3428-
constant_list = []
3429-
3430-
for module_idx, module in enumerate(runtime.metadata.pallets):
3431-
for constant in module.constants or []:
3432-
constant_list.append(
3433-
self.serialize_constant(constant, module, runtime.runtime_version)
3434-
)
3435-
3436-
return constant_list
3367+
return self._get_metadata_constants(runtime)
34373368

34383369
async def get_metadata_constant(
34393370
self,
34403371
module_name: str,
34413372
constant_name: str,
34423373
block_hash: Optional[str] = None,
34433374
runtime: Optional[Runtime] = None,
3444-
):
3375+
) -> Optional[scalecodec.ScaleInfoModuleConstantMetadata]:
34453376
"""
34463377
Retrieves the details of a constant for given module name, call function name and block_hash
34473378
(or chaintip if block_hash is omitted)
@@ -3457,12 +3388,7 @@ async def get_metadata_constant(
34573388
"""
34583389
if runtime is None:
34593390
runtime = await self.init_runtime(block_hash=block_hash)
3460-
3461-
for module in runtime.metadata.pallets:
3462-
if module_name == module.name and module.constants:
3463-
for constant in module.constants:
3464-
if constant_name == constant.value["name"]:
3465-
return constant
3391+
return self._get_metadata_constant(module_name, constant_name, runtime)
34663392

34673393
async def get_constant(
34683394
self,
@@ -3502,7 +3428,13 @@ async def get_constant(
35023428
return None
35033429

35043430
async def get_payment_info(
3505-
self, call: GenericCall, keypair: Keypair
3431+
self,
3432+
call: GenericCall,
3433+
keypair: Keypair,
3434+
era: Optional[Union[dict, str]] = None,
3435+
nonce: Optional[int] = None,
3436+
tip: int = 0,
3437+
tip_asset_id: Optional[int] = None,
35063438
) -> dict[str, Any]:
35073439
"""
35083440
Retrieves fee estimation via RPC for given extrinsic
@@ -3511,6 +3443,11 @@ async def get_payment_info(
35113443
call: Call object to estimate fees for
35123444
keypair: Keypair of the sender, does not have to include private key because no valid signature is
35133445
required
3446+
era: Specify mortality in blocks in follow format:
3447+
{'period': [amount_blocks]} If omitted the extrinsic is immortal
3448+
nonce: nonce to include in extrinsics, if omitted the current nonce is retrieved on-chain
3449+
tip: The tip for the block author to gain priority during network congestion
3450+
tip_asset_id: Optional asset ID with which to pay the tip
35143451
35153452
Returns:
35163453
Dict with payment info
@@ -3530,7 +3467,13 @@ async def get_payment_info(
35303467

35313468
# Create extrinsic
35323469
extrinsic = await self.create_signed_extrinsic(
3533-
call=call, keypair=keypair, signature=signature
3470+
call=call,
3471+
keypair=keypair,
3472+
era=era,
3473+
nonce=nonce,
3474+
tip=tip,
3475+
tip_asset_id=tip_asset_id,
3476+
signature=signature,
35343477
)
35353478
extrinsic_len = len(extrinsic.data)
35363479

@@ -3606,21 +3549,7 @@ async def get_metadata_modules(self, block_hash=None) -> list[dict[str, Any]]:
36063549
List of metadata modules
36073550
"""
36083551
runtime = await self.init_runtime(block_hash=block_hash)
3609-
3610-
return [
3611-
{
3612-
"metadata_index": idx,
3613-
"module_id": module.get_identifier(),
3614-
"name": module.name,
3615-
"spec_version": runtime.runtime_version,
3616-
"count_call_functions": len(module.calls or []),
3617-
"count_storage_functions": len(module.storage or []),
3618-
"count_events": len(module.events or []),
3619-
"count_constants": len(module.constants or []),
3620-
"count_errors": len(module.errors or []),
3621-
}
3622-
for idx, module in enumerate(runtime.metadata.pallets)
3623-
]
3552+
return self._get_metadata_modules(runtime)
36243553

36253554
async def get_metadata_module(self, name, block_hash=None) -> ScaleType:
36263555
"""
@@ -4083,7 +4012,7 @@ async def result_handler(message: dict, subscription_id) -> tuple[dict, bool]:
40834012

40844013
async def get_metadata_call_functions(
40854014
self, block_hash: Optional[str] = None, runtime: Optional[Runtime] = None
4086-
):
4015+
) -> dict[str, dict[str, dict[str, dict[str, Union[str, int, list]]]]]:
40874016
"""
40884017
Retrieves calls functions for the metadata at the specified block_hash or runtime. If neither are specified,
40894018
the metadata at chaintip is used.
@@ -4135,12 +4064,9 @@ async def get_metadata_call_function(
41354064
"""
41364065
runtime = await self.init_runtime(block_hash=block_hash)
41374066

4138-
for pallet in runtime.metadata.pallets:
4139-
if pallet.name == module_name and pallet.calls:
4140-
for call in pallet.calls:
4141-
if call.name == call_function_name:
4142-
return call
4143-
return None
4067+
return self._get_metadata_call_function(
4068+
module_name, call_function_name, runtime
4069+
)
41444070

41454071
async def get_metadata_events(self, block_hash=None) -> list[dict]:
41464072
"""
@@ -4154,17 +4080,7 @@ async def get_metadata_events(self, block_hash=None) -> list[dict]:
41544080
"""
41554081

41564082
runtime = await self.init_runtime(block_hash=block_hash)
4157-
4158-
event_list = []
4159-
4160-
for event_index, (module, event) in runtime.metadata.event_index.items():
4161-
event_list.append(
4162-
self.serialize_module_event(
4163-
module, event, runtime.runtime_version, event_index
4164-
)
4165-
)
4166-
4167-
return event_list
4083+
return self._get_metadata_events(runtime)
41684084

41694085
async def get_metadata_event(
41704086
self, module_name, event_name, block_hash=None
@@ -4184,12 +4100,7 @@ async def get_metadata_event(
41844100
"""
41854101

41864102
runtime = await self.init_runtime(block_hash=block_hash)
4187-
4188-
for pallet in runtime.metadata.pallets:
4189-
if pallet.name == module_name and pallet.events:
4190-
for event in pallet.events:
4191-
if event.name == event_name:
4192-
return event
4103+
return self._get_metadata_event(module_name, event_name, runtime)
41934104

41944105
async def get_block_number(self, block_hash: Optional[str] = None) -> int:
41954106
"""Async version of `substrateinterface.base.get_block_number` method."""

0 commit comments

Comments
 (0)