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 39
39
ExtrinsicNotFound ,
40
40
BlockNotFound ,
41
41
MaxRetriesExceeded ,
42
+ MetadataAtVersionNotFound ,
42
43
)
43
44
from async_substrate_interface .protocols import Keypair
44
45
from async_substrate_interface .types import (
@@ -817,10 +818,7 @@ async def _load_registry_at_block(
817
818
"Client error: Execution failed: Other: Exported method Metadata_metadata_at_version is not found"
818
819
in e .args
819
820
):
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
824
822
else :
825
823
raise e
826
824
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):
12
12
pass
13
13
14
14
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
+
15
25
class StorageFunctionNotFound (ValueError ):
16
26
pass
17
27
Original file line number Diff line number Diff line change 21
21
SubstrateRequestException ,
22
22
BlockNotFound ,
23
23
MaxRetriesExceeded ,
24
+ MetadataAtVersionNotFound ,
24
25
)
25
26
from async_substrate_interface .protocols import Keypair
26
27
from async_substrate_interface .types import (
@@ -617,11 +618,20 @@ def _get_current_block_hash(
617
618
def _load_registry_at_block (self , block_hash : Optional [str ]) -> MetadataV15 :
618
619
# Should be called for any block that fails decoding.
619
620
# 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
625
635
metadata_option_hex_str = metadata_rpc_result ["result" ]
626
636
metadata_option_bytes = bytes .fromhex (metadata_option_hex_str [2 :])
627
637
metadata = MetadataV15 .decode_from_metadata_option (metadata_option_bytes )
You can’t perform that action at this time.
0 commit comments