X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fchannelmonitor.rs;fp=lightning%2Fsrc%2Fln%2Fchannelmonitor.rs;h=20e8a2fdabe4cbad97cd816fd2b0d35e7e8526a9;hb=3670dd086ca43295d186d3b957fa99a9d1c458f0;hp=eaf207cd2745b49c54d2141ebdf16ab5fdc048f1;hpb=f952cc27d6d1c3e356ea46a5f63beec1f4105db9;p=rust-lightning diff --git a/lightning/src/ln/channelmonitor.rs b/lightning/src/ln/channelmonitor.rs index eaf207cd..20e8a2fd 100644 --- a/lightning/src/ln/channelmonitor.rs +++ b/lightning/src/ln/channelmonitor.rs @@ -43,6 +43,7 @@ use util::{byte_utils, events}; use std::collections::{HashMap, hash_map, HashSet}; use std::sync::{Arc,Mutex}; use std::{hash,cmp, mem}; +use std::ops::Deref; /// An error enum representing a failure to persist a channel monitor update. #[derive(Clone)] @@ -151,19 +152,21 @@ pub trait ManyChannelMonitor: Send + Sync { /// /// If you're using this for local monitoring of your own channels, you probably want to use /// `OutPoint` as the key, which will give you a ManyChannelMonitor implementation. -pub struct SimpleManyChannelMonitor { +pub struct SimpleManyChannelMonitor where T::Target: BroadcasterInterface { #[cfg(test)] // Used in ChannelManager tests to manipulate channels directly pub monitors: Mutex>>, #[cfg(not(test))] monitors: Mutex>>, chain_monitor: Arc, - broadcaster: Arc, + broadcaster: T, pending_events: Mutex>, logger: Arc, fee_estimator: Arc } -impl<'a, Key : Send + cmp::Eq + hash::Hash, ChanSigner: ChannelKeys> ChainListener for SimpleManyChannelMonitor { +impl<'a, Key : Send + cmp::Eq + hash::Hash, ChanSigner: ChannelKeys, T: Deref + Sync + Send> ChainListener for SimpleManyChannelMonitor + where T::Target: BroadcasterInterface +{ fn block_connected(&self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], _indexes_of_txn_matched: &[u32]) { let block_hash = header.bitcoin_hash(); let mut new_events: Vec = Vec::with_capacity(0); @@ -197,10 +200,12 @@ impl<'a, Key : Send + cmp::Eq + hash::Hash, ChanSigner: ChannelKeys> ChainListen } } -impl SimpleManyChannelMonitor { +impl SimpleManyChannelMonitor + where T::Target: BroadcasterInterface +{ /// Creates a new object which can be used to monitor several channels given the chain /// interface with which to register to receive notifications. - pub fn new(chain_monitor: Arc, broadcaster: Arc, logger: Arc, feeest: Arc) -> SimpleManyChannelMonitor { + pub fn new(chain_monitor: Arc, broadcaster: T, logger: Arc, feeest: Arc) -> SimpleManyChannelMonitor { let res = SimpleManyChannelMonitor { monitors: Mutex::new(HashMap::new()), chain_monitor, @@ -250,7 +255,9 @@ impl Simpl } } -impl ManyChannelMonitor for SimpleManyChannelMonitor { +impl ManyChannelMonitor for SimpleManyChannelMonitor + where T::Target: BroadcasterInterface +{ fn add_update_monitor(&self, funding_txo: OutPoint, monitor: ChannelMonitor) -> Result<(), ChannelMonitorUpdateErr> { match self.add_update_monitor_by_key(funding_txo, monitor) { Ok(_) => Ok(()), @@ -267,7 +274,9 @@ impl ManyChannelMonitor for SimpleManyChann } } -impl events::EventsProvider for SimpleManyChannelMonitor { +impl events::EventsProvider for SimpleManyChannelMonitor + where T::Target: BroadcasterInterface +{ fn get_and_clear_pending_events(&self) -> Vec { let mut pending_events = self.pending_events.lock().unwrap(); let mut ret = Vec::new(); @@ -2387,7 +2396,9 @@ impl ChannelMonitor { /// Eventually this should be pub and, roughly, implement ChainListener, however this requires /// &mut self, as well as returns new spendable outputs and outpoints to watch for spending of /// on-chain. - fn block_connected(&mut self, txn_matched: &[&Transaction], height: u32, block_hash: &Sha256dHash, broadcaster: &BroadcasterInterface, fee_estimator: &FeeEstimator)-> (Vec<(Sha256dHash, Vec)>, Vec) { + fn block_connected(&mut self, txn_matched: &[&Transaction], height: u32, block_hash: &Sha256dHash, broadcaster: B, fee_estimator: &FeeEstimator)-> (Vec<(Sha256dHash, Vec)>, Vec) + where B::Target: BroadcasterInterface + { for tx in txn_matched { let mut output_val = 0; for out in tx.output.iter() { @@ -2620,7 +2631,9 @@ impl ChannelMonitor { (watch_outputs, spendable_outputs) } - fn block_disconnected(&mut self, height: u32, block_hash: &Sha256dHash, broadcaster: &BroadcasterInterface, fee_estimator: &FeeEstimator) { + fn block_disconnected(&mut self, height: u32, block_hash: &Sha256dHash, broadcaster: B, fee_estimator: &FeeEstimator) + where B::Target: BroadcasterInterface + { log_trace!(self, "Block {} at height {} disconnected", block_hash, height); let mut bump_candidates = HashMap::new(); if let Some(events) = self.onchain_events_waiting_threshold_conf.remove(&(height + ANTI_REORG_DELAY - 1)) {