@@ -744,12 +744,15 @@ async def send(self, payload: dict) -> str:
744744 await self ._sending .put (to_send )
745745 return original_id
746746
747- async def unsubscribe (self , subscription_id : str ) -> None :
747+ async def unsubscribe (self , subscription_id : str , method : str = "author_unwatchExtrinsic" ) -> None :
748748 """
749749 Unwatches a watched extrinsic subscription.
750750
751751 Args:
752752 subscription_id: the internal ID of the subscription (typically a hex string)
753+ method: Typically "author_unwatchExtrinsic" for extrinsics, but can have different unsubscribe
754+ methods for things like watching chain head ("chain_unsubscribeFinalizedHeads" or
755+ "chain_unsubscribeNewHeads")
753756 """
754757 async with self ._lock :
755758 original_id = get_next_id ()
@@ -760,7 +763,7 @@ async def unsubscribe(self, subscription_id: str) -> None:
760763 to_send = {
761764 "jsonrpc" : "2.0" ,
762765 "id" : original_id ,
763- "method" : "author_unwatchExtrinsic" ,
766+ "method" : method ,
764767 "params" : [subscription_id ],
765768 }
766769 await self ._sending .put (to_send )
@@ -807,7 +810,7 @@ def __init__(
807810 max_retries : int = 5 ,
808811 retry_timeout : float = 60.0 ,
809812 _mock : bool = False ,
810- _log_raw_websockets : bool = False ,
813+ _log_raw_websockets : bool = True , # TODO change this back
811814 ws_shutdown_timer : float = 5.0 ,
812815 decode_ss58 : bool = False ,
813816 ):
@@ -1727,13 +1730,13 @@ async def result_handler(
17271730
17281731 if subscription_result is not None :
17291732 reached = True
1733+ logger .info ("REACHED!" )
17301734 # Handler returned end result: unsubscribe from further updates
1731- self ._forgettable_task = asyncio . create_task (
1732- self . rpc_request (
1733- f"chain_unsubscribe { rpc_method_prefix } Heads" ,
1734- [ subscription_id ] ,
1735+ async with self .ws as ws :
1736+ await ws . unsubscribe (
1737+ subscription_id ,
1738+ method = f"chain_unsubscribe { rpc_method_prefix } Heads" ,
17351739 )
1736- )
17371740
17381741 return subscription_result , reached
17391742
0 commit comments