X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fln%2Fchannelmonitor.rs;h=5ac9a6b0ab01cd93eb276b7a68ff29e2b7763298;hb=9606f94caf451d9eb3a690b559e2955486a3e76a;hp=e463b936e61011dd5b2adfab2ef2f87d387495d0;hpb=6185a2819090bd077954244c5e2adaab5efcaa1a;p=rust-lightning diff --git a/src/ln/channelmonitor.rs b/src/ln/channelmonitor.rs index e463b936..5ac9a6b0 100644 --- a/src/ln/channelmonitor.rs +++ b/src/ln/channelmonitor.rs @@ -4,7 +4,6 @@ use bitcoin::blockdata::script::Script; use bitcoin::util::hash::Sha256dHash; use bitcoin::util::bip143; -use crypto::sha2::Sha256; use crypto::digest::Digest; use secp256k1::{Secp256k1,Message,Signature}; @@ -13,7 +12,8 @@ use secp256k1::key::{SecretKey,PublicKey}; use ln::msgs::HandleError; use ln::chan_utils; use ln::chan_utils::HTLCOutputInCommitment; -use chain::chaininterface::{ChainListener,ChainWatchInterface}; +use chain::chaininterface::{ChainListener, ChainWatchInterface, BroadcasterInterface}; +use util::sha2::Sha256; use std::collections::HashMap; use std::sync::{Arc,Mutex}; @@ -39,13 +39,14 @@ pub trait ManyChannelMonitor: Send + Sync { pub struct SimpleManyChannelMonitor { monitors: Mutex>, chain_monitor: Arc, + broadcaster: Arc } impl ChainListener for SimpleManyChannelMonitor { fn block_connected(&self, _header: &BlockHeader, height: u32, txn_matched: &[&Transaction], _indexes_of_txn_matched: &[u32]) { let monitors = self.monitors.lock().unwrap(); for monitor in monitors.values() { - monitor.block_connected(txn_matched, height, &*self.chain_monitor); + monitor.block_connected(txn_matched, height, &*self.broadcaster); } } @@ -53,10 +54,11 @@ impl ChainListener for SimpleManyChannelMonit } impl SimpleManyChannelMonitor { - pub fn new(chain_monitor: Arc) -> Arc> { + pub fn new(chain_monitor: Arc, broadcaster: Arc) -> Arc> { let res = Arc::new(SimpleManyChannelMonitor { monitors: Mutex::new(HashMap::new()), - chain_monitor: chain_monitor, + chain_monitor, + broadcaster }); let weak_res = Arc::downgrade(&res); res.chain_monitor.register_listener(weak_res); @@ -443,7 +445,7 @@ impl ChannelMonitor { txn_to_broadcast } - fn block_connected(&self, txn_matched: &[&Transaction], height: u32, chain_monitor: &ChainWatchInterface) { + fn block_connected(&self, txn_matched: &[&Transaction], height: u32, broadcaster: &BroadcasterInterface) { for tx in txn_matched { if tx.input.len() != 1 { // We currently only ever sign something spending a commitment or HTLC @@ -454,7 +456,7 @@ impl ChannelMonitor { for txin in tx.input.iter() { if self.funding_txo.is_none() || (txin.prev_hash == self.funding_txo.unwrap().0 && txin.prev_index == self.funding_txo.unwrap().1 as u32) { for tx in self.check_spend_transaction(tx, height).iter() { - chain_monitor.broadcast_transaction(tx); + broadcaster.broadcast_transaction(tx); } } }