Skip to content

Commit b9e9f39

Browse files
author
µ
committed
async_substrate.py: eliminate double code around load_registry() for readability
1 parent afbff33 commit b9e9f39

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

async_substrate_interface/async_substrate.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -796,19 +796,11 @@ async def _get_current_block_hash(
796796

797797
async def load_registry(self):
798798
# TODO this needs to happen before init_runtime
799-
metadata_rpc_result = await self.rpc_request(
800-
"state_call",
801-
["Metadata_metadata_at_version", self.metadata_version_hex],
802-
)
803-
metadata_option_hex_str = metadata_rpc_result["result"]
804-
metadata_option_bytes = bytes.fromhex(metadata_option_hex_str[2:])
805-
self.metadata_v15 = MetadataV15.decode_from_metadata_option(
806-
metadata_option_bytes
807-
)
799+
self.metadata_v15 = await self._load_registry_at_block(None)
808800
self.registry = PortableRegistry.from_metadata_v15(self.metadata_v15)
809801
self._load_registry_type_map()
810802

811-
async def _load_registry_at_block(self, block_hash: str) -> MetadataV15:
803+
async def _load_registry_at_block(self, block_hash: Optional[str]) -> MetadataV15:
812804
# Should be called for any block that fails decoding.
813805
# Possibly the metadata was different.
814806
try:
@@ -830,9 +822,8 @@ async def _load_registry_at_block(self, block_hash: str) -> MetadataV15:
830822
raise e
831823
metadata_option_hex_str = metadata_rpc_result["result"]
832824
metadata_option_bytes = bytes.fromhex(metadata_option_hex_str[2:])
833-
old_metadata = MetadataV15.decode_from_metadata_option(metadata_option_bytes)
834-
835-
return old_metadata
825+
metadata = MetadataV15.decode_from_metadata_option(metadata_option_bytes)
826+
return metadata
836827

837828
async def _wait_for_registry(self, _attempt: int = 1, _retries: int = 3) -> None:
838829
async def _waiter():

0 commit comments

Comments
 (0)