File tree Expand file tree Collapse file tree 3 files changed +27
-9
lines changed
async_substrate_interface Expand file tree Collapse file tree 3 files changed +27
-9
lines changed Original file line number Diff line number Diff line change 3939 ExtrinsicNotFound ,
4040 BlockNotFound ,
4141 MaxRetriesExceeded ,
42+ MetadataAtVersionNotFound ,
4243)
4344from async_substrate_interface .protocols import Keypair
4445from 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" ]
Original file line number Diff line number Diff 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+
1525class StorageFunctionNotFound (ValueError ):
1626 pass
1727
Original file line number Diff line number Diff line change 2121 SubstrateRequestException ,
2222 BlockNotFound ,
2323 MaxRetriesExceeded ,
24+ MetadataAtVersionNotFound ,
2425)
2526from async_substrate_interface .protocols import Keypair
2627from 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 )
You can’t perform that action at this time.
0 commit comments