@@ -744,12 +744,15 @@ async def send(self, payload: dict) -> str:
744
744
await self ._sending .put (to_send )
745
745
return original_id
746
746
747
- async def unsubscribe (self , subscription_id : str ) -> None :
747
+ async def unsubscribe (self , subscription_id : str , method : str = "author_unwatchExtrinsic" ) -> None :
748
748
"""
749
749
Unwatches a watched extrinsic subscription.
750
750
751
751
Args:
752
752
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")
753
756
"""
754
757
async with self ._lock :
755
758
original_id = get_next_id ()
@@ -760,7 +763,7 @@ async def unsubscribe(self, subscription_id: str) -> None:
760
763
to_send = {
761
764
"jsonrpc" : "2.0" ,
762
765
"id" : original_id ,
763
- "method" : "author_unwatchExtrinsic" ,
766
+ "method" : method ,
764
767
"params" : [subscription_id ],
765
768
}
766
769
await self ._sending .put (to_send )
@@ -807,7 +810,7 @@ def __init__(
807
810
max_retries : int = 5 ,
808
811
retry_timeout : float = 60.0 ,
809
812
_mock : bool = False ,
810
- _log_raw_websockets : bool = False ,
813
+ _log_raw_websockets : bool = True , # TODO change this back
811
814
ws_shutdown_timer : float = 5.0 ,
812
815
decode_ss58 : bool = False ,
813
816
):
@@ -1727,13 +1730,13 @@ async def result_handler(
1727
1730
1728
1731
if subscription_result is not None :
1729
1732
reached = True
1733
+ logger .info ("REACHED!" )
1730
1734
# 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" ,
1735
1739
)
1736
- )
1737
1740
1738
1741
return subscription_result , reached
1739
1742
0 commit comments