use bitcoin::util::hash::Sha256dHash;
use bitcoin::util::bip143;
-use crypto::sha2::Sha256;
use crypto::digest::Digest;
use secp256k1::{Secp256k1,Message,Signature};
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};
pub struct SimpleManyChannelMonitor<Key> {
monitors: Mutex<HashMap<Key, ChannelMonitor>>,
chain_monitor: Arc<ChainWatchInterface>,
+ broadcaster: Arc<BroadcasterInterface>
}
impl<Key : Send + cmp::Eq + hash::Hash> ChainListener for SimpleManyChannelMonitor<Key> {
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);
}
}
}
impl<Key : Send + cmp::Eq + hash::Hash + 'static> SimpleManyChannelMonitor<Key> {
- pub fn new(chain_monitor: Arc<ChainWatchInterface>) -> Arc<SimpleManyChannelMonitor<Key>> {
+ pub fn new(chain_monitor: Arc<ChainWatchInterface>, broadcaster: Arc<BroadcasterInterface>) -> Arc<SimpleManyChannelMonitor<Key>> {
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);
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
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);
}
}
}