5353ResultHandler = Callable [[dict , Any ], tuple [dict , bool ]]
5454
5555logger = logging .getLogger ("async_substrate_interface" )
56+ raw_websocket_logger = logging .getLogger ("raw_websocket" )
5657
5758
5859class ExtrinsicReceipt :
@@ -485,6 +486,7 @@ def __init__(
485486 max_retries : int = 5 ,
486487 retry_timeout : float = 60.0 ,
487488 _mock : bool = False ,
489+ _log_raw_websockets : bool = False ,
488490 ):
489491 """
490492 The sync compatible version of the subtensor interface commands we use in bittensor. Use this instance only
@@ -501,6 +503,7 @@ def __init__(
501503 max_retries: number of times to retry RPC requests before giving up
502504 retry_timeout: how to long wait since the last ping to retry the RPC request
503505 _mock: whether to use mock version of the subtensor interface
506+ _log_raw_websockets: whether to log raw websocket requests during RPC requests
504507
505508 """
506509 self .max_retries = max_retries
@@ -527,6 +530,7 @@ def __init__(
527530 self .registry_type_map = {}
528531 self .type_id_to_name = {}
529532 self ._mock = _mock
533+ self .log_raw_websockets = _log_raw_websockets
530534 if not _mock :
531535 self .ws = self .connect (init = True )
532536 self .initialize ()
@@ -1831,12 +1835,18 @@ def _make_rpc_request(
18311835 ws = self .connect (init = False if attempt == 1 else True )
18321836 for payload in payloads :
18331837 item_id = get_next_id ()
1834- ws .send (json .dumps ({** payload ["payload" ], ** {"id" : item_id }}))
1838+ to_send = {** payload ["payload" ], ** {"id" : item_id }}
1839+ if self .log_raw_websockets :
1840+ raw_websocket_logger .debug (f"WEBSOCKET_SEND> { to_send } " )
1841+ ws .send (json .dumps (to_send ))
18351842 request_manager .add_request (item_id , payload ["id" ])
18361843
18371844 while True :
18381845 try :
1839- response = json .loads (ws .recv (timeout = self .retry_timeout , decode = False ))
1846+ recd = ws .recv (timeout = self .retry_timeout , decode = False )
1847+ if self .log_raw_websockets :
1848+ raw_websocket_logger .debug (f"WEBSOCKET_RECEIVE> { recd .decode ()} " )
1849+ response = json .loads (recd )
18401850 except (TimeoutError , ConnectionClosed ):
18411851 if attempt >= self .max_retries :
18421852 logger .warning (
0 commit comments