Merge pull request #590 from jkczyz/2020-04-feature-flags
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Wed, 29 Apr 2020 18:49:39 +0000 (18:49 +0000)
committerGitHub <noreply@github.com>
Wed, 29 Apr 2020 18:49:39 +0000 (18:49 +0000)
Features module improvements

35 files changed:
fuzz/Cargo.toml
fuzz/src/chanmon_consistency.rs
fuzz/src/chanmon_deser.rs
fuzz/src/full_stack.rs
fuzz/src/lib.rs
fuzz/src/peer_crypt.rs
fuzz/src/router.rs
lightning-net-tokio/Cargo.toml
lightning-net-tokio/src/lib.rs
lightning/Cargo.toml
lightning/src/chain/chaininterface.rs
lightning/src/chain/keysinterface.rs
lightning/src/chain/transaction.rs
lightning/src/lib.rs
lightning/src/ln/chan_utils.rs
lightning/src/ln/chanmon_update_fail_tests.rs
lightning/src/ln/channel.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/channelmonitor.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/functional_tests.rs
lightning/src/ln/msgs.rs
lightning/src/ln/onchaintx.rs
lightning/src/ln/onion_utils.rs
lightning/src/ln/peer_channel_encryptor.rs
lightning/src/ln/peer_handler.rs
lightning/src/ln/router.rs
lightning/src/util/chacha20poly1305rfc.rs
lightning/src/util/enforcing_trait_impls.rs
lightning/src/util/events.rs
lightning/src/util/fuzz_wrappers.rs
lightning/src/util/macro_logger.rs
lightning/src/util/ser.rs
lightning/src/util/ser_macros.rs
lightning/src/util/test_utils.rs

index 5e3197f8f8f1929c1c35270dd872f6f964130bca..115f3e8a4dc0db632cf417b0ae840051da4c783d 100644 (file)
@@ -19,11 +19,9 @@ stdin_fuzz = []
 [dependencies]
 afl = { version = "0.4", optional = true }
 lightning = { path = "../lightning", features = ["fuzztarget"] }
-bitcoin = { version = "0.21", features = ["fuzztarget"] }
-bitcoin_hashes = { version = "0.7", features = ["fuzztarget"] }
+bitcoin = { version = "0.23", features = ["fuzztarget"] }
 hex = "0.3"
 honggfuzz = { version = "0.5", optional = true }
-secp256k1 = { version = "0.15", features=["fuzztarget"] }
 libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git", optional = true }
 
 [build-dependencies]
index 8603458e7ef9172d264d945cb5983cd8d9f12e11..135249f7414479c8405003f4fd57398f536c9035 100644 (file)
@@ -16,10 +16,9 @@ use bitcoin::blockdata::script::{Builder, Script};
 use bitcoin::blockdata::opcodes;
 use bitcoin::network::constants::Network;
 
-use bitcoin_hashes::Hash as TraitImport;
-use bitcoin_hashes::hash160::Hash as Hash160;
-use bitcoin_hashes::sha256::Hash as Sha256;
-use bitcoin_hashes::sha256d::Hash as Sha256d;
+use bitcoin::hashes::Hash as TraitImport;
+use bitcoin::hashes::sha256::Hash as Sha256;
+use bitcoin::hash_types::{BlockHash, WPubkeyHash};
 
 use lightning::chain::chaininterface;
 use lightning::chain::transaction::OutPoint;
@@ -40,8 +39,8 @@ use lightning::util::ser::{Readable, ReadableArgs, Writeable, Writer};
 
 use utils::test_logger;
 
-use secp256k1::key::{PublicKey,SecretKey};
-use secp256k1::Secp256k1;
+use bitcoin::secp256k1::key::{PublicKey,SecretKey};
+use bitcoin::secp256k1::Secp256k1;
 
 use std::mem;
 use std::cmp::Ordering;
@@ -114,7 +113,7 @@ impl channelmonitor::ManyChannelMonitor<EnforcingChannelKeys> for TestChannelMon
                        hash_map::Entry::Occupied(entry) => entry,
                        hash_map::Entry::Vacant(_) => panic!("Didn't have monitor on update call"),
                };
-               let mut deserialized_monitor = <(Sha256d, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::
+               let mut deserialized_monitor = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::
                        read(&mut Cursor::new(&map_entry.get().1), Arc::clone(&self.logger)).unwrap().1;
                deserialized_monitor.update_monitor(update.clone(), &&TestBroadcaster {}).unwrap();
                let mut ser = VecWriter(Vec::new());
@@ -144,7 +143,7 @@ impl KeysInterface for KeyProvider {
        fn get_destination_script(&self) -> Script {
                let secp_ctx = Secp256k1::signing_only();
                let channel_monitor_claim_key = SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, self.node_id]).unwrap();
-               let our_channel_monitor_claim_key_hash = Hash160::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
+               let our_channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
                Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script()
        }
 
@@ -215,7 +214,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
                        let mut monitors = HashMap::new();
                        let mut old_monitors = $old_monitors.latest_monitors.lock().unwrap();
                        for (outpoint, (update_id, monitor_ser)) in old_monitors.drain() {
-                               monitors.insert(outpoint, <(Sha256d, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(&monitor_ser), Arc::clone(&logger)).expect("Failed to read monitor").1);
+                               monitors.insert(outpoint, <(BlockHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(&monitor_ser), Arc::clone(&logger)).expect("Failed to read monitor").1);
                                monitor.latest_monitors.lock().unwrap().insert(outpoint, (update_id, monitor_ser));
                        }
                        let mut monitor_refs = HashMap::new();
@@ -233,7 +232,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
                                channel_monitors: &mut monitor_refs,
                        };
 
-                       (<(Sha256d, ChannelManager<EnforcingChannelKeys, Arc<TestChannelMonitor>, Arc<TestBroadcaster>, Arc<KeyProvider>, Arc<FuzzEstimator>>)>::read(&mut Cursor::new(&$ser.0), read_args).expect("Failed to read manager").1, monitor)
+                       (<(BlockHash, ChannelManager<EnforcingChannelKeys, Arc<TestChannelMonitor>, Arc<TestBroadcaster>, Arc<KeyProvider>, Arc<FuzzEstimator>>)>::read(&mut Cursor::new(&$ser.0), read_args).expect("Failed to read manager").1, monitor)
                } }
        }
 
index abff1319a9bccd4fabdfe68ec28fdc8279c1312c..52caf36e1b96c092cd8f029e37b86816a46a8679 100644 (file)
@@ -1,7 +1,7 @@
 // This file is auto-generated by gen_target.sh based on msg_target_template.txt
 // To modify it, modify msg_target_template.txt and run gen_target.sh instead.
 
-use bitcoin_hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hash_types::BlockHash;
 
 use lightning::util::enforcing_trait_impls::EnforcingChannelKeys;
 use lightning::ln::channelmonitor;
@@ -26,10 +26,10 @@ impl Writer for VecWriter {
 #[inline]
 pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
        let logger = Arc::new(test_logger::TestLogger::new("".to_owned(), out));
-       if let Ok((latest_block_hash, monitor)) = <(Sha256dHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(data), logger.clone()) {
+       if let Ok((latest_block_hash, monitor)) = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(data), logger.clone()) {
                let mut w = VecWriter(Vec::new());
                monitor.write_for_disk(&mut w).unwrap();
-               let deserialized_copy = <(Sha256dHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(&w.0), logger.clone()).unwrap();
+               let deserialized_copy = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(&w.0), logger.clone()).unwrap();
                assert!(latest_block_hash == deserialized_copy.0);
                assert!(monitor == deserialized_copy.1);
        }
index 76953548eb4bd4895af9ab7dea4c4e46cb370e5c..d8d4abf9c7a93b5ec5aefc86728fabc714a16002 100644 (file)
@@ -12,11 +12,10 @@ use bitcoin::consensus::encode::deserialize;
 use bitcoin::network::constants::Network;
 use bitcoin::util::hash::BitcoinHash;
 
-use bitcoin_hashes::Hash as TraitImport;
-use bitcoin_hashes::HashEngine as TraitImportEngine;
-use bitcoin_hashes::sha256::Hash as Sha256;
-use bitcoin_hashes::hash160::Hash as Hash160;
-use bitcoin_hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hashes::Hash as TraitImport;
+use bitcoin::hashes::HashEngine as TraitImportEngine;
+use bitcoin::hashes::sha256::Hash as Sha256;
+use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
 
 use lightning::chain::chaininterface::{BroadcasterInterface,ConfirmationTarget,ChainListener,FeeEstimator,ChainWatchInterfaceUtil};
 use lightning::chain::transaction::OutPoint;
@@ -32,13 +31,12 @@ use lightning::util::config::UserConfig;
 
 use utils::test_logger;
 
-use secp256k1::key::{PublicKey,SecretKey};
-use secp256k1::Secp256k1;
+use bitcoin::secp256k1::key::{PublicKey,SecretKey};
+use bitcoin::secp256k1::Secp256k1;
 
 use std::cell::RefCell;
 use std::collections::{HashMap, hash_map};
 use std::cmp;
-use std::hash::Hash;
 use std::sync::Arc;
 use std::sync::atomic::{AtomicU64,AtomicUsize,Ordering};
 
@@ -129,7 +127,7 @@ impl<'a> PartialEq for Peer<'a> {
        }
 }
 impl<'a> Eq for Peer<'a> {}
-impl<'a> Hash for Peer<'a> {
+impl<'a> std::hash::Hash for Peer<'a> {
        fn hash<H : std::hash::Hasher>(&self, h: &mut H) {
                self.id.hash(h)
        }
@@ -142,8 +140,8 @@ struct MoneyLossDetector<'a> {
 
        peers: &'a RefCell<[bool; 256]>,
        funding_txn: Vec<Transaction>,
-       txids_confirmed: HashMap<Sha256dHash, usize>,
-       header_hashes: Vec<Sha256dHash>,
+       txids_confirmed: HashMap<Txid, usize>,
+       header_hashes: Vec<BlockHash>,
        height: usize,
        max_height: usize,
        blocks_connected: u32,
@@ -241,7 +239,7 @@ impl KeysInterface for KeyProvider {
        fn get_destination_script(&self) -> Script {
                let secp_ctx = Secp256k1::signing_only();
                let channel_monitor_claim_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
-               let our_channel_monitor_claim_key_hash = <Hash160 as bitcoin_hashes::Hash>::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
+               let our_channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
                Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script()
        }
 
index f87c7511c13c26469b3502c3746d97e4e57d9716..dbda28acf44d9dee7cb92336a27b7283a5c853ea 100644 (file)
@@ -1,7 +1,5 @@
 extern crate bitcoin;
-extern crate bitcoin_hashes;
 extern crate lightning;
-extern crate secp256k1;
 extern crate hex;
 
 pub mod utils;
index 176a7caab6530dcbf0d6f7cf0f704a9d7e21d96c..0d200d83a194f885d303e1a2d15ae48b118428b9 100644 (file)
@@ -1,6 +1,6 @@
 use lightning::ln::peer_channel_encryptor::PeerChannelEncryptor;
 
-use secp256k1::key::{PublicKey,SecretKey};
+use bitcoin::secp256k1::key::{PublicKey,SecretKey};
 
 use utils::test_logger;
 
index 7dcf1de72217c848cd70fd90497fafb9fac04648..2ff160e4ec844406ef1ff523be18ab6aff7b1532 100644 (file)
@@ -1,7 +1,7 @@
-use bitcoin_hashes::sha256d::Hash as Sha256dHash;
 use bitcoin::blockdata::script::{Script, Builder};
 use bitcoin::blockdata::block::Block;
 use bitcoin::blockdata::transaction::Transaction;
+use bitcoin::hash_types::{Txid, BlockHash};
 
 use lightning::chain::chaininterface::{ChainError,ChainWatchInterface};
 use lightning::ln::channelmanager::ChannelDetails;
@@ -12,7 +12,7 @@ use lightning::ln::router::{Router, RouteHint};
 use lightning::util::logger::Logger;
 use lightning::util::ser::Readable;
 
-use secp256k1::key::PublicKey;
+use bitcoin::secp256k1::key::PublicKey;
 
 use utils::test_logger;
 
@@ -72,15 +72,15 @@ struct DummyChainWatcher {
 }
 
 impl ChainWatchInterface for DummyChainWatcher {
-       fn install_watch_tx(&self, _txid: &Sha256dHash, _script_pub_key: &Script) { }
-       fn install_watch_outpoint(&self, _outpoint: (Sha256dHash, u32), _out_script: &Script) { }
+       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 reentered(&self) -> usize { 0 }
 
-       fn get_chain_utxo(&self, _genesis_hash: Sha256dHash, _unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError> {
+       fn get_chain_utxo(&self, _genesis_hash: BlockHash, _unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError> {
                match self.input.get_slice(2) {
                        Some(&[0, _]) => Err(ChainError::NotSupported),
                        Some(&[1, _]) => Err(ChainError::NotWatched),
index adfedea7bcc2666e46a1d5740eef70f03752ef02..bdcb911395d939e31229a24b9b9851feb939d82d 100644 (file)
@@ -10,10 +10,8 @@ For Rust-Lightning clients which wish to make direct connections to Lightning P2
 """
 
 [dependencies]
-bitcoin = "0.21"
-bitcoin_hashes = "0.7"
+bitcoin = "0.23"
 lightning = { version = "0.0.11", path = "../lightning" }
-secp256k1 = "0.15"
 tokio = { version = ">=0.2.12", features = [ "io-util", "macros", "rt-core", "sync", "tcp", "time" ] }
 
 [dev-dependencies]
index dd0b861c197a54fcd45242bbd4250af919511c90..e460df25e54d192e92548feb5b6053715798fd27 100644 (file)
@@ -16,7 +16,7 @@
 //! ```
 //! use tokio::sync::mpsc;
 //! use tokio::net::TcpStream;
-//! use secp256k1::key::PublicKey;
+//! use bitcoin::secp256k1::key::PublicKey;
 //! use lightning::util::events::EventsProvider;
 //! use std::net::SocketAddr;
 //! use std::sync::Arc;
@@ -59,7 +59,7 @@
 //! }
 //! ```
 
-use secp256k1::key::PublicKey;
+use bitcoin::secp256k1::key::PublicKey;
 
 use tokio::net::TcpStream;
 use tokio::{io, time};
@@ -481,7 +481,7 @@ mod tests {
        use lightning::ln::msgs::*;
        use lightning::ln::peer_handler::{MessageHandler, PeerManager};
        use lightning::util::events::*;
-       use secp256k1::{Secp256k1, SecretKey, PublicKey};
+       use bitcoin::secp256k1::{Secp256k1, SecretKey, PublicKey};
 
        use tokio::sync::mpsc;
 
index 96680b56e4788932070fd4ed1840f5abac2a60d0..50859aab27df683c82b0cab57f44aaaeaf014c5f 100644 (file)
@@ -13,7 +13,7 @@ Still missing tons of error-handling. See GitHub issues for suggested projects i
 [features]
 # Supports tracking channels with a non-bitcoin chain hashes. Currently enables all kinds of fun DoS attacks.
 non_bitcoin_chain_hash_routing = []
-fuzztarget = ["secp256k1/fuzztarget", "bitcoin/fuzztarget", "bitcoin_hashes/fuzztarget"]
+fuzztarget = ["bitcoin/fuzztarget"]
 # Unlog messages superior at targeted level.
 max_level_off = []
 max_level_error = []
@@ -22,12 +22,10 @@ max_level_info = []
 max_level_debug = []
 
 [dependencies]
-bitcoin = "0.21"
-bitcoin_hashes = "0.7"
-secp256k1 = "0.15"
+bitcoin = "0.23"
 
 [dev-dependencies.bitcoin]
-version = "0.21"
+version = "0.23"
 features = ["bitcoinconsensus"]
 
 [dev-dependencies]
index b30ebc1ee1629441ca7ed95e4e27a2518279ad35..814193af0033a21987757b2d1258bd30b988feda 100644 (file)
@@ -9,8 +9,8 @@ use bitcoin::blockdata::transaction::Transaction;
 use bitcoin::blockdata::script::Script;
 use bitcoin::blockdata::constants::genesis_block;
 use bitcoin::util::hash::BitcoinHash;
-use bitcoin_hashes::sha256d::Hash as Sha256dHash;
 use bitcoin::network::constants::Network;
+use bitcoin::hash_types::{Txid, BlockHash};
 
 use util::logger::Logger;
 
@@ -40,11 +40,11 @@ pub enum ChainError {
 /// events).
 pub trait ChainWatchInterface: Sync + Send {
        /// Provides a txid/random-scriptPubKey-in-the-tx which much be watched for.
-       fn install_watch_tx(&self, txid: &Sha256dHash, script_pub_key: &Script);
+       fn install_watch_tx(&self, txid: &Txid, script_pub_key: &Script);
 
        /// Provides an outpoint which must be watched for, providing any transactions which spend the
        /// given outpoint.
-       fn install_watch_outpoint(&self, outpoint: (Sha256dHash, u32), out_script: &Script);
+       fn install_watch_outpoint(&self, outpoint: (Txid, u32), out_script: &Script);
 
        /// Indicates that a listener needs to see all transactions.
        fn watch_all_txn(&self);
@@ -53,7 +53,7 @@ pub trait ChainWatchInterface: Sync + Send {
        /// short_channel_id (aka unspent_tx_output_identier). For BTC/tBTC channels the top three
        /// bytes are the block height, the next 3 the transaction index within the block, and the
        /// final two the output within the transaction.
-       fn get_chain_utxo(&self, genesis_hash: Sha256dHash, unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError>;
+       fn get_chain_utxo(&self, genesis_hash: BlockHash, unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError>;
 
        /// Gets the list of transactions and transaction indices that the ChainWatchInterface is
        /// watching for.
@@ -135,11 +135,11 @@ pub struct ChainWatchedUtil {
        // We are more conservative in matching during testing to ensure everything matches *exactly*,
        // even though during normal runtime we take more optimized match approaches...
        #[cfg(test)]
-       watched_txn: HashSet<(Sha256dHash, Script)>,
+       watched_txn: HashSet<(Txid, Script)>,
        #[cfg(not(test))]
        watched_txn: HashSet<Script>,
 
-       watched_outpoints: HashSet<(Sha256dHash, u32)>,
+       watched_outpoints: HashSet<(Txid, u32)>,
 }
 
 impl ChainWatchedUtil {
@@ -154,7 +154,7 @@ impl ChainWatchedUtil {
 
        /// Registers a tx for monitoring, returning true if it was a new tx and false if we'd already
        /// been watching for it.
-       pub fn register_tx(&mut self, txid: &Sha256dHash, script_pub_key: &Script) -> bool {
+       pub fn register_tx(&mut self, txid: &Txid, script_pub_key: &Script) -> bool {
                if self.watch_all { return false; }
                #[cfg(test)]
                {
@@ -169,7 +169,7 @@ impl ChainWatchedUtil {
 
        /// Registers an outpoint for monitoring, returning true if it was a new outpoint and false if
        /// we'd already been watching for it
-       pub fn register_outpoint(&mut self, outpoint: (Sha256dHash, u32), _script_pub_key: &Script) -> bool {
+       pub fn register_outpoint(&mut self, outpoint: (Txid, u32), _script_pub_key: &Script) -> bool {
                if self.watch_all { return false; }
                self.watched_outpoints.insert(outpoint)
        }
@@ -332,14 +332,14 @@ impl PartialEq for ChainWatchInterfaceUtil {
 
 /// Register listener
 impl ChainWatchInterface for ChainWatchInterfaceUtil {
-       fn install_watch_tx(&self, txid: &Sha256dHash, script_pub_key: &Script) {
+       fn install_watch_tx(&self, txid: &Txid, script_pub_key: &Script) {
                let mut watched = self.watched.lock().unwrap();
                if watched.register_tx(txid, script_pub_key) {
                        self.reentered.fetch_add(1, Ordering::Relaxed);
                }
        }
 
-       fn install_watch_outpoint(&self, outpoint: (Sha256dHash, u32), out_script: &Script) {
+       fn install_watch_outpoint(&self, outpoint: (Txid, u32), out_script: &Script) {
                let mut watched = self.watched.lock().unwrap();
                if watched.register_outpoint(outpoint, out_script) {
                        self.reentered.fetch_add(1, Ordering::Relaxed);
@@ -353,7 +353,7 @@ impl ChainWatchInterface for ChainWatchInterfaceUtil {
                }
        }
 
-       fn get_chain_utxo(&self, genesis_hash: Sha256dHash, _unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError> {
+       fn get_chain_utxo(&self, genesis_hash: BlockHash, _unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError> {
                if genesis_hash != genesis_block(self.network).header.bitcoin_hash() {
                        return Err(ChainError::NotWatched);
                }
index 73c22684c544459eb8bb2f10e24a405623db4d6a..ce865107abc3ee831b25263a7281b08921547155 100644 (file)
@@ -9,15 +9,15 @@ use bitcoin::network::constants::Network;
 use bitcoin::util::bip32::{ExtendedPrivKey, ExtendedPubKey, ChildNumber};
 use bitcoin::util::bip143;
 
-use bitcoin_hashes::{Hash, HashEngine};
-use bitcoin_hashes::sha256::HashEngine as Sha256State;
-use bitcoin_hashes::sha256::Hash as Sha256;
-use bitcoin_hashes::sha256d::Hash as Sha256dHash;
-use bitcoin_hashes::hash160::Hash as Hash160;
+use bitcoin::hashes::{Hash, HashEngine};
+use bitcoin::hashes::sha256::HashEngine as Sha256State;
+use bitcoin::hashes::sha256::Hash as Sha256;
+use bitcoin::hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hash_types::WPubkeyHash;
 
-use secp256k1::key::{SecretKey, PublicKey};
-use secp256k1::{Secp256k1, Signature, Signing};
-use secp256k1;
+use bitcoin::secp256k1::key::{SecretKey, PublicKey};
+use bitcoin::secp256k1::{Secp256k1, Signature, Signing};
+use bitcoin::secp256k1;
 
 use util::byte_utils;
 use util::logger::Logger;
@@ -513,9 +513,9 @@ impl KeysManager {
                                let node_secret = master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(0).unwrap()).expect("Your RNG is busted").private_key.key;
                                let destination_script = match master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(1).unwrap()) {
                                        Ok(destination_key) => {
-                                               let pubkey_hash160 = Hash160::hash(&ExtendedPubKey::from_private(&secp_ctx, &destination_key).public_key.key.serialize()[..]);
+                                               let wpubkey_hash = WPubkeyHash::hash(&ExtendedPubKey::from_private(&secp_ctx, &destination_key).public_key.to_bytes());
                                                Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
-                                                             .push_slice(&pubkey_hash160.into_inner())
+                                                             .push_slice(&wpubkey_hash.into_inner())
                                                              .into_script()
                                        },
                                        Err(_) => panic!("Your RNG is busted"),
index 0f479ff91abdff8c12aabb277d149f9b1646a5b1..33b9c7244a37d1ad13adedda973c70a23c40f10a 100644 (file)
@@ -1,6 +1,6 @@
 //! Contains simple structs describing parts of transactions on the chain.
 
-use bitcoin_hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hash_types::Txid;
 use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint;
 
 /// A reference to a transaction output.
@@ -10,14 +10,14 @@ use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint;
 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
 pub struct OutPoint {
        /// The referenced transaction's txid.
-       pub txid: Sha256dHash,
+       pub txid: Txid,
        /// The index of the referenced output in its transaction's vout.
        pub index: u16,
 }
 
 impl OutPoint {
        /// Creates a new `OutPoint` from the txid and the index.
-       pub fn new(txid: Sha256dHash, index: u16) -> OutPoint {
+       pub fn new(txid: Txid, index: u16) -> OutPoint {
                OutPoint { txid, index }
        }
 
index 68924b57a36af64b7fc01b43efcb4733ca8f3dc7..039f2f3aca1c9e36422aae2bea755f0de4c931cb 100644 (file)
@@ -19,8 +19,6 @@
 #![allow(ellipsis_inclusive_range_patterns)]
 
 extern crate bitcoin;
-extern crate bitcoin_hashes;
-extern crate secp256k1;
 #[cfg(test)] extern crate rand;
 #[cfg(test)] extern crate hex;
 
index 62d3103337d828943cba7e59adbd3b78f9f67ba9..9be3f38a78e6c027c7328a6d5e6c35e69013c8bd 100644 (file)
@@ -8,20 +8,19 @@ use bitcoin::blockdata::transaction::{TxIn,TxOut,OutPoint,Transaction, SigHashTy
 use bitcoin::consensus::encode::{self, Decodable, Encodable};
 use bitcoin::util::bip143;
 
-use bitcoin_hashes::{Hash, HashEngine};
-use bitcoin_hashes::sha256::Hash as Sha256;
-use bitcoin_hashes::ripemd160::Hash as Ripemd160;
-use bitcoin_hashes::hash160::Hash as Hash160;
-use bitcoin_hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hashes::{Hash, HashEngine};
+use bitcoin::hashes::sha256::Hash as Sha256;
+use bitcoin::hashes::ripemd160::Hash as Ripemd160;
+use bitcoin::hash_types::{Txid, PubkeyHash};
 
 use ln::channelmanager::{PaymentHash, PaymentPreimage};
 use ln::msgs::DecodeError;
 use util::ser::{Readable, Writeable, Writer, WriterWriteAdaptor};
 use util::byte_utils;
 
-use secp256k1::key::{SecretKey, PublicKey};
-use secp256k1::{Secp256k1, Signature};
-use secp256k1;
+use bitcoin::secp256k1::key::{SecretKey, PublicKey};
+use bitcoin::secp256k1::{Secp256k1, Signature};
+use bitcoin::secp256k1;
 
 use std::{cmp, mem};
 
@@ -364,7 +363,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
        if htlc.offered {
                Builder::new().push_opcode(opcodes::all::OP_DUP)
                              .push_opcode(opcodes::all::OP_HASH160)
-                             .push_slice(&Hash160::hash(&revocation_key.serialize())[..])
+                             .push_slice(&PubkeyHash::hash(&revocation_key.serialize())[..])
                              .push_opcode(opcodes::all::OP_EQUAL)
                              .push_opcode(opcodes::all::OP_IF)
                              .push_opcode(opcodes::all::OP_CHECKSIG)
@@ -392,7 +391,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
        } else {
                Builder::new().push_opcode(opcodes::all::OP_DUP)
                              .push_opcode(opcodes::all::OP_HASH160)
-                             .push_slice(&Hash160::hash(&revocation_key.serialize())[..])
+                             .push_slice(&PubkeyHash::hash(&revocation_key.serialize())[..])
                              .push_opcode(opcodes::all::OP_EQUAL)
                              .push_opcode(opcodes::all::OP_IF)
                              .push_opcode(opcodes::all::OP_CHECKSIG)
@@ -447,7 +446,7 @@ pub fn make_funding_redeemscript(a: &PublicKey, b: &PublicKey) -> Script {
 }
 
 /// panics if htlc.transaction_output_index.is_none()!
-pub fn build_htlc_transaction(prev_hash: &Sha256dHash, feerate_per_kw: u64, to_self_delay: u16, htlc: &HTLCOutputInCommitment, a_delayed_payment_key: &PublicKey, revocation_key: &PublicKey) -> Transaction {
+pub fn build_htlc_transaction(prev_hash: &Txid, feerate_per_kw: u64, to_self_delay: u16, htlc: &HTLCOutputInCommitment, a_delayed_payment_key: &PublicKey, revocation_key: &PublicKey) -> Transaction {
        let mut txins: Vec<TxIn> = Vec::new();
        txins.push(TxIn {
                previous_output: OutPoint {
@@ -563,7 +562,7 @@ impl LocalCommitmentTransaction {
 
        /// Get the txid of the local commitment transaction contained in this
        /// LocalCommitmentTransaction
-       pub fn txid(&self) -> Sha256dHash {
+       pub fn txid(&self) -> Txid {
                self.unsigned_tx.txid()
        }
 
index 739db729a19bd919383c8e441a6c56c0a528dd38..411c12d990d7151d5a29b95a93a85a46cfc72c1c 100644 (file)
@@ -12,8 +12,8 @@ use ln::msgs::{ChannelMessageHandler, ErrorAction, RoutingMessageHandler};
 use util::events::{Event, EventsProvider, MessageSendEvent, MessageSendEventsProvider};
 use util::errors::APIError;
 
-use bitcoin_hashes::sha256::Hash as Sha256;
-use bitcoin_hashes::Hash;
+use bitcoin::hashes::sha256::Hash as Sha256;
+use bitcoin::hashes::Hash;
 
 use ln::functional_test_utils::*;
 
index 98e515f00215fe952609cf5abda69dab322791d7..469698356af3dcdad9c1e9d50cffc4aad98f78d8 100644 (file)
@@ -6,14 +6,13 @@ use bitcoin::util::hash::BitcoinHash;
 use bitcoin::util::bip143;
 use bitcoin::consensus::encode;
 
-use bitcoin_hashes::{Hash, HashEngine};
-use bitcoin_hashes::sha256::Hash as Sha256;
-use bitcoin_hashes::hash160::Hash as Hash160;
-use bitcoin_hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hashes::{Hash, HashEngine};
+use bitcoin::hashes::sha256::Hash as Sha256;
+use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
 
-use secp256k1::key::{PublicKey,SecretKey};
-use secp256k1::{Secp256k1,Signature};
-use secp256k1;
+use bitcoin::secp256k1::key::{PublicKey,SecretKey};
+use bitcoin::secp256k1::{Secp256k1,Signature};
+use bitcoin::secp256k1;
 
 use ln::features::{ChannelFeatures, InitFeatures};
 use ln::msgs;
@@ -313,11 +312,11 @@ pub(super) struct Channel<ChanSigner: ChannelKeys> {
        /// to detect unconfirmation after a serialize-unserialize roundtrip where we may not see a full
        /// series of block_connected/block_disconnected calls. Obviously this is not a guarantee as we
        /// could miss the funding_tx_confirmed_in block as well, but it serves as a useful fallback.
-       funding_tx_confirmed_in: Option<Sha256dHash>,
+       funding_tx_confirmed_in: Option<BlockHash>,
        short_channel_id: Option<u64>,
        /// Used to deduplicate block_connected callbacks, also used to verify consistency during
        /// ChannelManager deserialization (hence pub(super))
-       pub(super) last_block_connected: Sha256dHash,
+       pub(super) last_block_connected: BlockHash,
        funding_tx_confirmations: u64,
 
        their_dust_limit_satoshis: u64,
@@ -983,7 +982,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
                        log_trace!(self, "   ...including {} output with value {}", if local { "to_remote" } else { "to_local" }, value_to_b);
                        txouts.push((TxOut {
                                script_pubkey: Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
-                                                            .push_slice(&Hash160::hash(&keys.b_payment_key.serialize())[..])
+                                                            .push_slice(&WPubkeyHash::hash(&keys.b_payment_key.serialize())[..])
                                                             .into_script(),
                                value: value_to_b as u64
                        }, None));
@@ -1025,7 +1024,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
 
        #[inline]
        fn get_closing_scriptpubkey(&self) -> Script {
-               let our_channel_close_key_hash = Hash160::hash(&self.shutdown_pubkey.serialize());
+               let our_channel_close_key_hash = WPubkeyHash::hash(&self.shutdown_pubkey.serialize());
                Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_close_key_hash[..]).into_script()
        }
 
@@ -1133,7 +1132,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
        /// Builds the htlc-success or htlc-timeout transaction which spends a given HTLC output
        /// @local is used only to convert relevant internal structures which refer to remote vs local
        /// to decide value of outputs and direction of HTLCs.
-       fn build_htlc_transaction(&self, prev_hash: &Sha256dHash, htlc: &HTLCOutputInCommitment, local: bool, keys: &TxCreationKeys, feerate_per_kw: u64) -> Transaction {
+       fn build_htlc_transaction(&self, prev_hash: &Txid, htlc: &HTLCOutputInCommitment, local: bool, keys: &TxCreationKeys, feerate_per_kw: u64) -> Transaction {
                chan_utils::build_htlc_transaction(prev_hash, feerate_per_kw, if local { self.their_to_self_delay } else { self.our_to_self_delay }, htlc, &keys.a_delayed_payment_key, &keys.revocation_key)
        }
 
@@ -3299,7 +3298,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
        // Methods to get unprompted messages to send to the remote end (or where we already returned
        // something in the handler for the message that prompted this message):
 
-       pub fn get_open_channel<F: Deref>(&self, chain_hash: Sha256dHash, fee_estimator: &F) -> msgs::OpenChannel
+       pub fn get_open_channel<F: Deref>(&self, chain_hash: BlockHash, fee_estimator: &F) -> msgs::OpenChannel
                where F::Target: FeeEstimator
        {
                if !self.channel_outbound {
@@ -3431,7 +3430,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
        /// closing).
        /// Note that the "channel must be funded" requirement is stricter than BOLT 7 requires - see
        /// https://github.com/lightningnetwork/lightning-rfc/issues/468
-       pub fn get_channel_announcement(&self, our_node_id: PublicKey, chain_hash: Sha256dHash) -> Result<(msgs::UnsignedChannelAnnouncement, Signature), ChannelError> {
+       pub fn get_channel_announcement(&self, our_node_id: PublicKey, chain_hash: BlockHash) -> Result<(msgs::UnsignedChannelAnnouncement, Signature), ChannelError> {
                if !self.config.announced_channel {
                        return Err(ChannelError::Ignore("Channel is not available for public announcements"));
                }
@@ -4291,7 +4290,7 @@ mod tests {
        use bitcoin::blockdata::constants::genesis_block;
        use bitcoin::blockdata::opcodes;
        use bitcoin::network::constants::Network;
-       use bitcoin_hashes::hex::FromHex;
+       use bitcoin::hashes::hex::FromHex;
        use hex;
        use ln::channelmanager::{HTLCSource, PaymentPreimage, PaymentHash};
        use ln::channel::{Channel,ChannelKeys,InboundHTLCOutput,OutboundHTLCOutput,InboundHTLCState,OutboundHTLCState,HTLCOutputInCommitment,TxCreationKeys};
@@ -4307,12 +4306,11 @@ mod tests {
        use util::enforcing_trait_impls::EnforcingChannelKeys;
        use util::test_utils;
        use util::logger::Logger;
-       use secp256k1::{Secp256k1, Message, Signature, All};
-       use secp256k1::key::{SecretKey,PublicKey};
-       use bitcoin_hashes::sha256::Hash as Sha256;
-       use bitcoin_hashes::sha256d::Hash as Sha256dHash;
-       use bitcoin_hashes::hash160::Hash as Hash160;
-       use bitcoin_hashes::Hash;
+       use bitcoin::secp256k1::{Secp256k1, Message, Signature, All};
+       use bitcoin::secp256k1::key::{SecretKey,PublicKey};
+       use bitcoin::hashes::sha256::Hash as Sha256;
+       use bitcoin::hashes::Hash;
+       use bitcoin::hash_types::{Txid, WPubkeyHash};
        use std::sync::Arc;
        use rand::{thread_rng,Rng};
 
@@ -4341,7 +4339,7 @@ mod tests {
                fn get_destination_script(&self) -> Script {
                        let secp_ctx = Secp256k1::signing_only();
                        let channel_monitor_claim_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
-                       let our_channel_monitor_claim_key_hash = Hash160::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
+                       let our_channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
                        Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script()
                }
 
@@ -4457,7 +4455,7 @@ mod tests {
                chan.their_to_self_delay = 144;
                chan.our_dust_limit_satoshis = 546;
 
-               let funding_info = OutPoint::new(Sha256dHash::from_hex("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(), 0);
+               let funding_info = OutPoint::new(Txid::from_hex("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(), 0);
                chan.funding_txo = Some(funding_info);
 
                let their_pubkeys = ChannelPublicKeys {
index f9b0f70468afb7024b9cd4ab832e66832416db52..08b28cc0f55dcdc1e037058cb10b26522e58ca27 100644 (file)
@@ -14,16 +14,17 @@ use bitcoin::blockdata::constants::genesis_block;
 use bitcoin::network::constants::Network;
 use bitcoin::util::hash::BitcoinHash;
 
-use bitcoin_hashes::{Hash, HashEngine};
-use bitcoin_hashes::hmac::{Hmac, HmacEngine};
-use bitcoin_hashes::sha256::Hash as Sha256;
-use bitcoin_hashes::sha256d::Hash as Sha256dHash;
-use bitcoin_hashes::cmp::fixed_time_eq;
-
-use secp256k1::key::{SecretKey,PublicKey};
-use secp256k1::Secp256k1;
-use secp256k1::ecdh::SharedSecret;
-use secp256k1;
+use bitcoin::hashes::{Hash, HashEngine};
+use bitcoin::hashes::hmac::{Hmac, HmacEngine};
+use bitcoin::hashes::sha256::Hash as Sha256;
+use bitcoin::hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hashes::cmp::fixed_time_eq;
+use bitcoin::hash_types::BlockHash;
+
+use bitcoin::secp256k1::key::{SecretKey,PublicKey};
+use bitcoin::secp256k1::Secp256k1;
+use bitcoin::secp256k1::ecdh::SharedSecret;
+use bitcoin::secp256k1;
 
 use chain::chaininterface::{BroadcasterInterface,ChainListener,FeeEstimator};
 use chain::transaction::OutPoint;
@@ -375,7 +376,7 @@ pub struct ChannelManager<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref,
         F::Target: FeeEstimator,
 {
        default_configuration: UserConfig,
-       genesis_hash: Sha256dHash,
+       genesis_hash: BlockHash,
        fee_estimator: F,
        monitor: M,
        tx_broadcaster: T,
@@ -384,7 +385,7 @@ pub struct ChannelManager<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref,
        pub(super) latest_block_height: AtomicUsize,
        #[cfg(not(test))]
        latest_block_height: AtomicUsize,
-       last_block_hash: Mutex<Sha256dHash>,
+       last_block_hash: Mutex<BlockHash>,
        secp_ctx: Secp256k1<secp256k1::All>,
 
        #[cfg(test)]
@@ -3686,20 +3687,20 @@ pub struct ChannelManagerReadArgs<'a, ChanSigner: 'a + ChannelKeys, M: Deref, T:
 // Implement ReadableArgs for an Arc'd ChannelManager to make it a bit easier to work with the
 // SipmleArcChannelManager type:
 impl<'a, ChanSigner: ChannelKeys + Readable, M: Deref, T: Deref, K: Deref, F: Deref>
-       ReadableArgs<ChannelManagerReadArgs<'a, ChanSigner, M, T, K, F>> for (Sha256dHash, Arc<ChannelManager<ChanSigner, M, T, K, F>>)
+       ReadableArgs<ChannelManagerReadArgs<'a, ChanSigner, M, T, K, F>> for (BlockHash, Arc<ChannelManager<ChanSigner, M, T, K, F>>)
        where M::Target: ManyChannelMonitor<ChanSigner>,
         T::Target: BroadcasterInterface,
         K::Target: KeysInterface<ChanKeySigner = ChanSigner>,
         F::Target: FeeEstimator,
 {
        fn read<R: ::std::io::Read>(reader: &mut R, args: ChannelManagerReadArgs<'a, ChanSigner, M, T, K, F>) -> Result<Self, DecodeError> {
-               let (blockhash, chan_manager) = <(Sha256dHash, ChannelManager<ChanSigner, M, T, K, F>)>::read(reader, args)?;
+               let (blockhash, chan_manager) = <(BlockHash, ChannelManager<ChanSigner, M, T, K, F>)>::read(reader, args)?;
                Ok((blockhash, Arc::new(chan_manager)))
        }
 }
 
 impl<'a, ChanSigner: ChannelKeys + Readable, M: Deref, T: Deref, K: Deref, F: Deref>
-       ReadableArgs<ChannelManagerReadArgs<'a, ChanSigner, M, T, K, F>> for (Sha256dHash, ChannelManager<ChanSigner, M, T, K, F>)
+       ReadableArgs<ChannelManagerReadArgs<'a, ChanSigner, M, T, K, F>> for (BlockHash, ChannelManager<ChanSigner, M, T, K, F>)
        where M::Target: ManyChannelMonitor<ChanSigner>,
         T::Target: BroadcasterInterface,
         K::Target: KeysInterface<ChanKeySigner = ChanSigner>,
@@ -3712,9 +3713,9 @@ impl<'a, ChanSigner: ChannelKeys + Readable, M: Deref, T: Deref, K: Deref, F: De
                        return Err(DecodeError::UnknownVersion);
                }
 
-               let genesis_hash: Sha256dHash = Readable::read(reader)?;
+               let genesis_hash: BlockHash = Readable::read(reader)?;
                let latest_block_height: u32 = Readable::read(reader)?;
-               let last_block_hash: Sha256dHash = Readable::read(reader)?;
+               let last_block_hash: BlockHash = Readable::read(reader)?;
 
                let mut failed_htlcs = Vec::new();
 
index c417671eca04f40ff7910adce1541b352652966e..71196252a3ca25313f9489086299079438531da0 100644 (file)
@@ -19,14 +19,13 @@ use bitcoin::blockdata::opcodes;
 use bitcoin::consensus::encode;
 use bitcoin::util::hash::BitcoinHash;
 
-use bitcoin_hashes::Hash;
-use bitcoin_hashes::sha256::Hash as Sha256;
-use bitcoin_hashes::hash160::Hash as Hash160;
-use bitcoin_hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hashes::Hash;
+use bitcoin::hashes::sha256::Hash as Sha256;
+use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
 
-use secp256k1::{Secp256k1,Signature};
-use secp256k1::key::{SecretKey,PublicKey};
-use secp256k1;
+use bitcoin::secp256k1::{Secp256k1,Signature};
+use bitcoin::secp256k1::key::{SecretKey,PublicKey};
+use bitcoin::secp256k1;
 
 use ln::msgs::DecodeError;
 use ln::chan_utils;
@@ -409,7 +408,7 @@ pub(crate) const HTLC_FAIL_BACK_BUFFER: u32 = CLTV_CLAIM_BUFFER + LATENCY_GRACE_
 #[derive(Clone, PartialEq)]
 struct LocalSignedTx {
        /// txid of the transaction in tx, just used to make comparison faster
-       txid: Sha256dHash,
+       txid: Txid,
        revocation_key: PublicKey,
        a_htlc_key: PublicKey,
        b_htlc_key: PublicKey,
@@ -727,8 +726,8 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
 
        keys: ChanSigner,
        funding_info: (OutPoint, Script),
-       current_remote_commitment_txid: Option<Sha256dHash>,
-       prev_remote_commitment_txid: Option<Sha256dHash>,
+       current_remote_commitment_txid: Option<Txid>,
+       prev_remote_commitment_txid: Option<Txid>,
 
        their_htlc_base_key: PublicKey,
        their_delayed_payment_base_key: PublicKey,
@@ -741,13 +740,13 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
        their_to_self_delay: u16,
 
        commitment_secrets: CounterpartyCommitmentSecrets,
-       remote_claimable_outpoints: HashMap<Sha256dHash, Vec<(HTLCOutputInCommitment, Option<Box<HTLCSource>>)>>,
+       remote_claimable_outpoints: HashMap<Txid, Vec<(HTLCOutputInCommitment, Option<Box<HTLCSource>>)>>,
        /// We cannot identify HTLC-Success or HTLC-Timeout transactions by themselves on the chain.
        /// Nor can we figure out their commitment numbers without the commitment transaction they are
        /// spending. Thus, in order to claim them via revocation key, we track all the remote
        /// commitment transactions which we find on-chain, mapping them to the commitment number which
        /// can be used to derive the revocation key and claim the transactions.
-       remote_commitment_txn_on_chain: HashMap<Sha256dHash, (u64, Vec<Script>)>,
+       remote_commitment_txn_on_chain: HashMap<Txid, (u64, Vec<Script>)>,
        /// Cache used to make pruning of payment_preimages faster.
        /// Maps payment_hash values to commitment numbers for remote transactions for non-revoked
        /// remote transactions (ie should remain pretty small).
@@ -782,7 +781,7 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
        // interface knows about the TXOs that we want to be notified of spends of. We could probably
        // be smart and derive them from the above storage fields, but its much simpler and more
        // Obviously Correct (tm) if we just keep track of them explicitly.
-       outputs_to_watch: HashMap<Sha256dHash, Vec<Script>>,
+       outputs_to_watch: HashMap<Txid, Vec<Script>>,
 
        #[cfg(test)]
        pub onchain_tx_handler: OnchainTxHandler<ChanSigner>,
@@ -804,7 +803,7 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
        // (we do *not*, however, update them in update_monitor to ensure any local user copies keep
        // their last_block_hash from its state and not based on updated copies that didn't run through
        // the full block_connected).
-       pub(crate) last_block_hash: Sha256dHash,
+       pub(crate) last_block_hash: BlockHash,
        secp_ctx: Secp256k1<secp256k1::All>, //TODO: dedup this a bit...
        logger: Arc<Logger>,
 }
@@ -1061,7 +1060,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
                        logger: Arc<Logger>) -> ChannelMonitor<ChanSigner> {
 
                assert!(commitment_transaction_number_obscure_factor <= (1 << 48));
-               let our_channel_close_key_hash = Hash160::hash(&shutdown_pubkey.serialize());
+               let our_channel_close_key_hash = WPubkeyHash::hash(&shutdown_pubkey.serialize());
                let shutdown_script = Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_close_key_hash[..]).into_script();
 
                let mut onchain_tx_handler = OnchainTxHandler::new(destination_script.clone(), keys.clone(), their_to_self_delay, logger.clone());
@@ -1231,7 +1230,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
        pub(super) fn provide_rescue_remote_commitment_tx_info(&mut self, their_revocation_point: PublicKey) {
                if let Ok(payment_key) = chan_utils::derive_public_key(&self.secp_ctx, &their_revocation_point, &self.keys.pubkeys().payment_basepoint) {
                        let to_remote_script =  Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
-                               .push_slice(&Hash160::hash(&payment_key.serialize())[..])
+                               .push_slice(&WPubkeyHash::hash(&payment_key.serialize())[..])
                                .into_script();
                        if let Ok(to_remote_key) = chan_utils::derive_private_key(&self.secp_ctx, &their_revocation_point, &self.keys.payment_base_key()) {
                                self.broadcasted_remote_payment_script = Some((to_remote_script, to_remote_key));
@@ -1363,7 +1362,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
 
        /// Gets a list of txids, with their output scripts (in the order they appear in the
        /// transaction), which we must learn about spends of via block_connected().
-       pub fn get_outputs_to_watch(&self) -> &HashMap<Sha256dHash, Vec<Script>> {
+       pub fn get_outputs_to_watch(&self) -> &HashMap<Txid, Vec<Script>> {
                &self.outputs_to_watch
        }
 
@@ -1371,7 +1370,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
        /// Generally useful when deserializing as during normal operation the return values of
        /// block_connected are sufficient to ensure all relevant outpoints are being monitored (note
        /// that the get_funding_txo outpoint and transaction must also be monitored for!).
-       pub fn get_monitored_outpoints(&self) -> Vec<(Sha256dHash, u32, &Script)> {
+       pub fn get_monitored_outpoints(&self) -> Vec<(Txid, u32, &Script)> {
                let mut res = Vec::with_capacity(self.remote_commitment_txn_on_chain.len() * 2);
                for (ref txid, &(_, ref outputs)) in self.remote_commitment_txn_on_chain.iter() {
                        for (idx, output) in outputs.iter().enumerate() {
@@ -1424,7 +1423,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
        /// HTLC-Success/HTLC-Timeout transactions.
        /// Return updates for HTLC pending in the channel and failed automatically by the broadcast of
        /// revoked remote commitment tx
-       fn check_spend_remote_transaction(&mut self, tx: &Transaction, height: u32) -> (Vec<ClaimRequest>, (Sha256dHash, Vec<TxOut>)) {
+       fn check_spend_remote_transaction(&mut self, tx: &Transaction, height: u32) -> (Vec<ClaimRequest>, (Txid, Vec<TxOut>)) {
                // Most secp and related errors trying to create keys means we have no hope of constructing
                // a spend transaction...so we return no transactions to broadcast
                let mut claimable_outpoints = Vec::new();
@@ -1460,7 +1459,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
                        self.broadcasted_remote_payment_script = {
                                // Note that the Network here is ignored as we immediately drop the address for the
                                // script_pubkey version
-                               let payment_hash160 = Hash160::hash(&PublicKey::from_secret_key(&self.secp_ctx, &local_payment_key).serialize());
+                               let payment_hash160 = WPubkeyHash::hash(&PublicKey::from_secret_key(&self.secp_ctx, &local_payment_key).serialize());
                                Some((Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&payment_hash160[..]).into_script(), local_payment_key))
                        };
 
@@ -1609,7 +1608,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
                                        self.broadcasted_remote_payment_script = {
                                                // Note that the Network here is ignored as we immediately drop the address for the
                                                // script_pubkey version
-                                               let payment_hash160 = Hash160::hash(&PublicKey::from_secret_key(&self.secp_ctx, &local_payment_key).serialize());
+                                               let payment_hash160 = WPubkeyHash::hash(&PublicKey::from_secret_key(&self.secp_ctx, &local_payment_key).serialize());
                                                Some((Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&payment_hash160[..]).into_script(), local_payment_key))
                                        };
 
@@ -1637,7 +1636,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
        }
 
        /// Attempts to claim a remote HTLC-Success/HTLC-Timeout's outputs using the revocation key
-       fn check_spend_remote_htlc(&mut self, tx: &Transaction, commitment_number: u64, height: u32) -> (Vec<ClaimRequest>, Option<(Sha256dHash, Vec<TxOut>)>) {
+       fn check_spend_remote_htlc(&mut self, tx: &Transaction, commitment_number: u64, height: u32) -> (Vec<ClaimRequest>, Option<(Txid, Vec<TxOut>)>) {
                let htlc_txid = tx.txid();
                if tx.input.len() != 1 || tx.output.len() != 1 || tx.input[0].witness.len() != 5 {
                        return (Vec::new(), None)
@@ -1699,7 +1698,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
        /// Attempts to claim any claimable HTLCs in a commitment transaction which was not (yet)
        /// revoked using data in local_claimable_outpoints.
        /// Should not be used if check_spend_revoked_transaction succeeds.
-       fn check_spend_local_transaction(&mut self, tx: &Transaction, height: u32) -> (Vec<ClaimRequest>, (Sha256dHash, Vec<TxOut>)) {
+       fn check_spend_local_transaction(&mut self, tx: &Transaction, height: u32) -> (Vec<ClaimRequest>, (Txid, Vec<TxOut>)) {
                let commitment_txid = tx.txid();
                let mut claim_requests = Vec::new();
                let mut watch_outputs = Vec::new();
@@ -1843,7 +1842,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
        /// 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<B: Deref, F: Deref>(&mut self, txn_matched: &[&Transaction], height: u32, block_hash: &Sha256dHash, broadcaster: B, fee_estimator: F)-> Vec<(Sha256dHash, Vec<TxOut>)>
+       fn block_connected<B: Deref, F: Deref>(&mut self, txn_matched: &[&Transaction], height: u32, block_hash: &BlockHash, broadcaster: B, fee_estimator: F)-> Vec<(Txid, Vec<TxOut>)>
                where B::Target: BroadcasterInterface,
                      F::Target: FeeEstimator
        {
@@ -1941,7 +1940,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
                watch_outputs
        }
 
-       fn block_disconnected<B: Deref, F: Deref>(&mut self, height: u32, block_hash: &Sha256dHash, broadcaster: B, fee_estimator: F)
+       fn block_disconnected<B: Deref, F: Deref>(&mut self, height: u32, block_hash: &BlockHash, broadcaster: B, fee_estimator: F)
                where B::Target: BroadcasterInterface,
                      F::Target: FeeEstimator
        {
@@ -2210,7 +2209,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
 
 const MAX_ALLOC_SIZE: usize = 64*1024;
 
-impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dHash, ChannelMonitor<ChanSigner>) {
+impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (BlockHash, ChannelMonitor<ChanSigner>) {
        fn read<R: ::std::io::Read>(reader: &mut R, logger: Arc<Logger>) -> Result<Self, DecodeError> {
                macro_rules! unwrap_obj {
                        ($key: expr) => {
@@ -2307,7 +2306,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
                let remote_claimable_outpoints_len: u64 = Readable::read(reader)?;
                let mut remote_claimable_outpoints = HashMap::with_capacity(cmp::min(remote_claimable_outpoints_len as usize, MAX_ALLOC_SIZE / 64));
                for _ in 0..remote_claimable_outpoints_len {
-                       let txid: Sha256dHash = Readable::read(reader)?;
+                       let txid: Txid = Readable::read(reader)?;
                        let htlcs_count: u64 = Readable::read(reader)?;
                        let mut htlcs = Vec::with_capacity(cmp::min(htlcs_count as usize, MAX_ALLOC_SIZE / 32));
                        for _ in 0..htlcs_count {
@@ -2321,7 +2320,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
                let remote_commitment_txn_on_chain_len: u64 = Readable::read(reader)?;
                let mut remote_commitment_txn_on_chain = HashMap::with_capacity(cmp::min(remote_commitment_txn_on_chain_len as usize, MAX_ALLOC_SIZE / 32));
                for _ in 0..remote_commitment_txn_on_chain_len {
-                       let txid: Sha256dHash = Readable::read(reader)?;
+                       let txid: Txid = Readable::read(reader)?;
                        let commitment_number = <U48 as Readable>::read(reader)?.0;
                        let outputs_count = <u64 as Readable>::read(reader)?;
                        let mut outputs = Vec::with_capacity(cmp::min(outputs_count as usize, MAX_ALLOC_SIZE / 8));
@@ -2411,7 +2410,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
                        }
                }
 
-               let last_block_hash: Sha256dHash = Readable::read(reader)?;
+               let last_block_hash: BlockHash = Readable::read(reader)?;
 
                let waiting_threshold_conf_len: u64 = Readable::read(reader)?;
                let mut onchain_events_waiting_threshold_conf = HashMap::with_capacity(cmp::min(waiting_threshold_conf_len as usize, MAX_ALLOC_SIZE / 128));
@@ -2442,7 +2441,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
                }
 
                let outputs_to_watch_len: u64 = Readable::read(reader)?;
-               let mut outputs_to_watch = HashMap::with_capacity(cmp::min(outputs_to_watch_len as usize, MAX_ALLOC_SIZE / (mem::size_of::<Sha256dHash>() + mem::size_of::<Vec<Script>>())));
+               let mut outputs_to_watch = HashMap::with_capacity(cmp::min(outputs_to_watch_len as usize, MAX_ALLOC_SIZE / (mem::size_of::<Txid>() + mem::size_of::<Vec<Script>>())));
                for _ in 0..outputs_to_watch_len {
                        let txid = Readable::read(reader)?;
                        let outputs_len: u64 = Readable::read(reader)?;
@@ -2518,10 +2517,10 @@ mod tests {
        use bitcoin::blockdata::transaction::{Transaction, TxIn, TxOut, SigHashType};
        use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint;
        use bitcoin::util::bip143;
-       use bitcoin_hashes::Hash;
-       use bitcoin_hashes::sha256::Hash as Sha256;
-       use bitcoin_hashes::sha256d::Hash as Sha256dHash;
-       use bitcoin_hashes::hex::FromHex;
+       use bitcoin::hashes::Hash;
+       use bitcoin::hashes::sha256::Hash as Sha256;
+       use bitcoin::hashes::hex::FromHex;
+       use bitcoin::hash_types::Txid;
        use hex;
        use chain::transaction::OutPoint;
        use ln::channelmanager::{PaymentPreimage, PaymentHash};
@@ -2530,8 +2529,8 @@ mod tests {
        use ln::chan_utils;
        use ln::chan_utils::{HTLCOutputInCommitment, LocalCommitmentTransaction};
        use util::test_utils::TestLogger;
-       use secp256k1::key::{SecretKey,PublicKey};
-       use secp256k1::Secp256k1;
+       use bitcoin::secp256k1::key::{SecretKey,PublicKey};
+       use bitcoin::secp256k1::Secp256k1;
        use rand::{thread_rng,Rng};
        use std::sync::Arc;
        use chain::keysinterface::InMemoryChannelKeys;
@@ -2605,7 +2604,7 @@ mod tests {
                // old state.
                let mut monitor = ChannelMonitor::new(keys,
                        &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap()), 0, &Script::new(),
-                       (OutPoint { txid: Sha256dHash::from_slice(&[43; 32]).unwrap(), index: 0 }, Script::new()),
+                       (OutPoint { txid: Txid::from_slice(&[43; 32]).unwrap(), index: 0 }, Script::new()),
                        &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
                        &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap()),
                        10, Script::new(), 46, 0, LocalCommitmentTransaction::dummy(), logger.clone());
@@ -2693,7 +2692,7 @@ mod tests {
                }
 
                let script_pubkey = Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script();
-               let txid = Sha256dHash::from_hex("56944c5d3f98413ef45cf54545538103cc9f298e0575820ad3591376e2e0f65d").unwrap();
+               let txid = Txid::from_hex("56944c5d3f98413ef45cf54545538103cc9f298e0575820ad3591376e2e0f65d").unwrap();
 
                // Justice tx with 1 to_local, 2 revoked offered HTLCs, 1 revoked received HTLCs
                let mut claim_tx = Transaction { version: 0, lock_time: 0, input: Vec::new(), output: Vec::new() };
index 91365d5a29bb6761f5d9a8a30bbda2626954aef2..4a56ea412c6c321099dc58b4e58e03c6686fd0fe 100644 (file)
@@ -24,12 +24,12 @@ use bitcoin::blockdata::block::BlockHeader;
 use bitcoin::blockdata::transaction::{Transaction, TxOut};
 use bitcoin::network::constants::Network;
 
-use bitcoin_hashes::sha256::Hash as Sha256;
-use bitcoin_hashes::sha256d::Hash as Sha256d;
-use bitcoin_hashes::Hash;
+use bitcoin::hashes::sha256::Hash as Sha256;
+use bitcoin::hashes::Hash;
+use bitcoin::hash_types::BlockHash;
 
-use secp256k1::Secp256k1;
-use secp256k1::key::PublicKey;
+use bitcoin::secp256k1::Secp256k1;
+use bitcoin::secp256k1::key::PublicKey;
 
 use rand::{thread_rng,Rng};
 
@@ -50,7 +50,7 @@ pub fn confirm_transaction<'a, 'b: 'a>(notifier: &'a chaininterface::BlockNotifi
        }
 }
 
-pub fn connect_blocks<'a, 'b>(notifier: &'a chaininterface::BlockNotifierRef<'b>, depth: u32, height: u32, parent: bool, prev_blockhash: Sha256d) -> Sha256d {
+pub fn connect_blocks<'a, 'b>(notifier: &'a chaininterface::BlockNotifierRef<'b>, depth: u32, height: u32, parent: bool, prev_blockhash: BlockHash) -> BlockHash {
        let mut header = BlockHeader { version: 0x2000000, prev_blockhash: if parent { prev_blockhash } else { Default::default() }, merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
        notifier.block_connected_checked(&header, height + 1, &Vec::new(), &Vec::new());
        for i in 2..depth + 1 {
@@ -137,7 +137,7 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> {
                                for (_, old_monitor) in old_monitors.iter() {
                                        let mut w = test_utils::TestVecWriter(Vec::new());
                                        old_monitor.write_for_disk(&mut w).unwrap();
-                                       let (_, deserialized_monitor) = <(Sha256d, ChannelMonitor<EnforcingChannelKeys>)>::read(
+                                       let (_, deserialized_monitor) = <(BlockHash, ChannelMonitor<EnforcingChannelKeys>)>::read(
                                                &mut ::std::io::Cursor::new(&w.0), Arc::clone(&self.logger) as Arc<Logger>).unwrap();
                                        deserialized_monitors.push(deserialized_monitor);
                                }
@@ -153,7 +153,7 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> {
 
                                let mut w = test_utils::TestVecWriter(Vec::new());
                                self.node.write(&mut w).unwrap();
-                               <(Sha256d, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut ::std::io::Cursor::new(w.0), ChannelManagerReadArgs {
+                               <(BlockHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut ::std::io::Cursor::new(w.0), ChannelManagerReadArgs {
                                        default_config: UserConfig::default(),
                                        keys_manager: self.keys_manager,
                                        fee_estimator: &test_utils::TestFeeEstimator { sat_per_kw: 253 },
index d7bdcc2d2ac50299bd84dbdf93a3d156aaf7e24e..cfc29394f8b5e56acce9454b2b5d096b5af0e109 100644 (file)
@@ -25,7 +25,8 @@ use util::config::UserConfig;
 use util::logger::Logger;
 
 use bitcoin::util::hash::BitcoinHash;
-use bitcoin_hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hash_types::{Txid, BlockHash};
 use bitcoin::util::bip143;
 use bitcoin::util::address::Address;
 use bitcoin::util::bip32::{ChildNumber, ExtendedPubKey, ExtendedPrivKey};
@@ -36,11 +37,11 @@ use bitcoin::blockdata::opcodes;
 use bitcoin::blockdata::constants::genesis_block;
 use bitcoin::network::constants::Network;
 
-use bitcoin_hashes::sha256::Hash as Sha256;
-use bitcoin_hashes::Hash;
+use bitcoin::hashes::sha256::Hash as Sha256;
+use bitcoin::hashes::Hash;
 
-use secp256k1::{Secp256k1, Message};
-use secp256k1::key::{PublicKey,SecretKey};
+use bitcoin::secp256k1::{Secp256k1, Message};
+use bitcoin::secp256k1::key::{PublicKey,SecretKey};
 
 use std::collections::{BTreeSet, HashMap, HashSet};
 use std::default::Default;
@@ -3078,7 +3079,7 @@ fn test_force_close_fail_back() {
        // Now check that if we add the preimage to ChannelMonitor it broadcasts our HTLC-Success..
        {
                let mut monitors = nodes[2].chan_monitor.simple_monitor.monitors.lock().unwrap();
-               monitors.get_mut(&OutPoint::new(Sha256dHash::from_slice(&payment_event.commitment_msg.channel_id[..]).unwrap(), 0)).unwrap()
+               monitors.get_mut(&OutPoint::new(Txid::from_slice(&payment_event.commitment_msg.channel_id[..]).unwrap(), 0)).unwrap()
                        .provide_payment_preimage(&our_payment_hash, &our_payment_preimage);
        }
        nodes[2].block_notifier.block_connected_checked(&header, 1, &[&tx], &[1]);
@@ -3827,7 +3828,7 @@ fn test_invalid_channel_announcement() {
        assert!(nodes[0].router.handle_channel_announcement(&chan_announcement).is_err());
 
        let mut unsigned_msg = dummy_unsigned_msg!();
-       unsigned_msg.chain_hash = Sha256dHash::hash(&[1,2,3,4,5,6,7,8,9]);
+       unsigned_msg.chain_hash = BlockHash::hash(&[1,2,3,4,5,6,7,8,9]);
        sign_msg!(unsigned_msg);
        assert!(nodes[0].router.handle_channel_announcement(&chan_announcement).is_err());
 }
@@ -3855,7 +3856,7 @@ fn test_no_txn_manager_serialize_deserialize() {
        new_chan_monitor = test_utils::TestChannelMonitor::new(nodes[0].chain_monitor.clone(), nodes[0].tx_broadcaster.clone(), Arc::new(test_utils::TestLogger::new()), &fee_estimator);
        nodes[0].chan_monitor = &new_chan_monitor;
        let mut chan_0_monitor_read = &chan_0_monitor_serialized.0[..];
-       let (_, mut chan_0_monitor) = <(Sha256dHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut chan_0_monitor_read, Arc::new(test_utils::TestLogger::new())).unwrap();
+       let (_, mut chan_0_monitor) = <(BlockHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut chan_0_monitor_read, Arc::new(test_utils::TestLogger::new())).unwrap();
        assert!(chan_0_monitor_read.is_empty());
 
        let mut nodes_0_read = &nodes_0_serialized[..];
@@ -3864,7 +3865,7 @@ fn test_no_txn_manager_serialize_deserialize() {
        let (_, nodes_0_deserialized_tmp) = {
                let mut channel_monitors = HashMap::new();
                channel_monitors.insert(chan_0_monitor.get_funding_txo(), &mut chan_0_monitor);
-               <(Sha256dHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
+               <(BlockHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
                        default_config: config,
                        keys_manager: &keys_manager,
                        fee_estimator: &fee_estimator,
@@ -3929,7 +3930,7 @@ fn test_simple_manager_serialize_deserialize() {
        new_chan_monitor = test_utils::TestChannelMonitor::new(nodes[0].chain_monitor.clone(), nodes[0].tx_broadcaster.clone(), Arc::new(test_utils::TestLogger::new()), &fee_estimator);
        nodes[0].chan_monitor = &new_chan_monitor;
        let mut chan_0_monitor_read = &chan_0_monitor_serialized.0[..];
-       let (_, mut chan_0_monitor) = <(Sha256dHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut chan_0_monitor_read, Arc::new(test_utils::TestLogger::new())).unwrap();
+       let (_, mut chan_0_monitor) = <(BlockHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut chan_0_monitor_read, Arc::new(test_utils::TestLogger::new())).unwrap();
        assert!(chan_0_monitor_read.is_empty());
 
        let mut nodes_0_read = &nodes_0_serialized[..];
@@ -3937,7 +3938,7 @@ fn test_simple_manager_serialize_deserialize() {
        let (_, nodes_0_deserialized_tmp) = {
                let mut channel_monitors = HashMap::new();
                channel_monitors.insert(chan_0_monitor.get_funding_txo(), &mut chan_0_monitor);
-               <(Sha256dHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
+               <(BlockHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
                        default_config: UserConfig::default(),
                        keys_manager: &keys_manager,
                        fee_estimator: &fee_estimator,
@@ -4008,7 +4009,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
        let mut node_0_stale_monitors = Vec::new();
        for serialized in node_0_stale_monitors_serialized.iter() {
                let mut read = &serialized[..];
-               let (_, monitor) = <(Sha256dHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut read, Arc::new(test_utils::TestLogger::new())).unwrap();
+               let (_, monitor) = <(BlockHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut read, Arc::new(test_utils::TestLogger::new())).unwrap();
                assert!(read.is_empty());
                node_0_stale_monitors.push(monitor);
        }
@@ -4016,7 +4017,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
        let mut node_0_monitors = Vec::new();
        for serialized in node_0_monitors_serialized.iter() {
                let mut read = &serialized[..];
-               let (_, monitor) = <(Sha256dHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut read, Arc::new(test_utils::TestLogger::new())).unwrap();
+               let (_, monitor) = <(BlockHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut read, Arc::new(test_utils::TestLogger::new())).unwrap();
                assert!(read.is_empty());
                node_0_monitors.push(monitor);
        }
@@ -4025,7 +4026,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
 
        let mut nodes_0_read = &nodes_0_serialized[..];
        if let Err(msgs::DecodeError::InvalidValue) =
-               <(Sha256dHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
+               <(BlockHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
                default_config: UserConfig::default(),
                keys_manager: &keys_manager,
                fee_estimator: &fee_estimator,
@@ -4039,7 +4040,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
 
        let mut nodes_0_read = &nodes_0_serialized[..];
        let (_, nodes_0_deserialized_tmp) =
-               <(Sha256dHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
+               <(BlockHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
                default_config: UserConfig::default(),
                keys_manager: &keys_manager,
                fee_estimator: &fee_estimator,
@@ -5440,12 +5441,12 @@ fn run_onion_failure_test_with_fail_intercept<F1,F2,F3>(_name: &str, test_case:
 
 impl msgs::ChannelUpdate {
        fn dummy() -> msgs::ChannelUpdate {
-               use secp256k1::ffi::Signature as FFISignature;
-               use secp256k1::Signature;
+               use bitcoin::secp256k1::ffi::Signature as FFISignature;
+               use bitcoin::secp256k1::Signature;
                msgs::ChannelUpdate {
                        signature: Signature::from(FFISignature::new()),
                        contents: msgs::UnsignedChannelUpdate {
-                               chain_hash: Sha256dHash::hash(&vec![0u8][..]),
+                               chain_hash: BlockHash::hash(&vec![0u8][..]),
                                short_channel_id: 0,
                                timestamp: 0,
                                flags: 0,
@@ -5477,7 +5478,7 @@ impl Writeable for BogusOnionHopData {
 fn test_onion_failure() {
        use ln::msgs::ChannelUpdate;
        use ln::channelmanager::CLTV_FAR_FAR_AWAY;
-       use secp256k1;
+       use bitcoin::secp256k1;
 
        const BADONION: u16 = 0x8000;
        const PERM: u16 = 0x4000;
@@ -6832,7 +6833,7 @@ fn test_data_loss_protect() {
 
        // Restore node A from previous state
        let logger: Arc<Logger> = Arc::new(test_utils::TestLogger::with_id(format!("node {}", 0)));
-       let mut chan_monitor = <(Sha256dHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut ::std::io::Cursor::new(previous_chan_monitor_state.0), Arc::clone(&logger)).unwrap().1;
+       let mut chan_monitor = <(BlockHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut ::std::io::Cursor::new(previous_chan_monitor_state.0), Arc::clone(&logger)).unwrap().1;
        let chain_monitor = Arc::new(ChainWatchInterfaceUtil::new(Network::Testnet, Arc::clone(&logger)));
        tx_broadcaster = test_utils::TestBroadcaster{txn_broadcasted: Mutex::new(Vec::new())};
        fee_estimator = test_utils::TestFeeEstimator { sat_per_kw: 253 };
@@ -6841,7 +6842,7 @@ fn test_data_loss_protect() {
        node_state_0 = {
                let mut channel_monitors = HashMap::new();
                channel_monitors.insert(OutPoint { txid: chan.3.txid(), index: 0 }, &mut chan_monitor);
-               <(Sha256dHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut ::std::io::Cursor::new(previous_node_state), ChannelManagerReadArgs {
+               <(BlockHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut ::std::io::Cursor::new(previous_node_state), ChannelManagerReadArgs {
                        keys_manager: &keys_manager,
                        fee_estimator: &fee_estimator,
                        monitor: &monitor,
@@ -7656,7 +7657,7 @@ fn test_update_err_monitor_lockdown() {
                let monitor = monitors.get(&outpoint).unwrap();
                let mut w = test_utils::TestVecWriter(Vec::new());
                monitor.write_for_disk(&mut w).unwrap();
-               let new_monitor = <(Sha256dHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(
+               let new_monitor = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(
                                &mut ::std::io::Cursor::new(&w.0), Arc::new(test_utils::TestLogger::new())).unwrap().1;
                assert!(new_monitor == *monitor);
                let chain_monitor = Arc::new(chaininterface::ChainWatchInterfaceUtil::new(Network::Testnet, logger.clone() as Arc<Logger>));
index de8014a6adaec2559a8d9941e0ecbea064175556..cce8c3d0b121722ff4b3ec24f592cc89067687de 100644 (file)
 //! raw socket events into your non-internet-facing system and then send routing events back to
 //! track the network on the less-secure system.
 
-use secp256k1::key::PublicKey;
-use secp256k1::Signature;
-use secp256k1;
-use bitcoin_hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::secp256k1::key::PublicKey;
+use bitcoin::secp256k1::Signature;
+use bitcoin::secp256k1;
 use bitcoin::blockdata::script::Script;
+use bitcoin::hash_types::{Txid, BlockHash};
 
 use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
 
@@ -84,7 +84,7 @@ pub struct Pong {
 /// An open_channel message to be sent or received from a peer
 #[derive(Clone)]
 pub struct OpenChannel {
-       pub(crate) chain_hash: Sha256dHash,
+       pub(crate) chain_hash: BlockHash,
        pub(crate) temporary_channel_id: [u8; 32],
        pub(crate) funding_satoshis: u64,
        pub(crate) push_msat: u64,
@@ -129,7 +129,7 @@ pub struct AcceptChannel {
 #[derive(Clone)]
 pub struct FundingCreated {
        pub(crate) temporary_channel_id: [u8; 32],
-       pub(crate) funding_txid: Sha256dHash,
+       pub(crate) funding_txid: Txid,
        pub(crate) funding_output_index: u16,
        pub(crate) signature: Signature,
 }
@@ -403,7 +403,7 @@ pub struct NodeAnnouncement {
 #[derive(PartialEq, Clone, Debug)]
 pub struct UnsignedChannelAnnouncement {
        pub(crate) features: ChannelFeatures,
-       pub(crate) chain_hash: Sha256dHash,
+       pub(crate) chain_hash: BlockHash,
        pub(crate) short_channel_id: u64,
        /// One of the two node_ids which are endpoints of this channel
        pub        node_id_1: PublicKey,
@@ -425,7 +425,7 @@ pub struct ChannelAnnouncement {
 
 #[derive(PartialEq, Clone, Debug)]
 pub(crate) struct UnsignedChannelUpdate {
-       pub(crate) chain_hash: Sha256dHash,
+       pub(crate) chain_hash: BlockHash,
        pub(crate) short_channel_id: u64,
        pub(crate) timestamp: u32,
        pub(crate) flags: u16,
@@ -1360,15 +1360,15 @@ mod tests {
        use ln::channelmanager::{PaymentPreimage, PaymentHash, PaymentSecret};
        use util::ser::{Writeable, Readable};
 
-       use bitcoin_hashes::sha256d::Hash as Sha256dHash;
-       use bitcoin_hashes::hex::FromHex;
+       use bitcoin::hashes::hex::FromHex;
        use bitcoin::util::address::Address;
        use bitcoin::network::constants::Network;
        use bitcoin::blockdata::script::Builder;
        use bitcoin::blockdata::opcodes;
+       use bitcoin::hash_types::{Txid, BlockHash};
 
-       use secp256k1::key::{PublicKey,SecretKey};
-       use secp256k1::{Secp256k1, Message};
+       use bitcoin::secp256k1::key::{PublicKey,SecretKey};
+       use bitcoin::secp256k1::{Secp256k1, Message};
 
        use std::io::Cursor;
 
@@ -1461,7 +1461,7 @@ mod tests {
                }
                let unsigned_channel_announcement = msgs::UnsignedChannelAnnouncement {
                        features,
-                       chain_hash: if !non_bitcoin_chain_hash { Sha256dHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap() } else { Sha256dHash::from_hex("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943").unwrap() },
+                       chain_hash: if !non_bitcoin_chain_hash { BlockHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap() } else { BlockHash::from_hex("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943").unwrap() },
                        short_channel_id: 2316138423780173,
                        node_id_1: pubkey_1,
                        node_id_2: pubkey_2,
@@ -1611,7 +1611,7 @@ mod tests {
                let (privkey_1, _) = get_keys_from!("0101010101010101010101010101010101010101010101010101010101010101", secp_ctx);
                let sig_1 = get_sig_on!(privkey_1, secp_ctx, String::from("01010101010101010101010101010101"));
                let unsigned_channel_update = msgs::UnsignedChannelUpdate {
-                       chain_hash: if !non_bitcoin_chain_hash { Sha256dHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap() } else { Sha256dHash::from_hex("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943").unwrap() },
+                       chain_hash: if !non_bitcoin_chain_hash { BlockHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap() } else { BlockHash::from_hex("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943").unwrap() },
                        short_channel_id: 2316138423780173,
                        timestamp: 20190119,
                        flags: if direction { 1 } else { 0 } | if disable { 1 << 1 } else { 0 } | if htlc_maximum_msat { 1 << 8 } else { 0 },
@@ -1673,7 +1673,7 @@ mod tests {
                let (_, pubkey_5) = get_keys_from!("0505050505050505050505050505050505050505050505050505050505050505", secp_ctx);
                let (_, pubkey_6) = get_keys_from!("0606060606060606060606060606060606060606060606060606060606060606", secp_ctx);
                let open_channel = msgs::OpenChannel {
-                       chain_hash: if !non_bitcoin_chain_hash { Sha256dHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap() } else { Sha256dHash::from_hex("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943").unwrap() },
+                       chain_hash: if !non_bitcoin_chain_hash { BlockHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap() } else { BlockHash::from_hex("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943").unwrap() },
                        temporary_channel_id: [2; 32],
                        funding_satoshis: 1311768467284833366,
                        push_msat: 2536655962884945560,
@@ -1767,7 +1767,7 @@ mod tests {
                let sig_1 = get_sig_on!(privkey_1, secp_ctx, String::from("01010101010101010101010101010101"));
                let funding_created = msgs::FundingCreated {
                        temporary_channel_id: [2; 32],
-                       funding_txid: Sha256dHash::from_hex("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap(),
+                       funding_txid: Txid::from_hex("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap(),
                        funding_output_index: 255,
                        signature: sig_1,
                };
index 49572f2cb8baee6f270778be52a4b92964995116..19c901fc9d009eb7dc564d8e9b4b857c7859c398 100644 (file)
@@ -8,10 +8,10 @@ use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint;
 use bitcoin::blockdata::script::Script;
 use bitcoin::util::bip143;
 
-use bitcoin_hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hash_types::Txid;
 
-use secp256k1::{Secp256k1, Signature};
-use secp256k1;
+use bitcoin::secp256k1::{Secp256k1, Signature};
+use bitcoin::secp256k1;
 
 use ln::msgs::DecodeError;
 use ln::channelmonitor::{ANTI_REORG_DELAY, CLTV_SHARED_CLAIM_BUFFER, InputMaterial, ClaimRequest};
@@ -37,7 +37,7 @@ enum OnchainEvent {
        /// Outpoint under claim process by our own tx, once this one get enough confirmations, we remove it from
        /// bump-txn candidate buffer.
        Claim {
-               claim_request: Sha256dHash,
+               claim_request: Txid,
        },
        /// Claim tx aggregate multiple claimable outpoints. One of the outpoint may be claimed by a remote party tx.
        /// In this case, we need to drop the outpoint and regenerate a new claim tx. By safety, we keep tracking
@@ -210,9 +210,9 @@ pub struct OnchainTxHandler<ChanSigner: ChannelKeys> {
        // us and is immutable until all outpoint of the claimable set are post-anti-reorg-delay solved.
        // Entry is cache of elements need to generate a bumped claiming transaction (see ClaimTxBumpMaterial)
        #[cfg(test)] // Used in functional_test to verify sanitization
-       pub pending_claim_requests: HashMap<Sha256dHash, ClaimTxBumpMaterial>,
+       pub pending_claim_requests: HashMap<Txid, ClaimTxBumpMaterial>,
        #[cfg(not(test))]
-       pending_claim_requests: HashMap<Sha256dHash, ClaimTxBumpMaterial>,
+       pending_claim_requests: HashMap<Txid, ClaimTxBumpMaterial>,
 
        // Used to link outpoints claimed in a connected block to a pending claim request.
        // Key is outpoint than monitor parsing has detected we have keys/scripts to claim
@@ -221,9 +221,9 @@ pub struct OnchainTxHandler<ChanSigner: ChannelKeys> {
        // post-anti-reorg-delay solved, confirmaiton_block is used to erase entry if
        // block with output gets disconnected.
        #[cfg(test)] // Used in functional_test to verify sanitization
-       pub claimable_outpoints: HashMap<BitcoinOutPoint, (Sha256dHash, u32)>,
+       pub claimable_outpoints: HashMap<BitcoinOutPoint, (Txid, u32)>,
        #[cfg(not(test))]
-       claimable_outpoints: HashMap<BitcoinOutPoint, (Sha256dHash, u32)>,
+       claimable_outpoints: HashMap<BitcoinOutPoint, (Txid, u32)>,
 
        onchain_events_waiting_threshold_conf: HashMap<u32, Vec<OnchainEvent>>,
 
index dc3b2f9022542556e9cc01bba9aa0d757fc85fe8..4128d09905f0a2ee5379c95f1b5f730b83656fc5 100644 (file)
@@ -7,15 +7,15 @@ use util::errors::{self, APIError};
 use util::ser::{Readable, Writeable, LengthCalculatingWriter};
 use util::logger::{Logger, LogHolder};
 
-use bitcoin_hashes::{Hash, HashEngine};
-use bitcoin_hashes::cmp::fixed_time_eq;
-use bitcoin_hashes::hmac::{Hmac, HmacEngine};
-use bitcoin_hashes::sha256::Hash as Sha256;
+use bitcoin::hashes::{Hash, HashEngine};
+use bitcoin::hashes::cmp::fixed_time_eq;
+use bitcoin::hashes::hmac::{Hmac, HmacEngine};
+use bitcoin::hashes::sha256::Hash as Sha256;
 
-use secp256k1::key::{SecretKey,PublicKey};
-use secp256k1::Secp256k1;
-use secp256k1::ecdh::SharedSecret;
-use secp256k1;
+use bitcoin::secp256k1::key::{SecretKey,PublicKey};
+use bitcoin::secp256k1::Secp256k1;
+use bitcoin::secp256k1::ecdh::SharedSecret;
+use bitcoin::secp256k1;
 
 use std::io::Cursor;
 use std::sync::Arc;
@@ -478,8 +478,8 @@ mod tests {
 
        use hex;
 
-       use secp256k1::Secp256k1;
-       use secp256k1::key::{PublicKey,SecretKey};
+       use bitcoin::secp256k1::Secp256k1;
+       use bitcoin::secp256k1::key::{PublicKey,SecretKey};
 
        use super::OnionKeys;
 
index 7e84e329eb1482bbeb9e08f1165ad1ddf93432fd..152426577adf33a7980c00890c3eae830a738b4f 100644 (file)
@@ -1,13 +1,13 @@
 use ln::msgs::LightningError;
 use ln::msgs;
 
-use bitcoin_hashes::{Hash, HashEngine, Hmac, HmacEngine};
-use bitcoin_hashes::sha256::Hash as Sha256;
+use bitcoin::hashes::{Hash, HashEngine, Hmac, HmacEngine};
+use bitcoin::hashes::sha256::Hash as Sha256;
 
-use secp256k1::Secp256k1;
-use secp256k1::key::{PublicKey,SecretKey};
-use secp256k1::ecdh::SharedSecret;
-use secp256k1;
+use bitcoin::secp256k1::Secp256k1;
+use bitcoin::secp256k1::key::{PublicKey,SecretKey};
+use bitcoin::secp256k1::ecdh::SharedSecret;
+use bitcoin::secp256k1;
 
 use util::chacha20poly1305rfc::ChaCha20Poly1305RFC;
 use util::byte_utils;
@@ -467,7 +467,7 @@ impl PeerChannelEncryptor {
 
 #[cfg(test)]
 mod tests {
-       use secp256k1::key::{PublicKey,SecretKey};
+       use bitcoin::secp256k1::key::{PublicKey,SecretKey};
 
        use hex;
 
index 2dadf2ec6149e565d65e155c6c844694fede4096..51a546de60b24c6926c36be422679a6826c32122 100644 (file)
@@ -6,7 +6,7 @@
 //! call into the provided message handlers (probably a ChannelManager and Router) with messages
 //! they should handle, and encoding/sending response messages.
 
-use secp256k1::key::{SecretKey,PublicKey};
+use bitcoin::secp256k1::key::{SecretKey,PublicKey};
 
 use ln::features::InitFeatures;
 use ln::msgs;
@@ -26,9 +26,9 @@ use std::sync::atomic::{AtomicUsize, Ordering};
 use std::{cmp,error,hash,fmt};
 use std::ops::Deref;
 
-use bitcoin_hashes::sha256::Hash as Sha256;
-use bitcoin_hashes::sha256::HashEngine as Sha256Engine;
-use bitcoin_hashes::{HashEngine, Hash};
+use bitcoin::hashes::sha256::Hash as Sha256;
+use bitcoin::hashes::sha256::HashEngine as Sha256Engine;
+use bitcoin::hashes::{HashEngine, Hash};
 
 /// Provides references to trait impls which handle different types of messages.
 pub struct MessageHandler<CM: Deref> where CM::Target: msgs::ChannelMessageHandler {
@@ -1153,7 +1153,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
 
 #[cfg(test)]
 mod tests {
-       use secp256k1::Signature;
+       use bitcoin::secp256k1::Signature;
        use bitcoin::BitcoinHash;
        use bitcoin::network::constants::Network;
        use bitcoin::blockdata::constants::genesis_block;
@@ -1164,8 +1164,8 @@ mod tests {
        use util::test_utils;
        use util::logger::Logger;
 
-       use secp256k1::Secp256k1;
-       use secp256k1::key::{SecretKey, PublicKey};
+       use bitcoin::secp256k1::Secp256k1;
+       use bitcoin::secp256k1::key::{SecretKey, PublicKey};
 
        use rand::{thread_rng, Rng};
 
@@ -1350,7 +1350,7 @@ mod tests {
        }
 
        fn get_dummy_channel_announcement(short_chan_id: u64) -> msgs::ChannelAnnouncement {
-               use secp256k1::ffi::Signature as FFISignature;
+               use bitcoin::secp256k1::ffi::Signature as FFISignature;
                let secp_ctx = Secp256k1::new();
                let network = Network::Testnet;
                let node_1_privkey = SecretKey::from_slice(&[42; 32]).unwrap();
@@ -1378,7 +1378,7 @@ mod tests {
        }
 
        fn get_dummy_channel_update(short_chan_id: u64) -> msgs::ChannelUpdate {
-               use secp256k1::ffi::Signature as FFISignature;
+               use bitcoin::secp256k1::ffi::Signature as FFISignature;
                let network = Network::Testnet;
                msgs::ChannelUpdate {
                        signature: Signature::from(FFISignature::new()),
index 1eec7533b653b8ff7ef5cf3f986f64cb2e4044fd..037303d917cfa8a911ddc0cacbe8cb7ae583b819 100644 (file)
@@ -3,12 +3,13 @@
 //! You probably want to create a Router and use that as your RoutingMessageHandler and then
 //! interrogate it to get routes for your own payments.
 
-use secp256k1::key::PublicKey;
-use secp256k1::Secp256k1;
-use secp256k1;
+use bitcoin::secp256k1::key::PublicKey;
+use bitcoin::secp256k1::Secp256k1;
+use bitcoin::secp256k1;
 
-use bitcoin_hashes::sha256d::Hash as Sha256dHash;
-use bitcoin_hashes::Hash;
+use bitcoin::hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hashes::Hash;
+use bitcoin::hash_types::BlockHash;
 use bitcoin::blockdata::script::Builder;
 use bitcoin::blockdata::opcodes;
 
@@ -329,19 +330,19 @@ impl std::fmt::Display for NetworkMap {
 impl NetworkMap {
        #[cfg(feature = "non_bitcoin_chain_hash_routing")]
        #[inline]
-       fn get_key(short_channel_id: u64, chain_hash: Sha256dHash) -> (u64, Sha256dHash) {
+       fn get_key(short_channel_id: u64, chain_hash: BlockHash) -> (u64, BlockHash) {
                (short_channel_id, chain_hash)
        }
 
        #[cfg(not(feature = "non_bitcoin_chain_hash_routing"))]
        #[inline]
-       fn get_key(short_channel_id: u64, _: Sha256dHash) -> u64 {
+       fn get_key(short_channel_id: u64, _: BlockHash) -> u64 {
                short_channel_id
        }
 
        #[cfg(feature = "non_bitcoin_chain_hash_routing")]
        #[inline]
-       fn get_short_id(id: &(u64, Sha256dHash)) -> &u64 {
+       fn get_short_id(id: &(u64, BlockHash)) -> &u64 {
                &id.0
        }
 
@@ -1085,8 +1086,9 @@ mod tests {
        use util::logger::Logger;
        use util::ser::{Writeable, Readable};
 
-       use bitcoin_hashes::sha256d::Hash as Sha256dHash;
-       use bitcoin_hashes::Hash;
+       use bitcoin::hashes::sha256d::Hash as Sha256dHash;
+       use bitcoin::hashes::Hash;
+       use bitcoin::hash_types::BlockHash;
        use bitcoin::network::constants::Network;
        use bitcoin::blockdata::constants::genesis_block;
        use bitcoin::blockdata::script::Builder;
@@ -1095,9 +1097,9 @@ mod tests {
 
        use hex;
 
-       use secp256k1::key::{PublicKey,SecretKey};
-       use secp256k1::All;
-       use secp256k1::Secp256k1;
+       use bitcoin::secp256k1::key::{PublicKey,SecretKey};
+       use bitcoin::secp256k1::All;
+       use bitcoin::secp256k1::Secp256k1;
 
        use std::sync::Arc;
        use std::collections::btree_map::Entry as BtreeEntry;
@@ -1181,7 +1183,7 @@ mod tests {
                let node7 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0808080808080808080808080808080808080808080808080808080808080808").unwrap()[..]).unwrap());
                let node8 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0909090909090909090909090909090909090909090909090909090909090909").unwrap()[..]).unwrap());
 
-               let zero_hash = Sha256dHash::hash(&[0; 32]);
+               let zero_hash = BlockHash::hash(&[0; 32]);
 
                macro_rules! id_to_feature_flags {
                        // Set the feature flags to the id'th odd (ie non-required) feature bit so that we can
index 1d3af1ea32072b4622756dcb8ef292921293904b..622af70acde6d0ebca871df2c812c78c53f3595b 100644 (file)
@@ -14,7 +14,7 @@
 mod real_chachapoly {
        use util::chacha20::ChaCha20;
        use util::poly1305::Poly1305;
-       use bitcoin_hashes::cmp::fixed_time_eq;
+       use bitcoin::hashes::cmp::fixed_time_eq;
 
        use util::byte_utils;
 
index 3e1ffd04446021a4e00d5e0a5fe55318128a6d2e..a4bfdf8800a398594b64f2f771fa68e28abad1c1 100644 (file)
@@ -8,9 +8,9 @@ use std::sync::{Mutex, Arc};
 use bitcoin::blockdata::transaction::Transaction;
 use bitcoin::util::bip143;
 
-use secp256k1;
-use secp256k1::key::{SecretKey, PublicKey};
-use secp256k1::{Secp256k1, Signature};
+use bitcoin::secp256k1;
+use bitcoin::secp256k1::key::{SecretKey, PublicKey};
+use bitcoin::secp256k1::{Secp256k1, Signature};
 use util::ser::{Writeable, Writer, Readable};
 use std::io::Error;
 use ln::msgs::DecodeError;
index 43a2dc3bd6f881ab4ec69241f30f5a2b37651a8e..76ec20209412a8ddc4865aa931c3265a5275f60e 100644 (file)
@@ -13,7 +13,7 @@ use util::ser::{Writeable, Writer, MaybeReadable, Readable};
 
 use bitcoin::blockdata::script::Script;
 
-use secp256k1::key::PublicKey;
+use bitcoin::secp256k1::key::PublicKey;
 
 use std::time::Duration;
 
index 508acf08d1ddc629252a63064a374a93bc4afdd3..42b4732f370275f08c6bda6dc0581f6b67cf555d 100644 (file)
@@ -3,13 +3,13 @@ macro_rules! hash_to_message {
                {
                        #[cfg(not(feature = "fuzztarget"))]
                        {
-                               ::secp256k1::Message::from_slice($slice).unwrap()
+                               ::bitcoin::secp256k1::Message::from_slice($slice).unwrap()
                        }
                        #[cfg(feature = "fuzztarget")]
                        {
-                               match ::secp256k1::Message::from_slice($slice) {
+                               match ::bitcoin::secp256k1::Message::from_slice($slice) {
                                        Ok(msg) => msg,
-                                       Err(_) => ::secp256k1::Message::from_slice(&[1; 32]).unwrap()
+                                       Err(_) => ::bitcoin::secp256k1::Message::from_slice(&[1; 32]).unwrap()
                                }
                        }
                }
index bee0f0d26f9a68e3ea4b00635ddd3994781c28c0..b94540446339d421fec525597d653878a647f621 100644 (file)
@@ -1,9 +1,9 @@
 use chain::transaction::OutPoint;
 use chain::keysinterface::SpendableOutputDescriptor;
 
-use bitcoin_hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hash_types::Txid;
 use bitcoin::blockdata::transaction::Transaction;
-use secp256k1::key::PublicKey;
+use bitcoin::secp256k1::key::PublicKey;
 
 use ln::router::Route;
 use ln::chan_utils::HTLCType;
@@ -40,7 +40,7 @@ macro_rules! log_bytes {
        }
 }
 
-pub(crate) struct DebugFundingChannelId<'a>(pub &'a Sha256dHash, pub u16);
+pub(crate) struct DebugFundingChannelId<'a>(pub &'a Txid, pub u16);
 impl<'a> std::fmt::Display for DebugFundingChannelId<'a> {
        fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
                for i in OutPoint::new(self.0.clone(), self.1).to_channel_id().iter() {
index 5a68f7a5eb4164a43753630d4e7015b712ac2f37..a087467f7a438304ee3db7f52c956ce1a9ef90c3 100644 (file)
@@ -8,13 +8,14 @@ use std::hash::Hash;
 use std::sync::Mutex;
 use std::cmp;
 
-use secp256k1::Signature;
-use secp256k1::key::{PublicKey, SecretKey};
+use bitcoin::secp256k1::Signature;
+use bitcoin::secp256k1::key::{PublicKey, SecretKey};
 use bitcoin::blockdata::script::Script;
 use bitcoin::blockdata::transaction::{OutPoint, Transaction, TxOut};
 use bitcoin::consensus;
 use bitcoin::consensus::Encodable;
-use bitcoin_hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hash_types::{Txid, BlockHash};
 use std::marker::Sized;
 use ln::msgs::DecodeError;
 use ln::channelmanager::{PaymentPreimage, PaymentHash, PaymentSecret};
@@ -542,7 +543,7 @@ impl Writeable for Sha256dHash {
 
 impl Readable for Sha256dHash {
        fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
-               use bitcoin_hashes::Hash;
+               use bitcoin::hashes::Hash;
 
                let buf: [u8; 32] = Readable::read(r)?;
                Ok(Sha256dHash::from_slice(&buf[..]).unwrap())
@@ -632,6 +633,36 @@ impl<T: Readable> Readable for Option<T>
        }
 }
 
+impl Writeable for Txid {
+       fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
+               w.write_all(&self[..])
+       }
+}
+
+impl Readable for Txid {
+       fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
+               use bitcoin::hashes::Hash;
+
+               let buf: [u8; 32] = Readable::read(r)?;
+               Ok(Txid::from_slice(&buf[..]).unwrap())
+       }
+}
+
+impl Writeable for BlockHash {
+       fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
+               w.write_all(&self[..])
+       }
+}
+
+impl Readable for BlockHash {
+       fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
+               use bitcoin::hashes::Hash;
+
+               let buf: [u8; 32] = Readable::read(r)?;
+               Ok(BlockHash::from_slice(&buf[..]).unwrap())
+       }
+}
+
 impl Writeable for OutPoint {
        fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
                self.txid.write(w)?;
index 28bd0e6882bb38cd8ab552117856685ac1690fa1..6758e36dff551adffc9c58e88cd1977766984001 100644 (file)
@@ -152,7 +152,7 @@ mod tests {
        use std::io::{Cursor, Read};
        use ln::msgs::DecodeError;
        use util::ser::{Readable, Writeable, HighZeroBytesDroppedVarInt, VecWriter};
-       use secp256k1::PublicKey;
+       use bitcoin::secp256k1::PublicKey;
 
        // The BOLT TLV test cases don't include any tests which use our "required-value" logic since
        // the encoding layer in the BOLTs has no such concept, though it makes our macros easier to
index 8385c39c1db081940bdbc373bf23d461cccc9e19..6a652aa6b39c0016c0ac3705cfcf9206733e04a8 100644 (file)
@@ -16,10 +16,10 @@ use bitcoin::blockdata::transaction::Transaction;
 use bitcoin::blockdata::script::{Builder, Script};
 use bitcoin::blockdata::block::Block;
 use bitcoin::blockdata::opcodes;
-use bitcoin_hashes::sha256d::Hash as Sha256dHash;
 use bitcoin::network::constants::Network;
+use bitcoin::hash_types::{Txid, BlockHash};
 
-use secp256k1::{SecretKey, PublicKey};
+use bitcoin::secp256k1::{SecretKey, PublicKey};
 
 use std::time::{SystemTime, UNIX_EPOCH};
 use std::sync::{Arc,Mutex};
@@ -72,7 +72,7 @@ impl<'a> channelmonitor::ManyChannelMonitor<EnforcingChannelKeys> for TestChanne
                // to a watchtower and disk...
                let mut w = TestVecWriter(Vec::new());
                monitor.write_for_disk(&mut w).unwrap();
-               let new_monitor = <(Sha256dHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(
+               let new_monitor = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(
                                &mut ::std::io::Cursor::new(&w.0), Arc::new(TestLogger::new())).unwrap().1;
                assert!(new_monitor == monitor);
                self.latest_monitor_update_id.lock().unwrap().insert(funding_txo.to_channel_id(), (funding_txo, monitor.get_latest_update_id()));
@@ -101,7 +101,7 @@ impl<'a> channelmonitor::ManyChannelMonitor<EnforcingChannelKeys> for TestChanne
                let monitor = monitors.get(&funding_txo).unwrap();
                w.0.clear();
                monitor.write_for_disk(&mut w).unwrap();
-               let new_monitor = <(Sha256dHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(
+               let new_monitor = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(
                                &mut ::std::io::Cursor::new(&w.0), Arc::new(TestLogger::new())).unwrap().1;
                assert!(new_monitor == *monitor);
                self.added_monitors.lock().unwrap().push((funding_txo, new_monitor));
@@ -297,15 +297,15 @@ impl TestChainWatcher {
 }
 
 impl ChainWatchInterface for TestChainWatcher {
-       fn install_watch_tx(&self, _txid: &Sha256dHash, _script_pub_key: &Script) { }
-       fn install_watch_outpoint(&self, _outpoint: (Sha256dHash, u32), _out_script: &Script) { }
+       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 reentered(&self) -> usize { 0 }
 
-       fn get_chain_utxo(&self, _genesis_hash: Sha256dHash, _unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError> {
+       fn get_chain_utxo(&self, _genesis_hash: BlockHash, _unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError> {
                self.utxo_ret.lock().unwrap().clone()
        }
 }