diff --git a/async_substrate_interface/async_substrate.py b/async_substrate_interface/async_substrate.py index 8df2341..d026e6c 100644 --- a/async_substrate_interface/async_substrate.py +++ b/async_substrate_interface/async_substrate.py @@ -39,6 +39,7 @@ ExtrinsicNotFound, BlockNotFound, MaxRetriesExceeded, + MetadataAtVersionNotFound, ) from async_substrate_interface.protocols import Keypair from async_substrate_interface.types import ( @@ -817,10 +818,7 @@ async def _load_registry_at_block( "Client error: Execution failed: Other: Exported method Metadata_metadata_at_version is not found" in e.args ): - raise SubstrateRequestException( - "You are attempting to call a block too old for this version of async-substrate-interface. Please" - " instead use legacy py-substrate-interface for these very old blocks." - ) + raise MetadataAtVersionNotFound else: raise e metadata_option_hex_str = metadata_rpc_result["result"] diff --git a/async_substrate_interface/errors.py b/async_substrate_interface/errors.py index 98114fe..c6a2d8d 100644 --- a/async_substrate_interface/errors.py +++ b/async_substrate_interface/errors.py @@ -12,6 +12,16 @@ class MaxRetriesExceeded(SubstrateRequestException): pass +class MetadataAtVersionNotFound(SubstrateRequestException): + def __init__(self): + message = ( + "Exported method Metadata_metadata_at_version is not found. This indicates the block is quite old, and is" + "not supported by async-substrate-interface. If you need this, we recommend using the legacy " + "substrate-interface (https://github.com/JAMdotTech/py-polkadot-sdk)." + ) + super().__init__(message) + + class StorageFunctionNotFound(ValueError): pass diff --git a/async_substrate_interface/sync_substrate.py b/async_substrate_interface/sync_substrate.py index 21664d4..cbd7136 100644 --- a/async_substrate_interface/sync_substrate.py +++ b/async_substrate_interface/sync_substrate.py @@ -21,6 +21,7 @@ SubstrateRequestException, BlockNotFound, MaxRetriesExceeded, + MetadataAtVersionNotFound, ) from async_substrate_interface.protocols import Keypair from async_substrate_interface.types import ( @@ -617,11 +618,20 @@ def _get_current_block_hash( def _load_registry_at_block(self, block_hash: Optional[str]) -> MetadataV15: # Should be called for any block that fails decoding. # Possibly the metadata was different. - metadata_rpc_result = self.rpc_request( - "state_call", - ["Metadata_metadata_at_version", self.metadata_version_hex], - block_hash=block_hash, - ) + try: + metadata_rpc_result = self.rpc_request( + "state_call", + ["Metadata_metadata_at_version", self.metadata_version_hex], + block_hash=block_hash, + ) + except SubstrateRequestException as e: + if ( + "Client error: Execution failed: Other: Exported method Metadata_metadata_at_version is not found" + in e.args + ): + raise MetadataAtVersionNotFound + else: + raise e metadata_option_hex_str = metadata_rpc_result["result"] metadata_option_bytes = bytes.fromhex(metadata_option_hex_str[2:]) metadata = MetadataV15.decode_from_metadata_option(metadata_option_bytes)