Skip to content

Commit fab6fc9

Browse files
authored
Merge pull request #113 from opentensor/feat/thewhaleking/add-metadata-at-version-not-found-error
2 parents b4e85d8 + a83f57e commit fab6fc9

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

async_substrate_interface/async_substrate.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
ExtrinsicNotFound,
4040
BlockNotFound,
4141
MaxRetriesExceeded,
42+
MetadataAtVersionNotFound,
4243
)
4344
from async_substrate_interface.protocols import Keypair
4445
from async_substrate_interface.types import (
@@ -817,10 +818,7 @@ async def _load_registry_at_block(
817818
"Client error: Execution failed: Other: Exported method Metadata_metadata_at_version is not found"
818819
in e.args
819820
):
820-
raise SubstrateRequestException(
821-
"You are attempting to call a block too old for this version of async-substrate-interface. Please"
822-
" instead use legacy py-substrate-interface for these very old blocks."
823-
)
821+
raise MetadataAtVersionNotFound
824822
else:
825823
raise e
826824
metadata_option_hex_str = metadata_rpc_result["result"]

async_substrate_interface/errors.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ class MaxRetriesExceeded(SubstrateRequestException):
1212
pass
1313

1414

15+
class MetadataAtVersionNotFound(SubstrateRequestException):
16+
def __init__(self):
17+
message = (
18+
"Exported method Metadata_metadata_at_version is not found. This indicates the block is quite old, and is"
19+
"not supported by async-substrate-interface. If you need this, we recommend using the legacy "
20+
"substrate-interface (https://github.com/JAMdotTech/py-polkadot-sdk)."
21+
)
22+
super().__init__(message)
23+
24+
1525
class StorageFunctionNotFound(ValueError):
1626
pass
1727

async_substrate_interface/sync_substrate.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
SubstrateRequestException,
2222
BlockNotFound,
2323
MaxRetriesExceeded,
24+
MetadataAtVersionNotFound,
2425
)
2526
from async_substrate_interface.protocols import Keypair
2627
from async_substrate_interface.types import (
@@ -617,11 +618,20 @@ def _get_current_block_hash(
617618
def _load_registry_at_block(self, block_hash: Optional[str]) -> MetadataV15:
618619
# Should be called for any block that fails decoding.
619620
# Possibly the metadata was different.
620-
metadata_rpc_result = self.rpc_request(
621-
"state_call",
622-
["Metadata_metadata_at_version", self.metadata_version_hex],
623-
block_hash=block_hash,
624-
)
621+
try:
622+
metadata_rpc_result = self.rpc_request(
623+
"state_call",
624+
["Metadata_metadata_at_version", self.metadata_version_hex],
625+
block_hash=block_hash,
626+
)
627+
except SubstrateRequestException as e:
628+
if (
629+
"Client error: Execution failed: Other: Exported method Metadata_metadata_at_version is not found"
630+
in e.args
631+
):
632+
raise MetadataAtVersionNotFound
633+
else:
634+
raise e
625635
metadata_option_hex_str = metadata_rpc_result["result"]
626636
metadata_option_bytes = bytes.fromhex(metadata_option_hex_str[2:])
627637
metadata = MetadataV15.decode_from_metadata_option(metadata_option_bytes)

0 commit comments

Comments
 (0)