+impl ChainWatchInterfaceUtil {
+ pub fn new() -> ChainWatchInterfaceUtil {
+ ChainWatchInterfaceUtil {
+ watched: Mutex::new((Vec::new(), Vec::new(), false)),
+ listeners: Mutex::new(Vec::new()),
+ reentered: AtomicUsize::new(1)
+ }
+ }
+
+ /// Notify listeners that a block was connected given a full, unfiltered block.
+ /// Handles re-scanning the block and calling block_connected again if listeners register new
+ /// watch data during the callbacks for you (see ChainListener::block_connected for more info).
+ pub fn block_connected_with_filtering(&self, block: &Block, height: u32) {
+ let mut reentered = true;
+ while reentered {
+ let mut matched = Vec::new();
+ let mut matched_index = Vec::new();
+ {
+ let watched = self.watched.lock().unwrap();
+ for (index, transaction) in block.txdata.iter().enumerate() {
+ if self.does_match_tx_unguarded(transaction, &watched) {
+ matched.push(transaction);
+ matched_index.push(index as u32);
+ }
+ }
+ }
+ reentered = self.block_connected_checked(&block.header, height, matched.as_slice(), matched_index.as_slice());
+ }
+ }
+
+ /// Notify listeners that a block was disconnected.
+ pub fn block_disconnected(&self, header: &BlockHeader) {