34
34
from async_substrate_interface .utils .decoding import (
35
35
_determine_if_old_runtime_call ,
36
36
_bt_decode_to_dict_or_list ,
37
+ decode_query_map ,
37
38
)
38
39
from async_substrate_interface .utils .storage import StorageKey
39
40
from async_substrate_interface .type_registry import _TYPE_REGISTRY
@@ -2600,7 +2601,7 @@ def query_map(
2600
2601
block_hash = self ._get_current_block_hash (block_hash , reuse_block_hash )
2601
2602
if block_hash :
2602
2603
self .last_block_hash = block_hash
2603
- self .init_runtime (block_hash = block_hash )
2604
+ runtime = self .init_runtime (block_hash = block_hash )
2604
2605
2605
2606
metadata_pallet = self .runtime .metadata .get_metadata_pallet (module )
2606
2607
if not metadata_pallet :
@@ -2656,19 +2657,6 @@ def query_map(
2656
2657
result = []
2657
2658
last_key = None
2658
2659
2659
- def concat_hash_len (key_hasher : str ) -> int :
2660
- """
2661
- Helper function to avoid if statements
2662
- """
2663
- if key_hasher == "Blake2_128Concat" :
2664
- return 16
2665
- elif key_hasher == "Twox64Concat" :
2666
- return 8
2667
- elif key_hasher == "Identity" :
2668
- return 0
2669
- else :
2670
- raise ValueError ("Unsupported hash type" )
2671
-
2672
2660
if len (result_keys ) > 0 :
2673
2661
last_key = result_keys [- 1 ]
2674
2662
@@ -2681,49 +2669,16 @@ def concat_hash_len(key_hasher: str) -> int:
2681
2669
raise SubstrateRequestException (response ["error" ]["message" ])
2682
2670
2683
2671
for result_group in response ["result" ]:
2684
- for item in result_group ["changes" ]:
2685
- try :
2686
- # Determine type string
2687
- key_type_string = []
2688
- for n in range (len (params ), len (param_types )):
2689
- key_type_string .append (
2690
- f"[u8; { concat_hash_len (key_hashers [n ])} ]"
2691
- )
2692
- key_type_string .append (param_types [n ])
2693
-
2694
- item_key_obj = self .decode_scale (
2695
- type_string = f"({ ', ' .join (key_type_string )} )" ,
2696
- scale_bytes = bytes .fromhex (item [0 ][len (prefix ) :]),
2697
- return_scale_obj = True ,
2698
- )
2699
-
2700
- # strip key_hashers to use as item key
2701
- if len (param_types ) - len (params ) == 1 :
2702
- item_key = item_key_obj [1 ]
2703
- else :
2704
- item_key = tuple (
2705
- item_key_obj [key + 1 ]
2706
- for key in range (len (params ), len (param_types ) + 1 , 2 )
2707
- )
2708
-
2709
- except Exception as _ :
2710
- if not ignore_decoding_errors :
2711
- raise
2712
- item_key = None
2713
-
2714
- try :
2715
- item_bytes = hex_to_bytes_ (item [1 ])
2716
-
2717
- item_value = self .decode_scale (
2718
- type_string = value_type ,
2719
- scale_bytes = item_bytes ,
2720
- return_scale_obj = True ,
2721
- )
2722
- except Exception as _ :
2723
- if not ignore_decoding_errors :
2724
- raise
2725
- item_value = None
2726
- result .append ([item_key , item_value ])
2672
+ result = decode_query_map (
2673
+ result_group ["changes" ],
2674
+ prefix ,
2675
+ runtime ,
2676
+ param_types ,
2677
+ params ,
2678
+ value_type ,
2679
+ key_hashers ,
2680
+ ignore_decoding_errors ,
2681
+ )
2727
2682
return QueryMapResult (
2728
2683
records = result ,
2729
2684
page_size = page_size ,
0 commit comments