Merge pull request #17 from TheBlueMatt/2017-04-channel-close
[rust-lightning] / src / util / test_utils.rs
index beb50940e45dbedb7548c1b1dbfc4acf76f64c8f..5d657b13df585922626d37c9950d303838c3d8ae 100644 (file)
@@ -3,11 +3,10 @@ use chain::chaininterface::ConfirmationTarget;
 use ln::channelmonitor;
 use ln::msgs::HandleError;
 
-use bitcoin::util::hash::Sha256dHash;
 use bitcoin::blockdata::transaction::Transaction;
-use bitcoin::blockdata::script::Script;
+use bitcoin::util::hash::Sha256dHash;
 
-use std::sync::Weak;
+use std::sync::Mutex;
 
 pub struct TestFeeEstimator {
        pub sat_per_vbyte: u64,
@@ -18,34 +17,6 @@ impl chaininterface::FeeEstimator for TestFeeEstimator {
        }
 }
 
-pub struct TestWatchInterface {
-       pub watch_util: chaininterface::ChainWatchInterfaceUtil,
-}
-impl chaininterface::ChainWatchInterface for TestWatchInterface {
-       fn install_watch_script(&self, _script_pub_key: Script) {
-               unimplemented!();
-       }
-       fn install_watch_outpoint(&self, _outpoint: (Sha256dHash, u32)) {
-               unimplemented!();
-       }
-       fn watch_all_txn(&self) {
-               unimplemented!();
-       }
-       fn broadcast_transaction(&self, _tx: &Transaction) {
-               unimplemented!();
-       }
-       fn register_listener(&self, listener: Weak<chaininterface::ChainListener>) {
-               self.watch_util.register_listener(listener);
-       }
-}
-impl TestWatchInterface {
-       pub fn new() -> TestWatchInterface {
-               TestWatchInterface {
-                       watch_util: chaininterface::ChainWatchInterfaceUtil::new(),
-               }
-       }
-}
-
 pub struct TestChannelMonitor {
 
 }
@@ -55,3 +26,12 @@ impl channelmonitor::ManyChannelMonitor for TestChannelMonitor {
                Ok(())
        }
 }
+
+pub struct TestBroadcaster {
+       pub txn_broadcasted: Mutex<Vec<Transaction>>,
+}
+impl chaininterface::BroadcasterInterface for TestBroadcaster {
+       fn broadcast_transaction(&self, tx: &Transaction) {
+               self.txn_broadcasted.lock().unwrap().push(tx.clone());
+       }
+}