4848 SubstrateMixin ,
4949 Preprocessed ,
5050)
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
5252from async_substrate_interface .utils .decoding import (
5353 _determine_if_old_runtime_call ,
5454 _bt_decode_to_dict_or_list ,
@@ -507,7 +507,6 @@ def __init__(
507507 # TODO reconnection logic
508508 self .ws_url = ws_url
509509 self .ws : Optional ["ClientConnection" ] = None
510- self .id = 0
511510 self .max_subscriptions = max_subscriptions
512511 self .max_connections = max_connections
513512 self .shutdown_timer = shutdown_timer
@@ -543,8 +542,6 @@ async def connect(self, force=False):
543542 connect (self .ws_url , ** self ._options ), timeout = 10
544543 )
545544 self ._receiving_task = asyncio .create_task (self ._start_receiving ())
546- if force :
547- self .id = 100
548545
549546 async def __aexit__ (self , exc_type , exc_val , exc_tb ):
550547 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):
556553 except asyncio .CancelledError :
557554 pass
558555 if self ._in_use == 0 and self .ws is not None :
559- self .id = 0
560556 self ._open_subscriptions = 0
561557 self ._exit_task = asyncio .create_task (self ._exit_with_timer ())
562558
@@ -582,7 +578,6 @@ async def shutdown(self):
582578 self .ws = None
583579 self ._initialized = False
584580 self ._receiving_task = None
585- self .id = 0
586581
587582 async def _recv (self ) -> None :
588583 try :
@@ -625,8 +620,7 @@ async def send(self, payload: dict) -> int:
625620 id: the internal ID of the request (incremented int)
626621 """
627622 # async with self._lock:
628- original_id = self .id
629- self .id += 1
623+ original_id = generate_unique_id (json .dumps (payload ))
630624 # self._open_subscriptions += 1
631625 try :
632626 await self .ws .send (json .dumps ({** payload , ** {"id" : original_id }}))
@@ -735,8 +729,9 @@ async def initialize(self):
735729 chain = await self .rpc_request ("system_chain" , [])
736730 self ._chain = chain .get ("result" )
737731 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 ,
740735 )
741736 for potential_exception in init_load :
742737 if isinstance (potential_exception , Exception ):
0 commit comments