40
40
import sr25519
41
41
42
42
43
- log = logging .getLogger (__name__ )
43
+ logger = logging .getLogger (__name__ )
44
44
45
45
46
46
class Keypair :
@@ -198,6 +198,7 @@ def __init__(self, url, address_type=None, type_registry=None, type_registry_pre
198
198
self .transaction_version = None
199
199
200
200
self .block_hash = None
201
+ self .block_id = None
201
202
202
203
self .metadata_cache = {}
203
204
self .type_registry_cache = {}
@@ -207,7 +208,7 @@ def __init__(self, url, address_type=None, type_registry=None, type_registry_pre
207
208
self .debug = False
208
209
209
210
def debug_message (self , message ):
210
- log .debug (message )
211
+ logger .debug (message )
211
212
212
213
def rpc_request (self , method , params , result_handler = None ):
213
214
"""
@@ -583,7 +584,7 @@ def generate_storage_hash(self, storage_module, storage_function, params=None, h
583
584
584
585
"""
585
586
586
- if metadata_version and metadata_version >= 9 :
587
+ if not metadata_version or metadata_version >= 9 :
587
588
storage_hash = xxh128 (storage_module .encode ()) + xxh128 (storage_function .encode ())
588
589
589
590
if params :
@@ -684,13 +685,22 @@ def init_runtime(self, block_hash=None, block_id=None):
684
685
if block_id and block_hash :
685
686
raise ValueError ('Cannot provide block_hash and block_id at the same time' )
686
687
688
+ # Check if runtime state already set to current block
689
+ if (block_hash and block_hash == self .block_hash ) or (block_id and block_id == self .block_id ):
690
+ return
691
+
687
692
if block_id :
688
693
block_hash = self .get_block_hash (block_id )
689
694
690
695
self .block_hash = block_hash
696
+ self .block_id = block_id
691
697
692
698
runtime_info = self .get_block_runtime_version (block_hash = self .block_hash )
693
699
700
+ # Check if runtime state already set to current block
701
+ if runtime_info .get ("specVersion" ) == self .runtime_version :
702
+ return
703
+
694
704
self .runtime_version = runtime_info .get ("specVersion" )
695
705
self .transaction_version = runtime_info .get ("transactionVersion" )
696
706
0 commit comments