-impl<Key : Send + cmp::Eq + hash::Hash, ChanSigner: ChannelKeys, T: Deref + Sync + Send, F: Deref + Sync + Send, L: Deref + Sync + Send, C: Deref + Sync + Send>
- ChainListener for SimpleManyChannelMonitor<Key, ChanSigner, T, F, L, C>
+struct WatchEventQueue {
+ watched: ChainWatchedUtil,
+ events: Vec<chain::WatchEvent>,
+}
+
+impl WatchEventQueue {
+ fn new() -> Self {
+ Self {
+ watched: ChainWatchedUtil::new(),
+ events: Vec::new(),
+ }
+ }
+
+ fn watch_tx(&mut self, txid: &Txid, script_pubkey: &Script) {
+ if self.watched.register_tx(txid, script_pubkey) {
+ self.events.push(chain::WatchEvent::WatchTransaction {
+ txid: *txid,
+ script_pubkey: script_pubkey.clone()
+ });
+ }
+ }
+
+ fn watch_output(&mut self, outpoint: (&Txid, usize), script_pubkey: &Script) {
+ let (txid, index) = outpoint;
+ if self.watched.register_outpoint((*txid, index as u32), script_pubkey) {
+ self.events.push(chain::WatchEvent::WatchOutput {
+ outpoint: OutPoint {
+ txid: *txid,
+ index: index as u16,
+ },
+ script_pubkey: script_pubkey.clone(),
+ });
+ }
+ }
+
+ fn dequeue_events(&mut self) -> Vec<chain::WatchEvent> {
+ let mut pending_events = Vec::with_capacity(self.events.len());
+ pending_events.append(&mut self.events);
+ pending_events
+ }
+
+ fn filter_block<'a>(&self, txdata: &[(usize, &'a Transaction)]) -> Vec<(usize, &'a Transaction)> {
+ let mut matched_txids = HashSet::new();
+ txdata.iter().filter(|&&(_, tx)| {
+ // A tx matches the filter if it either matches the filter directly (via does_match_tx)
+ // or if it is a descendant of another matched transaction within the same block.
+ let mut matched = self.watched.does_match_tx(tx);
+ for input in tx.input.iter() {
+ if matched || matched_txids.contains(&input.previous_output.txid) {
+ matched = true;
+ break;
+ }
+ }
+ if matched {
+ matched_txids.insert(tx.txid());
+ }
+ matched
+ }).map(|e| *e).collect()
+ }
+}
+
+impl<Key : Send + cmp::Eq + hash::Hash, ChanSigner: ChannelKeys, T: Deref + Sync + Send, F: Deref + Sync + Send, L: Deref + Sync + Send>
+ ChainListener for SimpleManyChannelMonitor<Key, ChanSigner, T, F, L>