48
48
SubstrateMixin ,
49
49
Preprocessed ,
50
50
)
51
- from async_substrate_interface .utils import hex_to_bytes , json
51
+ from async_substrate_interface .utils import hex_to_bytes , json , generate_unique_id
52
52
from async_substrate_interface .utils .decoding import (
53
53
_determine_if_old_runtime_call ,
54
54
_bt_decode_to_dict_or_list ,
@@ -507,7 +507,6 @@ def __init__(
507
507
# TODO reconnection logic
508
508
self .ws_url = ws_url
509
509
self .ws : Optional ["ClientConnection" ] = None
510
- self .id = 0
511
510
self .max_subscriptions = max_subscriptions
512
511
self .max_connections = max_connections
513
512
self .shutdown_timer = shutdown_timer
@@ -543,8 +542,6 @@ async def connect(self, force=False):
543
542
connect (self .ws_url , ** self ._options ), timeout = 10
544
543
)
545
544
self ._receiving_task = asyncio .create_task (self ._start_receiving ())
546
- if force :
547
- self .id = 100
548
545
549
546
async def __aexit__ (self , exc_type , exc_val , exc_tb ):
550
547
async with self ._lock : # TODO is this actually what I want to happen?
@@ -556,7 +553,6 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
556
553
except asyncio .CancelledError :
557
554
pass
558
555
if self ._in_use == 0 and self .ws is not None :
559
- self .id = 0
560
556
self ._open_subscriptions = 0
561
557
self ._exit_task = asyncio .create_task (self ._exit_with_timer ())
562
558
@@ -582,7 +578,6 @@ async def shutdown(self):
582
578
self .ws = None
583
579
self ._initialized = False
584
580
self ._receiving_task = None
585
- self .id = 0
586
581
587
582
async def _recv (self ) -> None :
588
583
try :
@@ -625,8 +620,7 @@ async def send(self, payload: dict) -> int:
625
620
id: the internal ID of the request (incremented int)
626
621
"""
627
622
# async with self._lock:
628
- original_id = self .id
629
- self .id += 1
623
+ original_id = generate_unique_id (json .dumps (payload ))
630
624
# self._open_subscriptions += 1
631
625
try :
632
626
await self .ws .send (json .dumps ({** payload , ** {"id" : original_id }}))
@@ -735,8 +729,9 @@ async def initialize(self):
735
729
chain = await self .rpc_request ("system_chain" , [])
736
730
self ._chain = chain .get ("result" )
737
731
init_load = await asyncio .gather (
738
- self .load_registry (), self ._first_initialize_runtime (),
739
- return_exceptions = True
732
+ self .load_registry (),
733
+ self ._first_initialize_runtime (),
734
+ return_exceptions = True ,
740
735
)
741
736
for potential_exception in init_load :
742
737
if isinstance (potential_exception , Exception ):
0 commit comments