@@ -66,7 +66,7 @@ def __init__(self, network: 'Network'):
6666 def _reset (self ):
6767 super ()._reset ()
6868 self ._adding_addrs = set ()
69- self ._adding_outpoints = set ()
69+ self ._adding_outpoints = {} # type: dict[str, str] # outpoint->spk_hint
7070 self .requested_addrs = set ()
7171 self .requested_outpoints = set ()
7272 self ._handling_addr_statuses = set ()
@@ -93,8 +93,9 @@ def add_address(self, addr: str) -> None:
9393 if not is_address (addr ): raise ValueError (f"invalid bitcoin address { neuter_bitcoin_address (addr )} " )
9494 self ._adding_addrs .add (addr ) # this lets is_up_to_date already know about addr
9595
96- def add_outpoint (self , outpoint : str ) -> None :
97- self ._adding_outpoints .add (outpoint ) # this lets is_up_to_date already know about outpoint
96+ def add_outpoint (self , outpoint : str , * , spk_hint : str ) -> None :
97+ # this lets is_up_to_date already know about outpoint
98+ self ._adding_outpoints [outpoint ] = spk_hint
9899
99100 async def _add_address (self , addr : str ):
100101 try :
@@ -105,13 +106,13 @@ async def _add_address(self, addr: str):
105106 finally :
106107 self ._adding_addrs .discard (addr ) # ok for addr not to be present
107108
108- async def _add_outpoint (self , outpoint : str ):
109+ async def _add_outpoint (self , outpoint : str , * , spk_hint : str ):
109110 try :
110111 if outpoint in self .requested_outpoints : return
111112 self .requested_outpoints .add (outpoint )
112- await self .taskgroup .spawn (self ._subscribe_to_outpoint , outpoint )
113+ await self .taskgroup .spawn (self ._subscribe_to_outpoint ( outpoint , spk_hint = spk_hint ) )
113114 finally :
114- self ._adding_outpoints .discard (outpoint ) # ok for addr not to be present
115+ self ._adding_outpoints .pop (outpoint , None ) # ok for outpoint not to be present
115116
116117 async def _on_address_status (self , addr : str , status : Optional [str ]):
117118 """Handle the change of the status of an address.
@@ -137,14 +138,14 @@ async def _subscribe_to_address(self, addr):
137138 raise
138139 self ._requests_answered += 1
139140
140- async def _subscribe_to_outpoint (self , outpoint ) :
141+ async def _subscribe_to_outpoint (self , outpoint : str , * , spk_hint : str ) -> None :
141142 self ._requests_sent += 1
142143 txhash , idx = outpoint .split (':' )
143144 idx = int (idx )
144145 self .logger .info (f'subscribe to outpoint: { txhash } :{ idx } ' )
145146 try :
146147 async with self ._network_request_semaphore :
147- await self .session .subscribe ('blockchain.outpoint.subscribe' , [txhash , idx ], self .outpoint_status_queue )
148+ await self .session .subscribe ('blockchain.outpoint.subscribe' , [txhash , idx , spk_hint ], self .outpoint_status_queue )
148149 except RPCError as e :
149150 raise
150151 self ._requests_answered += 1
@@ -365,17 +366,17 @@ async def main(self):
365366 for addr in random_shuffled_copy (self .adb .get_addresses ()):
366367 await self ._add_address (addr )
367368 # add outpoints to bootstrap (race)
368- for outpoint in self .adb ._subscribed_outpoints :
369- await self ._add_outpoint (outpoint )
369+ for outpoint , spk_hint in self .adb ._subscribed_outpoints . items () :
370+ await self ._add_outpoint (outpoint , spk_hint = spk_hint )
370371 # main loop
371372 self ._init_done = True
372373 prev_uptodate = False
373374 while True :
374375 await asyncio .sleep (0.1 )
375376 for addr in self ._adding_addrs .copy (): # copy set to ensure iterator stability
376377 await self ._add_address (addr )
377- for outpoint in list ( self ._adding_outpoints ):
378- await self ._add_outpoint (outpoint )
378+ for outpoint , spk_hint in self ._adding_outpoints . copy (). items ( ):
379+ await self ._add_outpoint (outpoint , spk_hint = spk_hint )
379380 up_to_date = self .adb .is_up_to_date ()
380381 # see if status changed
381382 if (up_to_date != prev_uptodate
0 commit comments