ChannelKeys provides individual commitment secrets
[rust-lightning] / lightning / src / util / test_utils.rs
index e426ec2d340a6967955016352a6b78aa8e09569c..2134c26f9f605e81126bab0632e25eac4227c523 100644 (file)
@@ -22,7 +22,7 @@ use bitcoin::hash_types::{Txid, BlockHash};
 
 use bitcoin::secp256k1::{SecretKey, PublicKey, Secp256k1, Signature};
 
-use std::time::{SystemTime, UNIX_EPOCH};
+use std::time::Duration;
 use std::sync::Mutex;
 use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
 use std::{cmp, mem};
@@ -40,10 +40,10 @@ impl Writer for TestVecWriter {
 }
 
 pub struct TestFeeEstimator {
-       pub sat_per_kw: u64,
+       pub sat_per_kw: u32,
 }
 impl chaininterface::FeeEstimator for TestFeeEstimator {
-       fn get_est_sat_per_1000_weight(&self, _confirmation_target: ConfirmationTarget) -> u64 {
+       fn get_est_sat_per_1000_weight(&self, _confirmation_target: ConfirmationTarget) -> u32 {
                self.sat_per_kw
        }
 }
@@ -344,13 +344,16 @@ impl keysinterface::KeysInterface for TestKeysInterface {
 
 impl TestKeysInterface {
        pub fn new(seed: &[u8; 32], network: Network) -> Self {
-               let now = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time went backwards");
+               let now = Duration::from_secs(genesis_block(network).header.time as u64);
                Self {
                        backing: keysinterface::KeysManager::new(seed, network, now.as_secs(), now.subsec_nanos()),
                        override_session_priv: Mutex::new(None),
                        override_channel_id_priv: Mutex::new(None),
                }
        }
+       pub fn derive_channel_keys(&self, channel_value_satoshis: u64, user_id_1: u64, user_id_2: u64) -> EnforcingChannelKeys {
+               EnforcingChannelKeys::new(self.backing.derive_channel_keys(channel_value_satoshis, user_id_1, user_id_2))
+       }
 }
 
 pub struct TestChainWatcher {
@@ -368,8 +371,8 @@ impl ChainWatchInterface for TestChainWatcher {
        fn install_watch_tx(&self, _txid: &Txid, _script_pub_key: &Script) { }
        fn install_watch_outpoint(&self, _outpoint: (Txid, u32), _out_script: &Script) { }
        fn watch_all_txn(&self) { }
-       fn filter_block<'a>(&self, _block: &'a Block) -> (Vec<&'a Transaction>, Vec<u32>) {
-               (Vec::new(), Vec::new())
+       fn filter_block<'a>(&self, _block: &'a Block) -> Vec<usize> {
+               Vec::new()
        }
        fn reentered(&self) -> usize { 0 }