@@ -53,9 +53,9 @@ pub trait ChainWatchInterface: Sync + Send {
53
53
/// final two the output within the transaction.
54
54
fn get_chain_utxo ( & self , genesis_hash : BlockHash , unspent_tx_output_identifier : u64 ) -> Result < ( Script , u64 ) , ChainError > ;
55
55
56
- /// Gets the list of transactions and transaction indices that the ChainWatchInterface is
56
+ /// Gets the list of transaction indices within a given block that the ChainWatchInterface is
57
57
/// watching for.
58
- fn filter_block < ' a > ( & self , block : & ' a Block ) -> ( Vec < & ' a Transaction > , Vec < u32 > ) ;
58
+ fn filter_block ( & self , block : & Block ) -> Vec < usize > ;
59
59
60
60
/// Returns a usize that changes when the ChainWatchInterface's watched data is modified.
61
61
/// Users of `filter_block` should pre-save a copy of `reentered`'s return value and use it to
@@ -86,7 +86,7 @@ pub trait ChainListener: Sync + Send {
86
86
///
87
87
/// This also means those counting confirmations using block_connected callbacks should watch
88
88
/// for duplicate headers and not count them towards confirmations!
89
- fn block_connected ( & self , header : & BlockHeader , height : u32 , txn_matched : & [ & Transaction ] , indexes_of_txn_matched : & [ u32 ] ) ;
89
+ fn block_connected ( & self , header : & BlockHeader , height : u32 , txn_matched : & [ & Transaction ] , indexes_of_txn_matched : & [ usize ] ) ;
90
90
/// Notifies a listener that a block was disconnected.
91
91
/// Unlike block_connected, this *must* never be called twice for the same disconnect event.
92
92
/// Height must be the one of the block which was disconnected (not new height of the best chain)
@@ -274,11 +274,15 @@ impl<'a, CL: Deref<Target = ChainListener + 'a> + 'a, C: Deref> BlockNotifier<'a
274
274
///
275
275
/// Handles re-scanning the block and calling block_connected again if listeners register new
276
276
/// watch data during the callbacks for you (see ChainListener::block_connected for more info).
277
- pub fn block_connected < ' b > ( & self , block : & ' b Block , height : u32 ) {
277
+ pub fn block_connected ( & self , block : & Block , height : u32 ) {
278
278
let mut reentered = true ;
279
279
while reentered {
280
- let ( matched, matched_index) = self . chain_monitor . filter_block ( block) ;
281
- reentered = self . block_connected_checked ( & block. header , height, matched. as_slice ( ) , matched_index. as_slice ( ) ) ;
280
+ let matched_indexes = self . chain_monitor . filter_block ( block) ;
281
+ let mut matched_txn = Vec :: new ( ) ;
282
+ for index in matched_indexes. iter ( ) {
283
+ matched_txn. push ( & block. txdata [ * index] ) ;
284
+ }
285
+ reentered = self . block_connected_checked ( & block. header , height, matched_txn. as_slice ( ) , matched_indexes. as_slice ( ) ) ;
282
286
}
283
287
}
284
288
@@ -288,7 +292,7 @@ impl<'a, CL: Deref<Target = ChainListener + 'a> + 'a, C: Deref> BlockNotifier<'a
288
292
/// Returns true if notified listeners registered additional watch data (implying that the
289
293
/// block must be re-scanned and this function called again prior to further block_connected
290
294
/// calls, see ChainListener::block_connected for more info).
291
- pub fn block_connected_checked ( & self , header : & BlockHeader , height : u32 , txn_matched : & [ & Transaction ] , indexes_of_txn_matched : & [ u32 ] ) -> bool {
295
+ pub fn block_connected_checked ( & self , header : & BlockHeader , height : u32 , txn_matched : & [ & Transaction ] , indexes_of_txn_matched : & [ usize ] ) -> bool {
292
296
let last_seen = self . chain_monitor . reentered ( ) ;
293
297
294
298
let listeners = self . listeners . lock ( ) . unwrap ( ) ;
@@ -357,19 +361,17 @@ impl ChainWatchInterface for ChainWatchInterfaceUtil {
357
361
Err ( ChainError :: NotSupported )
358
362
}
359
363
360
- fn filter_block < ' a > ( & self , block : & ' a Block ) -> ( Vec < & ' a Transaction > , Vec < u32 > ) {
361
- let mut matched = Vec :: new ( ) ;
364
+ fn filter_block ( & self , block : & Block ) -> Vec < usize > {
362
365
let mut matched_index = Vec :: new ( ) ;
363
366
{
364
367
let watched = self . watched . lock ( ) . unwrap ( ) ;
365
368
for ( index, transaction) in block. txdata . iter ( ) . enumerate ( ) {
366
369
if self . does_match_tx_unguarded ( transaction, & watched) {
367
- matched. push ( transaction) ;
368
- matched_index. push ( index as u32 ) ;
370
+ matched_index. push ( index) ;
369
371
}
370
372
}
371
373
}
372
- ( matched , matched_index)
374
+ matched_index
373
375
}
374
376
375
377
fn reentered ( & self ) -> usize {
0 commit comments