Skip to content

Commit e1e37b3

Browse files
committed
Types!
1 parent 98fe876 commit e1e37b3

File tree

3 files changed

+34
-29
lines changed

3 files changed

+34
-29
lines changed

async_substrate_interface/async_substrate.py

Lines changed: 7 additions & 6 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
@@ -1588,7 +1589,7 @@ async def retrieve_pending_extrinsics(self) -> list:
15881589

15891590
async def get_metadata_storage_functions(
15901591
self, block_hash: Optional[str] = None, runtime: Optional[Runtime] = None
1591-
) -> list:
1592+
) -> list[dict[str, Any]]:
15921593
"""
15931594
Retrieves a list of all storage functions in metadata active at given block_hash (or chaintip if
15941595
block_hash and runtime are omitted)
@@ -1656,7 +1657,7 @@ async def get_metadata_error(
16561657
error_name: str,
16571658
block_hash: Optional[str] = None,
16581659
runtime: Optional[Runtime] = None,
1659-
):
1660+
) -> Optional[scalecodec.GenericVariant]:
16601661
"""
16611662
Retrieves the details of an error for given module name, call function name and block_hash
16621663
@@ -1678,7 +1679,7 @@ async def get_metadata_error(
16781679

16791680
async def get_metadata_runtime_call_functions(
16801681
self, block_hash: Optional[str] = None, runtime: Optional[Runtime] = None
1681-
) -> list[ScaleType]:
1682+
) -> list[scalecodec.GenericRuntimeCallDefinition]:
16821683
"""
16831684
Get a list of available runtime API calls
16841685
@@ -1695,7 +1696,7 @@ async def get_metadata_runtime_call_function(
16951696
method: str,
16961697
block_hash: Optional[str] = None,
16971698
runtime: Optional[Runtime] = None,
1698-
) -> ScaleType:
1699+
) -> scalecodec.GenericRuntimeCallDefinition:
16991700
"""
17001701
Get details of a runtime API call. If not supplying `block_hash` or `runtime`, the runtime of the current block
17011702
will be used.
@@ -3369,7 +3370,7 @@ async def get_metadata_constant(
33693370
constant_name: str,
33703371
block_hash: Optional[str] = None,
33713372
runtime: Optional[Runtime] = None,
3372-
):
3373+
) -> Optional[scalecodec.ScaleInfoModuleConstantMetadata]:
33733374
"""
33743375
Retrieves the details of a constant for given module name, call function name and block_hash
33753376
(or chaintip if block_hash is omitted)
@@ -4080,7 +4081,7 @@ async def get_metadata_event(
40804081
"""
40814082

40824083
runtime = await self.init_runtime(block_hash=block_hash)
4083-
return self._get_metadata_event(runtime)
4084+
return self._get_metadata_event(module_name, event_name, runtime)
40844085

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

async_substrate_interface/sync_substrate.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import Optional, Union, Callable, Any
77
from unittest.mock import MagicMock
88

9+
import scalecodec
910
from bt_decode import MetadataV15, PortableRegistry, decode as decode_by_type_string
1011
from scalecodec import (
1112
GenericCall,
@@ -1031,7 +1032,7 @@ def retrieve_pending_extrinsics(self) -> list:
10311032

10321033
return extrinsics
10331034

1034-
def get_metadata_storage_functions(self, block_hash=None) -> list:
1035+
def get_metadata_storage_functions(self, block_hash=None) -> list[dict[str, Any]]:
10351036
"""
10361037
Retrieves a list of all storage functions in metadata active at given block_hash (or chaintip if block_hash is
10371038
omitted)
@@ -1078,7 +1079,9 @@ def get_metadata_errors(self, block_hash=None) -> list[dict[str, Optional[str]]]
10781079

10791080
return self._get_metadata_errors(runtime=runtime)
10801081

1081-
def get_metadata_error(self, module_name: str, error_name: str, block_hash=None):
1082+
def get_metadata_error(
1083+
self, module_name: str, error_name: str, block_hash=None
1084+
) -> Optional[scalecodec.GenericVariant]:
10821085
"""
10831086
Retrieves the details of an error for given module name, call function name and block_hash
10841087
@@ -1098,7 +1101,7 @@ def get_metadata_error(self, module_name: str, error_name: str, block_hash=None)
10981101

10991102
def get_metadata_runtime_call_functions(
11001103
self, block_hash: Optional[str] = None
1101-
) -> list[ScaleType]:
1104+
) -> list[scalecodec.GenericRuntimeCallDefinition]:
11021105
"""
11031106
Get a list of available runtime API calls
11041107
@@ -1110,7 +1113,7 @@ def get_metadata_runtime_call_functions(
11101113

11111114
def get_metadata_runtime_call_function(
11121115
self, api: str, method: str, block_hash: Optional[str] = None
1113-
) -> ScaleType:
1116+
) -> scalecodec.GenericRuntimeCallDefinition:
11141117
"""
11151118
Get details of a runtime API call
11161119
@@ -2662,7 +2665,9 @@ def get_metadata_constants(self, block_hash=None) -> list[dict]:
26622665

26632666
return self._get_metadata_constants(runtime)
26642667

2665-
def get_metadata_constant(self, module_name, constant_name, block_hash=None):
2668+
def get_metadata_constant(
2669+
self, module_name, constant_name, block_hash=None
2670+
) -> Optional[scalecodec.ScaleInfoModuleConstantMetadata]:
26662671
"""
26672672
Retrieves the details of a constant for given module name, call function name and block_hash
26682673
(or chaintip if block_hash is omitted)
@@ -3279,7 +3284,7 @@ def get_metadata_events(self, block_hash=None) -> list[dict]:
32793284
return self._get_metadata_events(runtime)
32803285

32813286
def get_metadata_event(
3282-
self, module_name, event_name, block_hash=None
3287+
self, module_name: str, event_name: str, block_hash=None
32833288
) -> Optional[Any]:
32843289
"""
32853290
Retrieves the details of an event for given module name, call function name and block_hash
@@ -3296,7 +3301,7 @@ def get_metadata_event(
32963301
"""
32973302

32983303
runtime = self.init_runtime(block_hash=block_hash)
3299-
return self._get_metadata_event(runtime)
3304+
return self._get_metadata_event(module_name, event_name, runtime)
33003305

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

async_substrate_interface/types.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,8 @@ def is_valid_ss58_address(self, value: str) -> bool:
676676

677677
def serialize_storage_item(
678678
self,
679-
storage_item: ScaleType,
680-
module: str,
679+
storage_item: scalecodec.ScaleInfoStorageEntryMetadata,
680+
module: scalecodec.ScaleInfoPalletMetadata,
681681
spec_version_id: int,
682682
runtime: Optional[Runtime] = None,
683683
) -> dict:
@@ -1026,7 +1026,7 @@ def _get_metadata_call_functions(
10261026
@staticmethod
10271027
def _get_metadata_call_function(
10281028
module_name: str, call_function_name: str, runtime: Runtime
1029-
):
1029+
) -> Optional[scalecodec.GenericVariant]:
10301030
"""
10311031
See subclass `get_metadata_call_function` for documentation.
10321032
"""
@@ -1037,8 +1037,7 @@ def _get_metadata_call_function(
10371037
return call
10381038
return None
10391039

1040-
@staticmethod
1041-
def _get_metadata_events(runtime: Runtime) -> list[dict]:
1040+
def _get_metadata_events(self, runtime: Runtime) -> list[dict]:
10421041
"""
10431042
See subclass `get_metadata_events` for documentation.
10441043
"""
@@ -1054,7 +1053,9 @@ def _get_metadata_events(runtime: Runtime) -> list[dict]:
10541053
return event_list
10551054

10561055
@staticmethod
1057-
def _get_metadata_event(runtime: Runtime) -> Optional[Any]:
1056+
def _get_metadata_event(
1057+
module_name: str, event_name: str, runtime: Runtime
1058+
) -> Optional[scalecodec.GenericScaleInfoEvent]:
10581059
"""
10591060
See subclass `get_metadata_event` for documentation.
10601061
"""
@@ -1065,8 +1066,7 @@ def _get_metadata_event(runtime: Runtime) -> Optional[Any]:
10651066
return event
10661067
return None
10671068

1068-
@staticmethod
1069-
def _get_metadata_constants(runtime: Runtime) -> list[dict]:
1069+
def _get_metadata_constants(self, runtime: Runtime) -> list[dict]:
10701070
"""
10711071
See subclass `get_metadata_constants` for documentation.
10721072
"""
@@ -1083,7 +1083,7 @@ def _get_metadata_constants(runtime: Runtime) -> list[dict]:
10831083
@staticmethod
10841084
def _get_metadata_constant(
10851085
module_name: str, constant_name: str, runtime: Runtime
1086-
) -> Optional[dict]:
1086+
) -> Optional[scalecodec.ScaleInfoModuleConstantMetadata]:
10871087
"""
10881088
See subclass `get_metadata_constant` for documentation.
10891089
"""
@@ -1114,8 +1114,7 @@ def _get_metadata_modules(runtime: Runtime) -> list[dict[str, Any]]:
11141114
for idx, module in enumerate(runtime.metadata.pallets)
11151115
]
11161116

1117-
@staticmethod
1118-
def _get_metadata_storage_functions(runtime: Runtime) -> list:
1117+
def _get_metadata_storage_functions(self, runtime: Runtime) -> list[dict[str, Any]]:
11191118
"""
11201119
See subclass `get_metadata_storage_functions` for documentation.
11211120
"""
@@ -1129,13 +1128,13 @@ def _get_metadata_storage_functions(runtime: Runtime) -> list:
11291128
storage_item=storage,
11301129
module=module,
11311130
spec_version_id=self.runtime.runtime_version,
1131+
runtime=runtime,
11321132
)
11331133
)
11341134

11351135
return storage_list
11361136

1137-
@staticmethod
1138-
def _get_metadata_errors(runtime: Runtime) -> list[dict[str, Optional[str]]]:
1137+
def _get_metadata_errors(self, runtime: Runtime) -> list[dict[str, Optional[str]]]:
11391138
"""
11401139
See subclass `get_metadata_errors` for documentation.
11411140
"""
@@ -1157,7 +1156,7 @@ def _get_metadata_errors(runtime: Runtime) -> list[dict[str, Optional[str]]]:
11571156
@staticmethod
11581157
def _get_metadata_error(
11591158
module_name: str, error_name: str, runtime: Runtime
1160-
) -> Optional[ScaleType]:
1159+
) -> Optional[scalecodec.GenericVariant]:
11611160
"""
11621161
See subclass `get_metadata_error` for documentation.
11631162
"""
@@ -1171,7 +1170,7 @@ def _get_metadata_error(
11711170
@staticmethod
11721171
def _get_metadata_runtime_call_function(
11731172
api: str, method: str, runtime: Runtime
1174-
) -> scalecodec.ScaleType:
1173+
) -> scalecodec.GenericRuntimeCallDefinition:
11751174
"""
11761175
See subclass `get_metadata_runtime_call_function` for documentation.
11771176
"""
@@ -1198,7 +1197,7 @@ def _get_metadata_runtime_call_function(
11981197

11991198
def _get_metadata_runtime_call_functions(
12001199
self, runtime: Runtime
1201-
) -> list[scalecodec.ScaleType]:
1200+
) -> list[scalecodec.GenericRuntimeCallDefinition]:
12021201
"""
12031202
See subclass `get_metadata_runtime_call_functions` for documentation.
12041203
"""

0 commit comments

Comments
 (0)