]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Bump rust-bitcoin to v0.30.2
authorWilmer Paulino <wilmer@wilmerpaulino.com>
Thu, 27 Apr 2023 07:16:40 +0000 (00:16 -0700)
committerWilmer Paulino <wilmer@wilmerpaulino.com>
Wed, 22 Nov 2023 23:58:01 +0000 (15:58 -0800)
74 files changed:
fuzz/Cargo.toml
fuzz/src/chanmon_consistency.rs
fuzz/src/full_stack.rs
fuzz/src/onion_message.rs
lightning-background-processor/Cargo.toml
lightning-background-processor/src/lib.rs
lightning-block-sync/Cargo.toml
lightning-block-sync/src/convert.rs
lightning-block-sync/src/init.rs
lightning-block-sync/src/lib.rs
lightning-block-sync/src/poll.rs
lightning-block-sync/src/rest.rs
lightning-block-sync/src/rpc.rs
lightning-block-sync/src/test_utils.rs
lightning-block-sync/src/utils.rs
lightning-custom-message/Cargo.toml
lightning-invoice/Cargo.toml
lightning-invoice/src/de.rs
lightning-invoice/src/lib.rs
lightning-invoice/src/payment.rs
lightning-invoice/src/utils.rs
lightning-invoice/tests/ser_de.rs
lightning-net-tokio/Cargo.toml
lightning-persister/Cargo.toml
lightning-persister/src/fs_store.rs
lightning-rapid-gossip-sync/Cargo.toml
lightning-transaction-sync/Cargo.toml
lightning-transaction-sync/src/common.rs
lightning-transaction-sync/tests/integration_tests.rs
lightning/Cargo.toml
lightning/src/blinded_path/utils.rs
lightning/src/chain/chainmonitor.rs
lightning/src/chain/channelmonitor.rs
lightning/src/chain/mod.rs
lightning/src/chain/onchaintx.rs
lightning/src/chain/package.rs
lightning/src/chain/transaction.rs
lightning/src/events/bump_transaction.rs
lightning/src/events/mod.rs
lightning/src/lib.rs
lightning/src/ln/chan_utils.rs
lightning/src/ln/channel.rs
lightning/src/ln/channel_id.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/functional_tests.rs
lightning/src/ln/inbound_payment.rs
lightning/src/ln/monitor_tests.rs
lightning/src/ln/msgs.rs
lightning/src/ln/onion_route_tests.rs
lightning/src/ln/onion_utils.rs
lightning/src/ln/outbound_payment.rs
lightning/src/ln/peer_channel_encryptor.rs
lightning/src/ln/peer_handler.rs
lightning/src/ln/script.rs
lightning/src/ln/shutdown_tests.rs
lightning/src/offers/invoice.rs
lightning/src/offers/merkle.rs
lightning/src/offers/signer.rs
lightning/src/onion_message/functional_tests.rs
lightning/src/onion_message/messenger.rs
lightning/src/routing/gossip.rs
lightning/src/routing/router.rs
lightning/src/routing/test_utils.rs
lightning/src/routing/utxo.rs
lightning/src/sign/mod.rs
lightning/src/util/crypto.rs
lightning/src/util/message_signing.rs
lightning/src/util/persist.rs
lightning/src/util/ser.rs
lightning/src/util/ser_macros.rs
lightning/src/util/test_channel_signer.rs
lightning/src/util/test_utils.rs
lightning/src/util/transaction_utils.rs

index 5daebb3506681503e197ba92656eb1ddd4eb4c06..573096efdfcfb3983fa94448c57453e9b21cdde4 100644 (file)
@@ -20,8 +20,8 @@ stdin_fuzz = []
 [dependencies]
 lightning = { path = "../lightning", features = ["regex", "hashbrown", "_test_utils"] }
 lightning-rapid-gossip-sync = { path = "../lightning-rapid-gossip-sync" }
-bitcoin = { version = "0.29.0", features = ["secp-lowmemory"] }
-hex = "0.3"
+bitcoin = { version = "0.30.2", features = ["secp-lowmemory"] }
+hex = { package = "hex-conservative", version = "0.1.1", default-features = false }
 hashbrown = "0.8"
 
 afl = { version = "0.12", optional = true }
index 9aebb38966c25d16296d7b39d501161ea58cc30f..af0c64d88aea7f76f751ebc24a15bade136919ed 100644 (file)
@@ -20,9 +20,9 @@
 
 use bitcoin::blockdata::constants::genesis_block;
 use bitcoin::blockdata::transaction::{Transaction, TxOut};
-use bitcoin::blockdata::script::{Builder, Script};
+use bitcoin::blockdata::script::{Builder, ScriptBuf};
 use bitcoin::blockdata::opcodes;
-use bitcoin::blockdata::locktime::PackedLockTime;
+use bitcoin::blockdata::locktime::absolute::LockTime;
 use bitcoin::network::constants::Network;
 
 use bitcoin::hashes::Hash as TraitImport;
@@ -270,11 +270,11 @@ impl SignerProvider for KeyProvider {
                })
        }
 
-       fn get_destination_script(&self) -> Result<Script, ()> {
+       fn get_destination_script(&self) -> Result<ScriptBuf, ()> {
                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_secret[31]]).unwrap();
                let our_channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
-               Ok(Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script())
+               Ok(Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(our_channel_monitor_claim_key_hash).into_script())
        }
 
        fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
@@ -343,7 +343,7 @@ type ChanMan<'a> = ChannelManager<Arc<TestChainMonitor>, Arc<TestBroadcaster>, A
 fn get_payment_secret_hash(dest: &ChanMan, payment_id: &mut u8) -> Option<(PaymentSecret, PaymentHash)> {
        let mut payment_hash;
        for _ in 0..256 {
-               payment_hash = PaymentHash(Sha256::hash(&[*payment_id; 1]).into_inner());
+               payment_hash = PaymentHash(Sha256::hash(&[*payment_id; 1]).to_byte_array());
                if let Ok(payment_secret) = dest.create_inbound_payment_for_hash(payment_hash, None, 3600, None) {
                        return Some((payment_secret, payment_hash));
                }
@@ -565,7 +565,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
                                let events = $source.get_and_clear_pending_events();
                                assert_eq!(events.len(), 1);
                                if let events::Event::FundingGenerationReady { ref temporary_channel_id, ref channel_value_satoshis, ref output_script, .. } = events[0] {
-                                       let tx = Transaction { version: $chan_id, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: vec![TxOut {
+                                       let tx = Transaction { version: $chan_id, lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut {
                                                value: *channel_value_satoshis, script_pubkey: output_script.clone(),
                                        }]};
                                        funding_output = OutPoint { txid: tx.txid(), index: 0 };
index a41d3f46b04ac3067008451e3fdfb33d563256a9..8a597a614772a46d711c34a4ba0758eea4cd2d64 100644 (file)
 
 use bitcoin::blockdata::constants::genesis_block;
 use bitcoin::blockdata::transaction::{Transaction, TxOut};
-use bitcoin::blockdata::script::{Builder, Script};
+use bitcoin::blockdata::script::{Builder, ScriptBuf};
 use bitcoin::blockdata::opcodes;
-use bitcoin::blockdata::locktime::PackedLockTime;
+use bitcoin::blockdata::locktime::absolute::LockTime;
 use bitcoin::consensus::encode::deserialize;
 use bitcoin::network::constants::Network;
 
+use bitcoin::hashes::hex::FromHex;
 use bitcoin::hashes::Hash as TraitImport;
 use bitcoin::hashes::HashEngine as TraitImportEngine;
 use bitcoin::hashes::sha256::Hash as Sha256;
@@ -391,11 +392,11 @@ impl SignerProvider for KeyProvider {
                ))
        }
 
-       fn get_destination_script(&self) -> Result<Script, ()> {
+       fn get_destination_script(&self) -> Result<ScriptBuf, ()> {
                let secp_ctx = Secp256k1::signing_only();
-               let channel_monitor_claim_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
+               let channel_monitor_claim_key = SecretKey::from_slice(&<Vec<u8>>::from_hex("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
                let our_channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
-               Ok(Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script())
+               Ok(Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(our_channel_monitor_claim_key_hash).into_script())
        }
 
        fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
@@ -481,7 +482,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
        let mut should_forward = false;
        let mut payments_received: Vec<PaymentHash> = Vec::new();
        let mut payments_sent = 0;
-       let mut pending_funding_generation: Vec<(ChannelId, PublicKey, u64, Script)> = Vec::new();
+       let mut pending_funding_generation: Vec<(ChannelId, PublicKey, u64, ScriptBuf)> = Vec::new();
        let mut pending_funding_signatures = HashMap::new();
 
        loop {
@@ -531,9 +532,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
                                        payment_params, final_value_msat);
                                let mut payment_hash = PaymentHash([0; 32]);
                                payment_hash.0[0..8].copy_from_slice(&be64_to_array(payments_sent));
-                               let mut sha = Sha256::engine();
-                               sha.input(&payment_hash.0[..]);
-                               payment_hash.0 = Sha256::from_engine(sha).into_inner();
+                               payment_hash.0 = Sha256::hash(&payment_hash.0[..]).to_byte_array();
                                payments_sent += 1;
                                match channelmanager.send_payment(payment_hash,
                                        RecipientOnionFields::spontaneous_empty(), PaymentId(payment_hash.0), params,
@@ -550,9 +549,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
                                        payment_params, final_value_msat);
                                let mut payment_hash = PaymentHash([0; 32]);
                                payment_hash.0[0..8].copy_from_slice(&be64_to_array(payments_sent));
-                               let mut sha = Sha256::engine();
-                               sha.input(&payment_hash.0[..]);
-                               payment_hash.0 = Sha256::from_engine(sha).into_inner();
+                               payment_hash.0 = Sha256::hash(&payment_hash.0[..]).to_byte_array();
                                payments_sent += 1;
                                let mut payment_secret = PaymentSecret([0; 32]);
                                payment_secret.0[0..8].copy_from_slice(&be64_to_array(payments_sent));
@@ -603,9 +600,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
                        },
                        16 => {
                                let payment_preimage = PaymentPreimage(keys_manager.get_secure_random_bytes());
-                               let mut sha = Sha256::engine();
-                               sha.input(&payment_preimage.0[..]);
-                               let payment_hash = PaymentHash(Sha256::from_engine(sha).into_inner());
+                               let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).to_byte_array());
                                // Note that this may fail - our hashes may collide and we'll end up trying to
                                // double-register the same payment_hash.
                                let _ = channelmanager.create_inbound_payment_for_hash(payment_hash, None, 1, None);
@@ -617,7 +612,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
                        },
                        10 => {
                                'outer_loop: for funding_generation in pending_funding_generation.drain(..) {
-                                       let mut tx = Transaction { version: 0, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: vec![TxOut {
+                                       let mut tx = Transaction { version: 0, lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut {
                                                        value: funding_generation.2, script_pubkey: funding_generation.3,
                                                }] };
                                        let funding_output = 'search_loop: loop {
@@ -721,6 +716,7 @@ pub extern "C" fn full_stack_run(data: *const u8, datalen: usize) {
 
 #[cfg(test)]
 mod tests {
+       use bitcoin::hashes::hex::FromHex;
        use lightning::util::logger::{Logger, Record};
        use std::collections::HashMap;
        use std::sync::{Arc, Mutex};
@@ -1033,7 +1029,7 @@ mod tests {
                // - client now fails the HTLC backwards as it was unable to extract the payment preimage (CHECK 9 duplicate and CHECK 10)
 
                let logger = Arc::new(TrackingLogger { lines: Mutex::new(HashMap::new()) });
-               super::do_test(&::hex::decode("01000000000000000000000000000000000000000000000000000000000000000000000001000300000000000000000000000000000000000000000000000000000000000000020300320003000000000000000000000000000000000000000000000000000000000000000203000000000000000000000000000000030012001003000000000000000000000000000000030020001000021aaa0008aaaaaaaaaaaa9aaa030000000000000000000000000000000300120147030000000000000000000000000000000300fe00206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000ff4f00f805273c1b203bb5ebf8436bfde57b3be8c2f5e95d9491dbb181909679000000000000c35000000000000000000000000000000162ffffffffffffffff00000000000002220000000000000000000000fd000601e3030000000000000000000000000000000000000000000000000000000000000001030000000000000000000000000000000000000000000000000000000000000002030000000000000000000000000000000000000000000000000000000000000003030000000000000000000000000000000000000000000000000000000000000004030059030000000000000000000000000000000000000000000000000000000000000005020900000000000000000000000000000000000000000000000000000000000000010000010210000300000000000000000000000000000000fd0300120084030000000000000000000000000000000300940022ff4f00f805273c1b203bb5ebf8436bfde57b3be8c2f5e95d9491dbb1819096793d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000210100000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000c005e020000000100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0150c3000000000000220020ae00000000000000000000000000000000000000000000000000000000000000000000000c00000c00000c00000c00000c00000c00000c00000c00000c00000c00000c00000c000003001200430300000000000000000000000000000003005300243d0000000000000000000000000000000000000000000000000000000000000002080000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000010301320003000000000000000000000000000000000000000000000000000000000000000703000000000000000000000000000000030142000302000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003000000000000000000000000000000030112001001000000000000000000000000000000030120001000021aaa0008aaaaaaaaaaaa9aaa01000000000000000000000000000000050103020000000000000000000000000000000000000000000000000000000000000000c3500003e800fd0301120112010000000000000000000000000000000301ff00210000000000000000000000000000000000000000000000000000000000000e05000000000000016200000000004c4b4000000000000003e800000000000003e80000000203f000050300000000000000000000000000000000000000000000000000000000000001000300000000000000000000000000000000000000000000000000000000000002000300000000000000000000000000000000000000000000000000000000000003000300000000000000000000000000000000000000000000000000000000000004000300000000000000000000000000000000000000000000000000000000000005000266000000000000000000000000000003012300000000000000000000000000000000000000010000000000000000000000000000000a00fd00fd03011200620100000000000000000000000000000003017200233a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007c0001000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000b03011200430100000000000000000000000000000003015300243a000000000000000000000000000000000000000000000000000000000000000267000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003001205ac030000000000000000000000000000000300ff00803d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003e80ff00000000000000000000000000000000000000000000000000000000000000000003f00003000000000000000000000000000000000000000000000000000000000000055511020203e80401a0060800000e00000100000a00000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300c1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffab000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000fd03001200640300000000000000000000000000000003007400843d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030010000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003001200630300000000000000000000000000000003007300853d000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000020b00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000700fd00fd03011200640100000000000000000000000000000003017400843a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006a000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003011200630100000000000000000000000000000003017300853a00000000000000000000000000000000000000000000000000000000000000660000000000000000000000000000000000000000000000000000000000000002640000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000030112004a0100000000000000000000000000000003015a00823a000000000000000000000000000000000000000000000000000000000000000000000000000000ff008888888888888888888888888888888888888888888888888888888888880100000000000000000000000000000003011200640100000000000000000000000000000003017400843a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003011200630100000000000000000000000000000003017300853a0000000000000000000000000000000000000000000000000000000000000067000000000000000000000000000000000000000000000000000000000000000265000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003001205ac030000000000000000000000000000000300ff00803d0000000000000000000000000000000000000000000000000000000000000000000000000000010000000000003e80ff00000000000000000000000000000000000000000000000000000000000000000003f00003000000000000000000000000000000000000000000000000000000000000055511020203e80401a0060800000e00000100000a00000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300c1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffab000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000fd03001200630300000000000000000000000000000003007300853d000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000020a000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003001200640300000000000000000000000000000003007400843d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c3010000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003001200630300000000000000000000000000000003007300853d000000000000000000000000000000000000000000000000000000000000000b00000000000000000000000000000000000000000000000000000000000000020d00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000700fd00fd03011200640100000000000000000000000000000003017400843a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000039000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003011200630100000000000000000000000000000003017300853a00000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000002700000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000030112002c0100000000000000000000000000000003013c00833a00000000000000000000000000000000000000000000000000000000000000000000000000000100000100000000000000000000000000000003011200640100000000000000000000000000000003017400843a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000039000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003011200630100000000000000000000000000000003017300853a000000000000000000000000000000000000000000000000000000000000006500000000000000000000000000000000000000000000000000000000000000027100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000703001200630300000000000000000000000000000003007300853d000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000020c000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003001200640300000000000000000000000000000003007400843d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000032010000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003001205ac030000000000000000000000000000000300ff00803d00000000000000000000000000000000000000000000000000000000000000000000000000000200000000000b0838ff00000000000000000000000000000000000000000000000000000000000000000003f0000300000000000000000000000000000000000000000000000000000000000005551202030927c00401a0060800000e00000100000a00000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300c1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff53000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000fd03001200a4030000000000000000000000000000000300b400843d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007501000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006705000000000000000000000000000000000000000000000000000000000000060300000000000000000000000000000003001200630300000000000000000000000000000003007300853d000000000000000000000000000000000000000000000000000000000000000d00000000000000000000000000000000000000000000000000000000000000020f00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000700fd00fd0c007d02000000013a000000000000000000000000000000000000000000000000000000000000000000000000000000800258020000000000002200204b0000000000000000000000000000000000000000000000000000000000000014c00000000000001600142800000000000000000000000000000000000000050000200c005e0200000001730000000000000000000000000000000000000000000000000000000000000000000000000000000001a701000000000000220020b200000000000000000000000000000000000000000000000000000000000000000000000c00000c00000c00000c00000c000007").unwrap(), &(Arc::clone(&logger) as Arc<dyn Logger>));
+               super::do_test(&<Vec<u8>>::from_hex("01000000000000000000000000000000000000000000000000000000000000000000000001000300000000000000000000000000000000000000000000000000000000000000020300320003000000000000000000000000000000000000000000000000000000000000000203000000000000000000000000000000030012001003000000000000000000000000000000030020001000021aaa0008aaaaaaaaaaaa9aaa030000000000000000000000000000000300120147030000000000000000000000000000000300fe00206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000ff4f00f805273c1b203bb5ebf8436bfde57b3be8c2f5e95d9491dbb181909679000000000000c35000000000000000000000000000000162ffffffffffffffff00000000000002220000000000000000000000fd000601e3030000000000000000000000000000000000000000000000000000000000000001030000000000000000000000000000000000000000000000000000000000000002030000000000000000000000000000000000000000000000000000000000000003030000000000000000000000000000000000000000000000000000000000000004030059030000000000000000000000000000000000000000000000000000000000000005020900000000000000000000000000000000000000000000000000000000000000010000010210000300000000000000000000000000000000fd0300120084030000000000000000000000000000000300940022ff4f00f805273c1b203bb5ebf8436bfde57b3be8c2f5e95d9491dbb1819096793d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000210100000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000c005e020000000100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0150c3000000000000220020ae00000000000000000000000000000000000000000000000000000000000000000000000c00000c00000c00000c00000c00000c00000c00000c00000c00000c00000c00000c000003001200430300000000000000000000000000000003005300243d0000000000000000000000000000000000000000000000000000000000000002080000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000010301320003000000000000000000000000000000000000000000000000000000000000000703000000000000000000000000000000030142000302000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003000000000000000000000000000000030112001001000000000000000000000000000000030120001000021aaa0008aaaaaaaaaaaa9aaa01000000000000000000000000000000050103020000000000000000000000000000000000000000000000000000000000000000c3500003e800fd0301120112010000000000000000000000000000000301ff00210000000000000000000000000000000000000000000000000000000000000e05000000000000016200000000004c4b4000000000000003e800000000000003e80000000203f000050300000000000000000000000000000000000000000000000000000000000001000300000000000000000000000000000000000000000000000000000000000002000300000000000000000000000000000000000000000000000000000000000003000300000000000000000000000000000000000000000000000000000000000004000300000000000000000000000000000000000000000000000000000000000005000266000000000000000000000000000003012300000000000000000000000000000000000000010000000000000000000000000000000a00fd00fd03011200620100000000000000000000000000000003017200233a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007c0001000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000b03011200430100000000000000000000000000000003015300243a000000000000000000000000000000000000000000000000000000000000000267000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003001205ac030000000000000000000000000000000300ff00803d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003e80ff00000000000000000000000000000000000000000000000000000000000000000003f00003000000000000000000000000000000000000000000000000000000000000055511020203e80401a0060800000e00000100000a00000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300c1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffab000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000fd03001200640300000000000000000000000000000003007400843d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030010000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003001200630300000000000000000000000000000003007300853d000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000020b00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000700fd00fd03011200640100000000000000000000000000000003017400843a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006a000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003011200630100000000000000000000000000000003017300853a00000000000000000000000000000000000000000000000000000000000000660000000000000000000000000000000000000000000000000000000000000002640000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000030112004a0100000000000000000000000000000003015a00823a000000000000000000000000000000000000000000000000000000000000000000000000000000ff008888888888888888888888888888888888888888888888888888888888880100000000000000000000000000000003011200640100000000000000000000000000000003017400843a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003011200630100000000000000000000000000000003017300853a0000000000000000000000000000000000000000000000000000000000000067000000000000000000000000000000000000000000000000000000000000000265000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003001205ac030000000000000000000000000000000300ff00803d0000000000000000000000000000000000000000000000000000000000000000000000000000010000000000003e80ff00000000000000000000000000000000000000000000000000000000000000000003f00003000000000000000000000000000000000000000000000000000000000000055511020203e80401a0060800000e00000100000a00000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300c1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffab000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000fd03001200630300000000000000000000000000000003007300853d000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000020a000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003001200640300000000000000000000000000000003007400843d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c3010000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003001200630300000000000000000000000000000003007300853d000000000000000000000000000000000000000000000000000000000000000b00000000000000000000000000000000000000000000000000000000000000020d00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000700fd00fd03011200640100000000000000000000000000000003017400843a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000039000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003011200630100000000000000000000000000000003017300853a00000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000002700000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000030112002c0100000000000000000000000000000003013c00833a00000000000000000000000000000000000000000000000000000000000000000000000000000100000100000000000000000000000000000003011200640100000000000000000000000000000003017400843a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000039000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003011200630100000000000000000000000000000003017300853a000000000000000000000000000000000000000000000000000000000000006500000000000000000000000000000000000000000000000000000000000000027100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000703001200630300000000000000000000000000000003007300853d000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000020c000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003001200640300000000000000000000000000000003007400843d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000032010000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003001205ac030000000000000000000000000000000300ff00803d00000000000000000000000000000000000000000000000000000000000000000000000000000200000000000b0838ff00000000000000000000000000000000000000000000000000000000000000000003f0000300000000000000000000000000000000000000000000000000000000000005551202030927c00401a0060800000e00000100000a00000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300c1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff53000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000fd03001200a4030000000000000000000000000000000300b400843d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007501000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006705000000000000000000000000000000000000000000000000000000000000060300000000000000000000000000000003001200630300000000000000000000000000000003007300853d000000000000000000000000000000000000000000000000000000000000000d00000000000000000000000000000000000000000000000000000000000000020f00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000700fd00fd0c007d02000000013a000000000000000000000000000000000000000000000000000000000000000000000000000000800258020000000000002200204b0000000000000000000000000000000000000000000000000000000000000014c00000000000001600142800000000000000000000000000000000000000050000200c005e0200000001730000000000000000000000000000000000000000000000000000000000000000000000000000000001a701000000000000220020b200000000000000000000000000000000000000000000000000000000000000000000000c00000c00000c00000c00000c000007").unwrap(), &(Arc::clone(&logger) as Arc<dyn Logger>));
 
                let log_entries = logger.lines.lock().unwrap();
                assert_eq!(log_entries.get(&("lightning::ln::peer_handler".to_string(), "Handling SendAcceptChannel event in peer_handler for node 030000000000000000000000000000000000000000000000000000000000000002 for channel ff4f00f805273c1b203bb5ebf8436bfde57b3be8c2f5e95d9491dbb181909679".to_string())), Some(&1)); // 1
index d9d5c0a90376c2cabf5c50ac26b9cd50af23d8a0..c071d806e93aa42fb7bc653d2232f3dbf3491238 100644 (file)
@@ -1,6 +1,6 @@
 // Imports that need to be added manually
 use bitcoin::bech32::u5;
-use bitcoin::blockdata::script::Script;
+use bitcoin::blockdata::script::ScriptBuf;
 use bitcoin::secp256k1::{PublicKey, Scalar, Secp256k1, SecretKey};
 use bitcoin::secp256k1::ecdh::SharedSecret;
 use bitcoin::secp256k1::ecdsa::RecoverableSignature;
@@ -199,13 +199,14 @@ impl SignerProvider for KeyProvider {
 
        fn read_chan_signer(&self, _data: &[u8]) -> Result<TestChannelSigner, DecodeError> { unreachable!() }
 
-       fn get_destination_script(&self) -> Result<Script, ()> { unreachable!() }
+       fn get_destination_script(&self) -> Result<ScriptBuf, ()> { unreachable!() }
 
        fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> { unreachable!() }
 }
 
 #[cfg(test)]
 mod tests {
+       use bitcoin::hashes::hex::FromHex;
        use lightning::util::logger::{Logger, Record};
        use std::collections::HashMap;
        use std::sync::Mutex;
@@ -258,7 +259,7 @@ mod tests {
                        000000000000000000000000000000000000000005600000000000000000000000000000000000000000000\
                        000000000000000000";
                let logger = TrackingLogger { lines: Mutex::new(HashMap::new()) };
-               super::do_test(&::hex::decode(one_hop_om).unwrap(), &logger);
+               super::do_test(&<Vec<u8>>::from_hex(one_hop_om).unwrap(), &logger);
                {
                        let log_entries = logger.lines.lock().unwrap();
                        assert_eq!(log_entries.get(&("lightning::onion_message::messenger".to_string(),
@@ -302,7 +303,7 @@ mod tests {
                        000000000000000000000000000000000000000004800000000000000000000000000000000000000000000\
                        000000000000000000";
                let logger = TrackingLogger { lines: Mutex::new(HashMap::new()) };
-               super::do_test(&::hex::decode(two_unblinded_hops_om).unwrap(), &logger);
+               super::do_test(&<Vec<u8>>::from_hex(two_unblinded_hops_om).unwrap(), &logger);
                {
                        let log_entries = logger.lines.lock().unwrap();
                        assert_eq!(log_entries.get(&("lightning::onion_message::messenger".to_string(), "Forwarding an onion message to peer 020202020202020202020202020202020202020202020202020202020202020202".to_string())), Some(&1));
@@ -343,7 +344,7 @@ mod tests {
                        000000000000000000000000000000000000000004800000000000000000000000000000000000000000000\
                        000000000000000000";
                let logger = TrackingLogger { lines: Mutex::new(HashMap::new()) };
-               super::do_test(&::hex::decode(two_unblinded_two_blinded_om).unwrap(), &logger);
+               super::do_test(&<Vec<u8>>::from_hex(two_unblinded_two_blinded_om).unwrap(), &logger);
                {
                        let log_entries = logger.lines.lock().unwrap();
                        assert_eq!(log_entries.get(&("lightning::onion_message::messenger".to_string(), "Forwarding an onion message to peer 020202020202020202020202020202020202020202020202020202020202020202".to_string())), Some(&1));
@@ -384,7 +385,7 @@ mod tests {
                        000000000000000000000000000000000000000004800000000000000000000000000000000000000000000\
                        000000000000000000";
                let logger = TrackingLogger { lines: Mutex::new(HashMap::new()) };
-               super::do_test(&::hex::decode(three_blinded_om).unwrap(), &logger);
+               super::do_test(&<Vec<u8>>::from_hex(three_blinded_om).unwrap(), &logger);
                {
                        let log_entries = logger.lines.lock().unwrap();
                        assert_eq!(log_entries.get(&("lightning::onion_message::messenger".to_string(), "Forwarding an onion message to peer 020202020202020202020202020202020202020202020202020202020202020202".to_string())), Some(&1));
index 59f77ac5fa44d1ca6fc80f2c33baf48ef18a67fb..933cbc466a677a8cd1f93e9d5e63219682477870 100644 (file)
@@ -21,7 +21,7 @@ no-std = ["bitcoin/no-std", "lightning/no-std", "lightning-rapid-gossip-sync/no-
 default = ["std"]
 
 [dependencies]
-bitcoin = { version = "0.29.0", default-features = false }
+bitcoin = { version = "0.30.2", default-features = false }
 lightning = { version = "0.0.118", path = "../lightning", default-features = false }
 lightning-rapid-gossip-sync = { version = "0.0.118", path = "../lightning-rapid-gossip-sync", default-features = false }
 
index 24d39bf50c1991357859c0ead0b9ecdc15247a57..76252324efc7a37d0072a62e08ac4f171a3841ea 100644 (file)
@@ -845,7 +845,7 @@ impl Drop for BackgroundProcessor {
 #[cfg(all(feature = "std", test))]
 mod tests {
        use bitcoin::blockdata::constants::{genesis_block, ChainHash};
-       use bitcoin::blockdata::locktime::PackedLockTime;
+       use bitcoin::blockdata::locktime::absolute::LockTime;
        use bitcoin::blockdata::transaction::{Transaction, TxOut};
        use bitcoin::network::constants::Network;
        use bitcoin::secp256k1::{SecretKey, PublicKey, Secp256k1};
@@ -1254,7 +1254,7 @@ mod tests {
                                        assert_eq!(channel_value_satoshis, $channel_value);
                                        assert_eq!(user_channel_id, 42);
 
-                                       let tx = Transaction { version: 1 as i32, lock_time: PackedLockTime(0), input: Vec::new(), output: vec![TxOut {
+                                       let tx = Transaction { version: 1 as i32, lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut {
                                                value: channel_value_satoshis, script_pubkey: output_script.clone(),
                                        }]};
                                        (temporary_channel_id, tx)
index d9bb4ee7b1e4bc4b84c4dc69fb3f9072322c0d62..5a8f887c1d82b2b9acb9739bd9055b96653340f5 100644 (file)
@@ -18,7 +18,8 @@ rest-client = [ "serde_json", "chunked_transfer" ]
 rpc-client = [ "serde_json", "chunked_transfer" ]
 
 [dependencies]
-bitcoin = "0.29.0"
+bitcoin = "0.30.2"
+hex = { package = "hex-conservative", version = "0.1.1", default-features = false }
 lightning = { version = "0.0.118", path = "../lightning" }
 tokio = { version = "1.0", features = [ "io-util", "net", "time" ], optional = true }
 serde_json = { version = "1.0", optional = true }
index bf9e9577619a3fd0a1a7fecc3d79cd070bd706e1..0f9ab8c43baadcc8cb72eec2375a063e9c4ffb37 100644 (file)
@@ -1,8 +1,8 @@
 use crate::http::{BinaryResponse, JsonResponse};
-use crate::utils::hex_to_uint256;
+use crate::utils::hex_to_work;
 use crate::{BlockHeaderData, BlockSourceError};
 
-use bitcoin::blockdata::block::{Block, BlockHeader};
+use bitcoin::blockdata::block::{Block, Header};
 use bitcoin::consensus::encode;
 use bitcoin::hash_types::{BlockHash, TxMerkleNode, Txid};
 use bitcoin::hashes::hex::FromHex;
@@ -88,17 +88,21 @@ impl TryFrom<serde_json::Value> for BlockHeaderData {
                } }
 
                Ok(BlockHeaderData {
-                       header: BlockHeader {
-                               version: get_field!("version", as_i64).try_into().map_err(|_| ())?,
+                       header: Header {
+                               version: bitcoin::blockdata::block::Version::from_consensus(
+                                       get_field!("version", as_i64).try_into().map_err(|_| ())?
+                               ),
                                prev_blockhash: if let Some(hash_str) = response.get("previousblockhash") {
-                                               BlockHash::from_hex(hash_str.as_str().ok_or(())?).map_err(|_| ())?
+                                               BlockHash::from_str(hash_str.as_str().ok_or(())?).map_err(|_| ())?
                                        } else { BlockHash::all_zeros() },
-                               merkle_root: TxMerkleNode::from_hex(get_field!("merkleroot", as_str)).map_err(|_| ())?,
+                               merkle_root: TxMerkleNode::from_str(get_field!("merkleroot", as_str)).map_err(|_| ())?,
                                time: get_field!("time", as_u64).try_into().map_err(|_| ())?,
-                               bits: u32::from_be_bytes(<[u8; 4]>::from_hex(get_field!("bits", as_str)).map_err(|_| ())?),
+                               bits: bitcoin::CompactTarget::from_consensus(
+                                       u32::from_be_bytes(<[u8; 4]>::from_hex(get_field!("bits", as_str)).map_err(|_| ())?)
+                               ),
                                nonce: get_field!("nonce", as_u64).try_into().map_err(|_| ())?,
                        },
-                       chainwork: hex_to_uint256(get_field!("chainwork", as_str)).map_err(|_| ())?,
+                       chainwork: hex_to_work(get_field!("chainwork", as_str)).map_err(|_| ())?,
                        height: get_field!("height", as_u64).try_into().map_err(|_| ())?,
                })
        }
@@ -132,7 +136,7 @@ impl TryInto<(BlockHash, Option<u32>)> for JsonResponse {
                }
 
                let hash = match &self.0["bestblockhash"] {
-                       serde_json::Value::String(hex_data) => match BlockHash::from_hex(&hex_data) {
+                       serde_json::Value::String(hex_data) => match BlockHash::from_str(&hex_data) {
                                Err(_) => return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "invalid hex data")),
                                Ok(block_hash) => block_hash,
                        },
@@ -288,8 +292,8 @@ pub(crate) mod tests {
        use super::*;
        use bitcoin::blockdata::constants::genesis_block;
        use bitcoin::hashes::Hash;
-       use bitcoin::hashes::hex::ToHex;
        use bitcoin::network::constants::Network;
+       use hex::DisplayHex;
        use serde_json::value::Number;
        use serde_json::Value;
 
@@ -298,14 +302,14 @@ pub(crate) mod tests {
                fn from(data: BlockHeaderData) -> Self {
                        let BlockHeaderData { chainwork, height, header } = data;
                        serde_json::json!({
-                               "chainwork": chainwork.to_string()["0x".len()..],
+                               "chainwork": chainwork.to_be_bytes().as_hex().to_string(),
                                "height": height,
-                               "version": header.version,
-                               "merkleroot": header.merkle_root.to_hex(),
+                               "version": header.version.to_consensus(),
+                               "merkleroot": header.merkle_root.to_string(),
                                "time": header.time,
                                "nonce": header.nonce,
-                               "bits": header.bits.to_hex(),
-                               "previousblockhash": header.prev_blockhash.to_hex(),
+                               "bits": header.bits.to_consensus().to_be_bytes().as_hex().to_string(),
+                               "previousblockhash": header.prev_blockhash.to_string(),
                        })
                }
        }
@@ -394,7 +398,7 @@ pub(crate) mod tests {
        #[test]
        fn into_block_header_from_json_response_with_valid_header_array() {
                let genesis_block = genesis_block(Network::Bitcoin);
-               let best_block_header = BlockHeader {
+               let best_block_header = Header {
                        prev_blockhash: genesis_block.block_hash(),
                        ..genesis_block.header
                };
@@ -541,7 +545,7 @@ pub(crate) mod tests {
        fn into_block_hash_from_json_response_without_height() {
                let block = genesis_block(Network::Bitcoin);
                let response = JsonResponse(serde_json::json!({
-                       "bestblockhash": block.block_hash().to_hex(),
+                       "bestblockhash": block.block_hash().to_string(),
                }));
                match TryInto::<(BlockHash, Option<u32>)>::try_into(response) {
                        Err(e) => panic!("Unexpected error: {:?}", e),
@@ -556,7 +560,7 @@ pub(crate) mod tests {
        fn into_block_hash_from_json_response_with_unexpected_blocks_type() {
                let block = genesis_block(Network::Bitcoin);
                let response = JsonResponse(serde_json::json!({
-                       "bestblockhash": block.block_hash().to_hex(),
+                       "bestblockhash": block.block_hash().to_string(),
                        "blocks": "foo",
                }));
                match TryInto::<(BlockHash, Option<u32>)>::try_into(response) {
@@ -572,7 +576,7 @@ pub(crate) mod tests {
        fn into_block_hash_from_json_response_with_invalid_height() {
                let block = genesis_block(Network::Bitcoin);
                let response = JsonResponse(serde_json::json!({
-                       "bestblockhash": block.block_hash().to_hex(),
+                       "bestblockhash": block.block_hash().to_string(),
                        "blocks": std::u64::MAX,
                }));
                match TryInto::<(BlockHash, Option<u32>)>::try_into(response) {
@@ -588,7 +592,7 @@ pub(crate) mod tests {
        fn into_block_hash_from_json_response_with_height() {
                let block = genesis_block(Network::Bitcoin);
                let response = JsonResponse(serde_json::json!({
-                       "bestblockhash": block.block_hash().to_hex(),
+                       "bestblockhash": block.block_hash().to_string(),
                        "blocks": 1,
                }));
                match TryInto::<(BlockHash, Option<u32>)>::try_into(response) {
index 5423bba5182e166e75aba7b49f719b1373017af2..df113fb012ae7d22556b18eaaeefe75e379b2c60 100644 (file)
@@ -4,7 +4,7 @@
 use crate::{BlockSource, BlockSourceResult, Cache, ChainNotifier};
 use crate::poll::{ChainPoller, Validate, ValidatedBlockHeader};
 
-use bitcoin::blockdata::block::BlockHeader;
+use bitcoin::blockdata::block::Header;
 use bitcoin::hash_types::BlockHash;
 use bitcoin::network::constants::Network;
 
@@ -211,11 +211,11 @@ impl<'a, C: Cache> Cache for ReadOnlyCache<'a, C> {
 struct DynamicChainListener<'a, L: chain::Listen + ?Sized>(&'a L);
 
 impl<'a, L: chain::Listen + ?Sized> chain::Listen for DynamicChainListener<'a, L> {
-       fn filtered_block_connected(&self, _header: &BlockHeader, _txdata: &chain::transaction::TransactionData, _height: u32) {
+       fn filtered_block_connected(&self, _header: &Header, _txdata: &chain::transaction::TransactionData, _height: u32) {
                unreachable!()
        }
 
-       fn block_disconnected(&self, header: &BlockHeader, height: u32) {
+       fn block_disconnected(&self, header: &Header, height: u32) {
                self.0.block_disconnected(header, height)
        }
 }
@@ -234,7 +234,7 @@ impl<'a, L: chain::Listen + ?Sized> chain::Listen for ChainListenerSet<'a, L> {
                }
        }
 
-       fn filtered_block_connected(&self, header: &BlockHeader, txdata: &chain::transaction::TransactionData, height: u32) {
+       fn filtered_block_connected(&self, header: &Header, txdata: &chain::transaction::TransactionData, height: u32) {
                for (starting_height, chain_listener) in self.0.iter() {
                        if height > *starting_height {
                                chain_listener.filtered_block_connected(header, txdata, height);
@@ -242,7 +242,7 @@ impl<'a, L: chain::Listen + ?Sized> chain::Listen for ChainListenerSet<'a, L> {
                }
        }
 
-       fn block_disconnected(&self, _header: &BlockHeader, _height: u32) {
+       fn block_disconnected(&self, _header: &Header, _height: u32) {
                unreachable!()
        }
 }
index 3561a1b5d769f19381dfdf1bec1e7749cdf8c2d8..77ff3f0810b6f4a3bd6addd98a11faa383660b9d 100644 (file)
@@ -47,9 +47,9 @@ mod utils;
 
 use crate::poll::{ChainTip, Poll, ValidatedBlockHeader};
 
-use bitcoin::blockdata::block::{Block, BlockHeader};
+use bitcoin::blockdata::block::{Block, Header};
 use bitcoin::hash_types::BlockHash;
-use bitcoin::util::uint::Uint256;
+use bitcoin::pow::Work;
 
 use lightning::chain;
 use lightning::chain::Listen;
@@ -147,14 +147,13 @@ impl BlockSourceError {
 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
 pub struct BlockHeaderData {
        /// The block header itself.
-       pub header: BlockHeader,
+       pub header: Header,
 
        /// The block height where the genesis block has height 0.
        pub height: u32,
 
-       /// The total chain work in expected number of double-SHA256 hashes required to build a chain
-       /// of equivalent weight.
-       pub chainwork: Uint256,
+       /// The total chain work required to build a chain of equivalent weight.
+       pub chainwork: Work,
 }
 
 /// A block including either all its transactions or only the block header.
@@ -166,7 +165,7 @@ pub enum BlockData {
        /// A block containing all its transactions.
        FullBlock(Block),
        /// A block header for when the block does not contain any pertinent transactions.
-       HeaderOnly(BlockHeader),
+       HeaderOnly(Header),
 }
 
 /// A lightweight client for keeping a listener in sync with the chain, allowing for Simplified
index e7171cf3656138036d50385691c96e419db29bcd..dcc19a4969dd3eab863c1216b17d434b93f54849 100644 (file)
@@ -60,7 +60,7 @@ impl Validate for BlockHeaderData {
 
        fn validate(self, block_hash: BlockHash) -> BlockSourceResult<Self::T> {
                let pow_valid_block_hash = self.header
-                       .validate_pow(&self.header.target())
+                       .validate_pow(self.header.target())
                        .map_err(BlockSourceError::persistent)?;
 
                if pow_valid_block_hash != block_hash {
@@ -81,7 +81,7 @@ impl Validate for BlockData {
                };
 
                let pow_valid_block_hash = header
-                       .validate_pow(&header.target())
+                       .validate_pow(header.target())
                        .map_err(BlockSourceError::persistent)?;
 
                if pow_valid_block_hash != block_hash {
@@ -138,8 +138,8 @@ impl ValidatedBlockHeader {
                        if self.height % 2016 == 0 {
                                let target = self.header.target();
                                let previous_target = previous_header.header.target();
-                               let min_target = previous_target >> 2;
-                               let max_target = previous_target << 2;
+                               let min_target = previous_target.min_difficulty_transition_threshold();
+                               let max_target = previous_target.max_difficulty_transition_threshold();
                                if target > max_target || target < min_target {
                                        return Err(BlockSourceError::persistent("invalid difficulty transition"))
                                }
@@ -262,7 +262,6 @@ mod tests {
        use crate::*;
        use crate::test_utils::Blockchain;
        use super::*;
-       use bitcoin::util::uint::Uint256;
 
        #[tokio::test]
        async fn poll_empty_chain() {
@@ -302,7 +301,7 @@ mod tests {
 
                // Invalidate the tip by changing its target.
                chain.blocks.last_mut().unwrap().header.bits =
-                       BlockHeader::compact_target_from_u256(&Uint256::from_be_bytes([0; 32]));
+                       bitcoin::Target::from_be_bytes([0x01; 32]).to_compact_lossy();
 
                let poller = ChainPoller::new(&chain, Network::Bitcoin);
                match poller.poll_chain_tip(best_known_chain_tip).await {
index 5690da12ea0495c1c8062655a95b27e83611cfa8..74a460a7ab505d24d70582dece828638c373e593 100644 (file)
@@ -8,7 +8,6 @@ use crate::convert::GetUtxosResponse;
 
 use bitcoin::OutPoint;
 use bitcoin::hash_types::BlockHash;
-use bitcoin::hashes::hex::ToHex;
 
 use std::convert::TryFrom;
 use std::convert::TryInto;
@@ -44,14 +43,14 @@ impl RestClient {
 impl BlockSource for RestClient {
        fn get_header<'a>(&'a self, header_hash: &'a BlockHash, _height: Option<u32>) -> AsyncBlockSourceResult<'a, BlockHeaderData> {
                Box::pin(async move {
-                       let resource_path = format!("headers/1/{}.json", header_hash.to_hex());
+                       let resource_path = format!("headers/1/{}.json", header_hash.to_string());
                        Ok(self.request_resource::<JsonResponse, _>(&resource_path).await?)
                })
        }
 
        fn get_block<'a>(&'a self, header_hash: &'a BlockHash) -> AsyncBlockSourceResult<'a, BlockData> {
                Box::pin(async move {
-                       let resource_path = format!("block/{}.bin", header_hash.to_hex());
+                       let resource_path = format!("block/{}.bin", header_hash.to_string());
                        Ok(BlockData::FullBlock(self.request_resource::<BinaryResponse, _>(&resource_path).await?))
                })
        }
@@ -73,7 +72,7 @@ impl UtxoSource for RestClient {
 
        fn is_output_unspent<'a>(&'a self, outpoint: OutPoint) -> AsyncBlockSourceResult<'a, bool> {
                Box::pin(async move {
-                       let resource_path = format!("getutxos/{}-{}.json", outpoint.txid.to_hex(), outpoint.vout);
+                       let resource_path = format!("getutxos/{}-{}.json", outpoint.txid.to_string(), outpoint.vout);
                        let utxo_result =
                                self.request_resource::<JsonResponse, GetUtxosResponse>(&resource_path).await?;
                        Ok(utxo_result.hit_bitmap_nonempty)
@@ -145,7 +144,7 @@ mod tests {
                ));
                let client = RestClient::new(server.endpoint()).unwrap();
 
-               let outpoint = OutPoint::new(bitcoin::Txid::from_inner([0; 32]), 0);
+               let outpoint = OutPoint::new(bitcoin::Txid::from_byte_array([0; 32]), 0);
                let unspent_output = client.is_output_unspent(outpoint).await.unwrap();
                assert_eq!(unspent_output, false);
        }
@@ -159,7 +158,7 @@ mod tests {
                ));
                let client = RestClient::new(server.endpoint()).unwrap();
 
-               let outpoint = OutPoint::new(bitcoin::Txid::from_inner([0; 32]), 0);
+               let outpoint = OutPoint::new(bitcoin::Txid::from_byte_array([0; 32]), 0);
                let unspent_output = client.is_output_unspent(outpoint).await.unwrap();
                assert_eq!(unspent_output, true);
        }
index 0ad94040acaf0cfcfd326588ecedc35ed1a00a19..d296088ae7eeaf9a1cc07e9ccfdfb7c8a6a2fd42 100644 (file)
@@ -6,7 +6,6 @@ use crate::http::{HttpClient, HttpEndpoint, HttpError, JsonResponse};
 use crate::gossip::UtxoSource;
 
 use bitcoin::hash_types::BlockHash;
-use bitcoin::hashes::hex::ToHex;
 use bitcoin::OutPoint;
 
 use std::sync::Mutex;
@@ -120,14 +119,14 @@ impl RpcClient {
 impl BlockSource for RpcClient {
        fn get_header<'a>(&'a self, header_hash: &'a BlockHash, _height: Option<u32>) -> AsyncBlockSourceResult<'a, BlockHeaderData> {
                Box::pin(async move {
-                       let header_hash = serde_json::json!(header_hash.to_hex());
+                       let header_hash = serde_json::json!(header_hash.to_string());
                        Ok(self.call_method("getblockheader", &[header_hash]).await?)
                })
        }
 
        fn get_block<'a>(&'a self, header_hash: &'a BlockHash) -> AsyncBlockSourceResult<'a, BlockData> {
                Box::pin(async move {
-                       let header_hash = serde_json::json!(header_hash.to_hex());
+                       let header_hash = serde_json::json!(header_hash.to_string());
                        let verbosity = serde_json::json!(0);
                        Ok(BlockData::FullBlock(self.call_method("getblock", &[header_hash, verbosity]).await?))
                })
@@ -150,7 +149,7 @@ impl UtxoSource for RpcClient {
 
        fn is_output_unspent<'a>(&'a self, outpoint: OutPoint) -> AsyncBlockSourceResult<'a, bool> {
                Box::pin(async move {
-                       let txid_param = serde_json::json!(outpoint.txid.to_hex());
+                       let txid_param = serde_json::json!(outpoint.txid.to_string());
                        let vout_param = serde_json::json!(outpoint.vout);
                        let include_mempool = serde_json::json!(false);
                        let utxo_opt: serde_json::Value = self.call_method(
@@ -275,7 +274,7 @@ mod tests {
                let response = serde_json::json!({ "result": null });
                let server = HttpServer::responding_with_ok(MessageBody::Content(response));
                let client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
-               let outpoint = OutPoint::new(bitcoin::Txid::from_inner([0; 32]), 0);
+               let outpoint = OutPoint::new(bitcoin::Txid::from_byte_array([0; 32]), 0);
                let unspent_output = client.is_output_unspent(outpoint).await.unwrap();
                assert_eq!(unspent_output, false);
        }
@@ -285,7 +284,7 @@ mod tests {
                let response = serde_json::json!({ "result": {"bestblock": 1, "confirmations": 42}});
                let server = HttpServer::responding_with_ok(MessageBody::Content(response));
                let client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
-               let outpoint = OutPoint::new(bitcoin::Txid::from_inner([0; 32]), 0);
+               let outpoint = OutPoint::new(bitcoin::Txid::from_byte_array([0; 32]), 0);
                let unspent_output = client.is_output_unspent(outpoint).await.unwrap();
                assert_eq!(unspent_output, true);
        }
index 597d2a85fd51ca8fae8274ec1e6b78adcdc5c9b4..b6fa6617c846e2d57f5288b0a6ecab975425081a 100644 (file)
@@ -1,13 +1,12 @@
 use crate::{AsyncBlockSourceResult, BlockData, BlockHeaderData, BlockSource, BlockSourceError, UnboundedCache};
 use crate::poll::{Validate, ValidatedBlockHeader};
 
-use bitcoin::blockdata::block::{Block, BlockHeader};
+use bitcoin::blockdata::block::{Block, Header, Version};
 use bitcoin::blockdata::constants::genesis_block;
-use bitcoin::hash_types::BlockHash;
+use bitcoin::blockdata::locktime::absolute::LockTime;
+use bitcoin::hash_types::{BlockHash, TxMerkleNode};
 use bitcoin::network::constants::Network;
-use bitcoin::util::uint::Uint256;
-use bitcoin::util::hash::bitcoin_merkle_root;
-use bitcoin::{PackedLockTime, Transaction};
+use bitcoin::Transaction;
 
 use lightning::chain;
 
@@ -35,7 +34,7 @@ impl Blockchain {
 
        pub fn with_height(mut self, height: usize) -> Self {
                self.blocks.reserve_exact(height);
-               let bits = BlockHeader::compact_target_from_u256(&Uint256::from_be_bytes([0xff; 32]));
+               let bits = bitcoin::Target::from_be_bytes([0xff; 32]).to_compact_lossy();
                for i in 1..=height {
                        let prev_block = &self.blocks[i - 1];
                        let prev_blockhash = prev_block.block_hash();
@@ -46,16 +45,16 @@ impl Blockchain {
                        // but that's OK because those tests don't trigger the check.
                        let coinbase = Transaction {
                                version: 0,
-                               lock_time: PackedLockTime::ZERO,
+                               lock_time: LockTime::ZERO,
                                input: vec![],
                                output: vec![]
                        };
-                       let merkle_root = bitcoin_merkle_root(vec![coinbase.txid().as_hash()].into_iter()).unwrap();
+                       let merkle_root = TxMerkleNode::from_raw_hash(coinbase.txid().to_raw_hash());
                        self.blocks.push(Block {
-                               header: BlockHeader {
-                                       version: 0,
+                               header: Header {
+                                       version: Version::NO_SOFT_FORK_SIGNALLING,
                                        prev_blockhash,
-                                       merkle_root: merkle_root.into(),
+                                       merkle_root,
                                        time,
                                        bits,
                                        nonce: 0,
@@ -103,8 +102,12 @@ impl Blockchain {
        fn at_height_unvalidated(&self, height: usize) -> BlockHeaderData {
                assert!(!self.blocks.is_empty());
                assert!(height < self.blocks.len());
+               let mut total_work = self.blocks[0].header.work();
+               for i in 1..=height {
+                       total_work = total_work + self.blocks[i].header.work();
+               }
                BlockHeaderData {
-                       chainwork: self.blocks[0].header.work() + Uint256::from_u64(height as u64).unwrap(),
+                       chainwork: total_work,
                        height: height as u32,
                        header: self.blocks[height].header,
                }
@@ -188,8 +191,8 @@ impl BlockSource for Blockchain {
 pub struct NullChainListener;
 
 impl chain::Listen for NullChainListener {
-       fn filtered_block_connected(&self, _header: &BlockHeader, _txdata: &chain::transaction::TransactionData, _height: u32) {}
-       fn block_disconnected(&self, _header: &BlockHeader, _height: u32) {}
+       fn filtered_block_connected(&self, _header: &Header, _txdata: &chain::transaction::TransactionData, _height: u32) {}
+       fn block_disconnected(&self, _header: &Header, _height: u32) {}
 }
 
 pub struct MockChainListener {
@@ -236,7 +239,7 @@ impl chain::Listen for MockChainListener {
                }
        }
 
-       fn filtered_block_connected(&self, header: &BlockHeader, _txdata: &chain::transaction::TransactionData, height: u32) {
+       fn filtered_block_connected(&self, header: &Header, _txdata: &chain::transaction::TransactionData, height: u32) {
                match self.expected_filtered_blocks_connected.borrow_mut().pop_front() {
                        None => {
                                panic!("Unexpected filtered block connected: {:?}", header.block_hash());
@@ -248,7 +251,7 @@ impl chain::Listen for MockChainListener {
                }
        }
 
-       fn block_disconnected(&self, header: &BlockHeader, height: u32) {
+       fn block_disconnected(&self, header: &Header, height: u32) {
                match self.expected_blocks_disconnected.borrow_mut().pop_front() {
                        None => {
                                panic!("Unexpected block disconnected: {:?}", header.block_hash());
index 96a2e578877aba57d24c0870f44e594dbc8df9c4..b841f5f9d413d90dfa45ebe8cf18516490a9092e 100644 (file)
@@ -1,54 +1,54 @@
 use bitcoin::hashes::hex::FromHex;
-use bitcoin::util::uint::Uint256;
+use bitcoin::pow::Work;
 
-pub fn hex_to_uint256(hex: &str) -> Result<Uint256, bitcoin::hashes::hex::Error> {
+pub fn hex_to_work(hex: &str) -> Result<Work, bitcoin::hashes::hex::Error> {
        let bytes = <[u8; 32]>::from_hex(hex)?;
-       Ok(Uint256::from_be_bytes(bytes))
+       Ok(Work::from_be_bytes(bytes))
 }
 
 #[cfg(test)]
 mod tests {
        use super::*;
-       use bitcoin::util::uint::Uint256;
+       use bitcoin::pow::Work;
 
        #[test]
-       fn hex_to_uint256_empty_str() {
-               assert!(hex_to_uint256("").is_err());
+       fn hex_to_work_empty_str() {
+               assert!(hex_to_work("").is_err());
        }
 
        #[test]
-       fn hex_to_uint256_too_short_str() {
+       fn hex_to_work_too_short_str() {
                let hex = String::from_utf8(vec![b'0'; 32]).unwrap();
-               assert_eq!(hex_to_uint256(&hex), Err(bitcoin::hashes::hex::Error::InvalidLength(64, 32)));
+               assert_eq!(hex_to_work(&hex), Err(bitcoin::hashes::hex::Error::InvalidLength(64, 32)));
        }
 
        #[test]
-       fn hex_to_uint256_too_long_str() {
+       fn hex_to_work_too_long_str() {
                let hex = String::from_utf8(vec![b'0'; 128]).unwrap();
-               assert_eq!(hex_to_uint256(&hex), Err(bitcoin::hashes::hex::Error::InvalidLength(64, 128)));
+               assert_eq!(hex_to_work(&hex), Err(bitcoin::hashes::hex::Error::InvalidLength(64, 128)));
        }
 
        #[test]
-       fn hex_to_uint256_odd_length_str() {
+       fn hex_to_work_odd_length_str() {
                let hex = String::from_utf8(vec![b'0'; 65]).unwrap();
-               assert_eq!(hex_to_uint256(&hex), Err(bitcoin::hashes::hex::Error::OddLengthString(65)));
+               assert_eq!(hex_to_work(&hex), Err(bitcoin::hashes::hex::Error::OddLengthString(65)));
        }
 
        #[test]
-       fn hex_to_uint256_invalid_char() {
+       fn hex_to_work_invalid_char() {
                let hex = String::from_utf8(vec![b'G'; 64]).unwrap();
-               assert_eq!(hex_to_uint256(&hex), Err(bitcoin::hashes::hex::Error::InvalidChar(b'G')));
+               assert_eq!(hex_to_work(&hex), Err(bitcoin::hashes::hex::Error::InvalidChar(b'G')));
        }
 
        #[test]
-       fn hex_to_uint256_lowercase_str() {
-               let hex: String = std::iter::repeat("0123456789abcdef").take(4).collect();
-               assert_eq!(hex_to_uint256(&hex).unwrap(), Uint256([0x0123456789abcdefu64; 4]));
+       fn hex_to_work_lowercase_str() {
+               let hex: String = std::iter::repeat("1a").take(32).collect();
+               assert_eq!(hex_to_work(&hex).unwrap(), Work::from_be_bytes([0x1a; 32]));
        }
 
        #[test]
-       fn hex_to_uint256_uppercase_str() {
-               let hex: String = std::iter::repeat("0123456789ABCDEF").take(4).collect();
-               assert_eq!(hex_to_uint256(&hex).unwrap(), Uint256([0x0123456789abcdefu64; 4]));
+       fn hex_to_work_uppercase_str() {
+               let hex: String = std::iter::repeat("1A").take(32).collect();
+               assert_eq!(hex_to_work(&hex).unwrap(), Work::from_be_bytes([0x1A; 32]));
        }
 }
index 2efce6bcd2cad074a4bb8027eb77625ada4ee255..182ff498512c77515d561376cc04247e876c490e 100644 (file)
@@ -14,5 +14,5 @@ all-features = true
 rustdoc-args = ["--cfg", "docsrs"]
 
 [dependencies]
-bitcoin = "0.29.0"
+bitcoin = "0.30.2"
 lightning = { version = "0.0.118", path = "../lightning" }
index a34bd63b7f296bc06c616a8152cdfebccb03fc2a..0b45fa41e6cbcdede6a5bea5c71446a5f0d0f239 100644 (file)
@@ -22,14 +22,14 @@ std = ["bitcoin_hashes/std", "num-traits/std", "lightning/std", "bech32/std"]
 [dependencies]
 bech32 = { version = "0.9.0", default-features = false }
 lightning = { version = "0.0.118", path = "../lightning", default-features = false }
-secp256k1 = { version = "0.24.0", default-features = false, features = ["recovery", "alloc"] }
+secp256k1 = { version = "0.27.0", default-features = false, features = ["recovery", "alloc"] }
 num-traits = { version = "0.2.8", default-features = false }
-bitcoin_hashes = { version = "0.11", default-features = false }
+bitcoin_hashes = { version = "0.12.0", default-features = false }
 hashbrown = { version = "0.8", optional = true }
 serde = { version = "1.0.118", optional = true }
-bitcoin = { version = "0.29.0", default-features = false }
+bitcoin = { version = "0.30.2", default-features = false }
 
 [dev-dependencies]
 lightning = { version = "0.0.118", path = "../lightning", default-features = false, features = ["_test_utils"] }
-hex = "0.4"
+hex = { package = "hex-conservative", version = "0.1.1", default-features = false }
 serde_json = { version = "1"}
index 5bfa9a042c364b749359f09a0ed96380a589cba6..0276b742f28405b21c2099adeb4333654784c231 100644 (file)
@@ -10,7 +10,7 @@ use core::str::FromStr;
 use bech32::{u5, FromBase32};
 
 use bitcoin::{PubkeyHash, ScriptHash};
-use bitcoin::util::address::WitnessVersion;
+use bitcoin::address::WitnessVersion;
 use bitcoin_hashes::Hash;
 use bitcoin_hashes::sha256;
 use crate::prelude::*;
@@ -726,8 +726,8 @@ mod test {
        use crate::de::Bolt11ParseError;
        use secp256k1::PublicKey;
        use bech32::u5;
-       use bitcoin_hashes::hex::FromHex;
        use bitcoin_hashes::sha256;
+       use std::str::FromStr;
 
        const CHARSET_REV: [i8; 128] = [
                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -778,7 +778,7 @@ mod test {
                        "qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypq".as_bytes()
                );
 
-               let hash = sha256::Hash::from_hex(
+               let hash = sha256::Hash::from_str(
                        "0001020304050607080900010203040506070809000102030405060708090102"
                ).unwrap();
                let expected = Ok(Sha256(hash));
@@ -855,7 +855,7 @@ mod test {
                use crate::Fallback;
                use bech32::FromBase32;
                use bitcoin::{PubkeyHash, ScriptHash};
-               use bitcoin::util::address::WitnessVersion;
+               use bitcoin::address::WitnessVersion;
                use bitcoin_hashes::Hash;
 
                let cases = vec![
@@ -988,7 +988,7 @@ mod test {
                                                data: RawDataPart {
                                                        timestamp: PositiveTimestamp::from_unix_timestamp(1496314658).unwrap(),
                                                        tagged_fields: vec ! [
-                                                               PaymentHash(Sha256(sha256::Hash::from_hex(
+                                                               PaymentHash(Sha256(sha256::Hash::from_str(
                                                                        "0001020304050607080900010203040506070809000102030405060708090102"
                                                                ).unwrap())).into(),
                                                                Description(crate::Description::new("coffee beans".to_owned()).unwrap()).into(),
@@ -1035,7 +1035,7 @@ mod test {
                                        data: RawDataPart {
                                        timestamp: PositiveTimestamp::from_unix_timestamp(1496314658).unwrap(),
                                        tagged_fields: vec ! [
-                                               PaymentHash(Sha256(sha256::Hash::from_hex(
+                                               PaymentHash(Sha256(sha256::Hash::from_str(
                                                        "0001020304050607080900010203040506070809000102030405060708090102"
                                                ).unwrap())).into(),
                                                Description(
index 42d0a337e4a842ce17230c5977552fb6fa477dc7..a5ebf466f8c334e581fa7c25a56e078df9abc184 100644 (file)
@@ -46,7 +46,7 @@ use std::time::SystemTime;
 
 use bech32::u5;
 use bitcoin::{Address, Network, PubkeyHash, ScriptHash};
-use bitcoin::util::address::{Payload, WitnessVersion};
+use bitcoin::address::{Payload, WitnessProgram, WitnessVersion};
 use bitcoin_hashes::{Hash, sha256};
 use lightning::ln::features::Bolt11InvoiceFeatures;
 use lightning::util::invoice::construct_invoice_preimage;
@@ -413,6 +413,7 @@ impl From<Network> for Currency {
                        Network::Testnet => Currency::BitcoinTestnet,
                        Network::Regtest => Currency::Regtest,
                        Network::Signet => Currency::Signet,
+                       _ => unreachable!(),
                }
        }
 }
@@ -1429,10 +1430,13 @@ impl Bolt11Invoice {
 
        /// Returns a list of all fallback addresses as [`Address`]es
        pub fn fallback_addresses(&self) -> Vec<Address> {
-               self.fallbacks().iter().map(|fallback| {
+               self.fallbacks().iter().filter_map(|fallback| {
                        let payload = match fallback {
                                Fallback::SegWitProgram { version, program } => {
-                                       Payload::WitnessProgram { version: *version, program: program.to_vec() }
+                                       match WitnessProgram::new(*version, program.clone()) {
+                                               Ok(witness_program) => Payload::WitnessProgram(witness_program),
+                                               Err(_) => return None,
+                                       }
                                }
                                Fallback::PubKeyHash(pkh) => {
                                        Payload::PubkeyHash(*pkh)
@@ -1442,7 +1446,7 @@ impl Bolt11Invoice {
                                }
                        };
 
-                       Address { payload, network: self.network() }
+                       Some(Address::new(self.network(), payload))
                }).collect()
        }
 
@@ -1755,9 +1759,9 @@ impl<'de> Deserialize<'de> for Bolt11Invoice {
 
 #[cfg(test)]
 mod test {
-       use bitcoin::Script;
-       use bitcoin_hashes::hex::FromHex;
+       use bitcoin::ScriptBuf;
        use bitcoin_hashes::sha256;
+       use std::str::FromStr;
 
        #[test]
        fn test_system_time_bounds_assumptions() {
@@ -1781,7 +1785,7 @@ mod test {
                        data: RawDataPart {
                                timestamp: PositiveTimestamp::from_unix_timestamp(1496314658).unwrap(),
                                tagged_fields: vec![
-                                       PaymentHash(crate::Sha256(sha256::Hash::from_hex(
+                                       PaymentHash(crate::Sha256(sha256::Hash::from_str(
                                                "0001020304050607080900010203040506070809000102030405060708090102"
                                        ).unwrap())).into(),
                                        Description(crate::Description::new(
@@ -1819,7 +1823,7 @@ mod test {
                                data: RawDataPart {
                                        timestamp: PositiveTimestamp::from_unix_timestamp(1496314658).unwrap(),
                                        tagged_fields: vec ! [
-                                               PaymentHash(Sha256(sha256::Hash::from_hex(
+                                               PaymentHash(Sha256(sha256::Hash::from_str(
                                                        "0001020304050607080900010203040506070809000102030405060708090102"
                                                ).unwrap())).into(),
                                                Description(
@@ -1875,7 +1879,7 @@ mod test {
                use lightning::ln::features::Bolt11InvoiceFeatures;
                use secp256k1::Secp256k1;
                use secp256k1::SecretKey;
-               use crate::{Bolt11Invoice, RawBolt11Invoice, RawHrp, RawDataPart, Currency, Sha256, PositiveTimestamp, 
+               use crate::{Bolt11Invoice, RawBolt11Invoice, RawHrp, RawDataPart, Currency, Sha256, PositiveTimestamp,
                         Bolt11SemanticError};
 
                let private_key = SecretKey::from_slice(&[42; 32]).unwrap();
@@ -1889,7 +1893,7 @@ mod test {
                        data: RawDataPart {
                                timestamp: PositiveTimestamp::from_unix_timestamp(1496314658).unwrap(),
                                tagged_fields: vec ! [
-                                       PaymentHash(Sha256(sha256::Hash::from_hex(
+                                       PaymentHash(Sha256(sha256::Hash::from_str(
                                                "0001020304050607080900010203040506070809000102030405060708090102"
                                        ).unwrap())).into(),
                                        Description(
@@ -2146,7 +2150,7 @@ mod test {
                assert_eq!(invoice.expiry_time(), Duration::from_secs(54321));
                assert_eq!(invoice.min_final_cltv_expiry_delta(), 144);
                assert_eq!(invoice.fallbacks(), vec![&Fallback::PubKeyHash(PubkeyHash::from_slice(&[0;20]).unwrap())]);
-               let address = Address::from_script(&Script::new_p2pkh(&PubkeyHash::from_slice(&[0;20]).unwrap()), Network::Testnet).unwrap();
+               let address = Address::from_script(&ScriptBuf::new_p2pkh(&PubkeyHash::from_slice(&[0;20]).unwrap()), Network::Testnet).unwrap();
                assert_eq!(invoice.fallback_addresses(), vec![address]);
                assert_eq!(invoice.private_routes(), vec![&PrivateRoute(route_1), &PrivateRoute(route_2)]);
                assert_eq!(
index a7c9104d3697e774c03c03ef3cee3d7eadc0989c..7306d12f5e6c0061825ebf1d2fde3c2decafde79 100644 (file)
@@ -10,8 +10,7 @@
 //! Convenient utilities for paying Lightning invoices.
 
 use crate::Bolt11Invoice;
-
-use bitcoin_hashes::Hash;
+use crate::bitcoin_hashes::Hash;
 
 use lightning::ln::PaymentHash;
 use lightning::ln::channelmanager::RecipientOnionFields;
@@ -60,7 +59,7 @@ pub fn payment_parameters_from_invoice(invoice: &Bolt11Invoice)
 
 fn params_from_invoice(invoice: &Bolt11Invoice, amount_msat: u64)
 -> (PaymentHash, RecipientOnionFields, RouteParameters) {
-       let payment_hash = PaymentHash((*invoice.payment_hash()).into_inner());
+       let payment_hash = PaymentHash((*invoice.payment_hash()).to_byte_array());
 
        let mut recipient_onion = RecipientOnionFields::secret_only(*invoice.payment_secret());
        recipient_onion.payment_metadata = invoice.payment_metadata().map(|v| v.clone());
index f3e642a2ef555877adc4b83f4b4ccbb670f84611..9930b545662ae4598115f548b983c24860c3337e 100644 (file)
@@ -873,8 +873,7 @@ mod test {
                let route_params = RouteParameters::from_payment_params_and_value(
                        payment_params, invoice.amount_milli_satoshis().unwrap());
                let payment_event = {
-                       let mut payment_hash = PaymentHash([0; 32]);
-                       payment_hash.0.copy_from_slice(&invoice.payment_hash().as_ref()[0..32]);
+                       let payment_hash = PaymentHash(invoice.payment_hash().to_byte_array());
                        nodes[0].node.send_payment(payment_hash,
                                RecipientOnionFields::secret_only(*invoice.payment_secret()),
                                PaymentId(payment_hash.0), route_params, Retry::Attempts(0)).unwrap();
@@ -1295,7 +1294,7 @@ mod test {
 
                let user_payment_preimage = PaymentPreimage([1; 32]);
                let payment_hash = if user_generated_pmt_hash {
-                       Some(PaymentHash(Sha256::hash(&user_payment_preimage.0[..]).into_inner()))
+                       Some(PaymentHash(Sha256::hash(&user_payment_preimage.0[..]).to_byte_array()))
                } else {
                        None
                };
@@ -1308,7 +1307,7 @@ mod test {
                                route_hints, nodes[1].keys_manager, nodes[1].keys_manager, nodes[1].logger,
                                Currency::BitcoinTestnet, None, Duration::from_secs(genesis_timestamp)
                        ).unwrap();
-               let (payment_hash, payment_secret) = (PaymentHash(invoice.payment_hash().into_inner()), *invoice.payment_secret());
+               let (payment_hash, payment_secret) = (PaymentHash(invoice.payment_hash().to_byte_array()), *invoice.payment_secret());
                let payment_preimage = if user_generated_pmt_hash {
                        user_payment_preimage
                } else {
@@ -1328,8 +1327,7 @@ mod test {
                let params = RouteParameters::from_payment_params_and_value(
                        payment_params, invoice.amount_milli_satoshis().unwrap());
                let (payment_event, fwd_idx) = {
-                       let mut payment_hash = PaymentHash([0; 32]);
-                       payment_hash.0.copy_from_slice(&invoice.payment_hash().as_ref()[0..32]);
+                       let payment_hash = PaymentHash(invoice.payment_hash().to_byte_array());
                        nodes[0].node.send_payment(payment_hash,
                                RecipientOnionFields::secret_only(*invoice.payment_secret()),
                                PaymentId(payment_hash.0), params, Retry::Attempts(0)).unwrap();
@@ -1454,7 +1452,7 @@ mod test {
                        nodes[2].node.get_phantom_route_hints(),
                ];
                let user_payment_preimage = PaymentPreimage([1; 32]);
-               let payment_hash = Some(PaymentHash(Sha256::hash(&user_payment_preimage.0[..]).into_inner()));
+               let payment_hash = Some(PaymentHash(Sha256::hash(&user_payment_preimage.0[..]).to_byte_array()));
                let non_default_invoice_expiry_secs = 4200;
                let min_final_cltv_expiry_delta = Some(100);
                let duration_since_epoch = Duration::from_secs(1234567);
index e21b82eae3c7e0053b9efc5f02383716574f026f..98886bef78809aeb7bd9ef9e1784e72e3cf96e4a 100644 (file)
@@ -5,9 +5,9 @@ extern crate lightning_invoice;
 extern crate secp256k1;
 extern crate hex;
 
-use bitcoin::util::address::WitnessVersion;
+use bitcoin::address::WitnessVersion;
 use bitcoin::{PubkeyHash, ScriptHash};
-use bitcoin_hashes::hex::FromHex;
+use bitcoin::hashes::hex::FromHex;
 use bitcoin_hashes::{sha256, Hash};
 use lightning::ln::PaymentSecret;
 use lightning::routing::gossip::RoutingFees;
@@ -26,7 +26,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                        InvoiceBuilder::new(Currency::Bitcoin)
                                .duration_since_epoch(Duration::from_secs(1496314658))
                                .payment_secret(PaymentSecret([0x11; 32]))
-                               .payment_hash(sha256::Hash::from_hex(
+                               .payment_hash(sha256::Hash::from_str(
                                                "0001020304050607080900010203040506070809000102030405060708090102"
                                ).unwrap())
                                .description("Please consider supporting this project".to_owned())
@@ -34,7 +34,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .unwrap()
                                .sign(|_| {
                                        RecoverableSignature::from_compact(
-                                               &hex::decode("8d3ce9e28357337f62da0162d9454df827f83cfe499aeb1c1db349d4d81127425e434ca29929406c23bba1ae8ac6ca32880b38d4bf6ff874024cac34ba9625f1").unwrap(),
+                                               &<Vec<u8>>::from_hex("8d3ce9e28357337f62da0162d9454df827f83cfe499aeb1c1db349d4d81127425e434ca29929406c23bba1ae8ac6ca32880b38d4bf6ff874024cac34ba9625f1").unwrap(),
                                                RecoveryId::from_i32(1).unwrap()
                                        )
                                }).unwrap(),
@@ -47,7 +47,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .amount_milli_satoshis(250_000_000)
                                .duration_since_epoch(Duration::from_secs(1496314658))
                                .payment_secret(PaymentSecret([0x11; 32]))
-                               .payment_hash(sha256::Hash::from_hex(
+                               .payment_hash(sha256::Hash::from_str(
                                        "0001020304050607080900010203040506070809000102030405060708090102"
                                ).unwrap())
                                .description("1 cup coffee".to_owned())
@@ -56,7 +56,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .unwrap()
                                .sign(|_| {
                                        RecoverableSignature::from_compact(
-                                               &hex::decode("e59e3ffbd3945e4334879158d31e89b076dff54f3fa7979ae79df2db9dcaf5896cbfe1a478b8d2307e92c88139464cb7e6ef26e414c4abe33337961ddc5e8ab1").unwrap(),
+                                               &<Vec<u8>>::from_hex("e59e3ffbd3945e4334879158d31e89b076dff54f3fa7979ae79df2db9dcaf5896cbfe1a478b8d2307e92c88139464cb7e6ef26e414c4abe33337961ddc5e8ab1").unwrap(),
                                                RecoveryId::from_i32(1).unwrap()
                                        )
                                }).unwrap(),
@@ -69,7 +69,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .amount_milli_satoshis(250_000_000)
                                .duration_since_epoch(Duration::from_secs(1496314658))
                                .payment_secret(PaymentSecret([0x11; 32]))
-                               .payment_hash(sha256::Hash::from_hex(
+                               .payment_hash(sha256::Hash::from_str(
                                        "0001020304050607080900010203040506070809000102030405060708090102"
                                ).unwrap())
                                .description("ナンセンス 1杯".to_owned())
@@ -78,7 +78,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .unwrap()
                                .sign(|_| {
                                        RecoverableSignature::from_compact(
-                                               &hex::decode("bae41ef385e0fc972977c7ea42b12cbd76577d2412919da8a8a22f9577b6507710c0e96dd78c821dea16453037f717f44aa7e3d196ebb18fbb97307dcb7336c3").unwrap(),
+                                               &<Vec<u8>>::from_hex("bae41ef385e0fc972977c7ea42b12cbd76577d2412919da8a8a22f9577b6507710c0e96dd78c821dea16453037f717f44aa7e3d196ebb18fbb97307dcb7336c3").unwrap(),
                                                RecoveryId::from_i32(1).unwrap()
                                        )
                                }).unwrap(),
@@ -92,14 +92,14 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .duration_since_epoch(Duration::from_secs(1496314658))
                                .description_hash(sha256::Hash::hash(b"One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon"))
                                .payment_secret(PaymentSecret([0x11; 32]))
-                               .payment_hash(sha256::Hash::from_hex(
+                               .payment_hash(sha256::Hash::from_str(
                                        "0001020304050607080900010203040506070809000102030405060708090102"
                                ).unwrap())
                                .build_raw()
                                .unwrap()
                                .sign(|_| {
                                        RecoverableSignature::from_compact(
-                                               &hex::decode("f67a5f696648fa4fb102e1a07b230e54722f8e024cee71e80b4847ac191da3fb2d2cdb28cc32344d7e9a9cf5c9b6a0ee0582ae46e9938b9c81e344a4dbb5289d").unwrap(),
+                                               &<Vec<u8>>::from_hex("f67a5f696648fa4fb102e1a07b230e54722f8e024cee71e80b4847ac191da3fb2d2cdb28cc32344d7e9a9cf5c9b6a0ee0582ae46e9938b9c81e344a4dbb5289d").unwrap(),
                                                RecoveryId::from_i32(1).unwrap()
                                        )
                                }).unwrap(),
@@ -113,7 +113,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .duration_since_epoch(Duration::from_secs(1496314658))
                                .description_hash(sha256::Hash::hash(b"One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon"))
                                .payment_secret(PaymentSecret([0x11; 32]))
-                               .payment_hash(sha256::Hash::from_hex(
+                               .payment_hash(sha256::Hash::from_str(
                                        "0001020304050607080900010203040506070809000102030405060708090102"
                                ).unwrap())
                                .fallback(Fallback::PubKeyHash(PubkeyHash::from_slice(&[49, 114, 181, 101, 79, 102, 131, 200, 251, 20, 105, 89, 211, 71, 206, 48, 60, 174, 76, 167]).unwrap()))
@@ -121,7 +121,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .unwrap()
                                .sign(|_| {
                                        RecoverableSignature::from_compact(
-                                               &hex::decode("6ca95a74dc32e69ced6175b15a5cc56a92bf19f5dace0f134b7d94d464b9f5cf6090a18d48b243f289394d17bdf89466d8e6b37df5981f696bc3dd5986e1bee1").unwrap(),
+                                               &<Vec<u8>>::from_hex("6ca95a74dc32e69ced6175b15a5cc56a92bf19f5dace0f134b7d94d464b9f5cf6090a18d48b243f289394d17bdf89466d8e6b37df5981f696bc3dd5986e1bee1").unwrap(),
                                                RecoveryId::from_i32(1).unwrap()
                                        )
                                }).unwrap(),
@@ -135,12 +135,12 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .duration_since_epoch(Duration::from_secs(1496314658))
                                .description_hash(sha256::Hash::hash(b"One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon"))
                                .payment_secret(PaymentSecret([0x11; 32]))
-                               .payment_hash(sha256::Hash::from_hex(
+                               .payment_hash(sha256::Hash::from_str(
                                        "0001020304050607080900010203040506070809000102030405060708090102"
                                ).unwrap())
                                .fallback(Fallback::PubKeyHash(PubkeyHash::from_slice(&[4, 182, 31, 125, 193, 234, 13, 201, 148, 36, 70, 76, 196, 6, 77, 197, 100, 217, 30, 137]).unwrap()))
                                .private_route(RouteHint(vec![RouteHintHop {
-                                       src_node_id: PublicKey::from_slice(&hex::decode(
+                                       src_node_id: PublicKey::from_slice(&<Vec<u8>>::from_hex(
                                                        "029e03a901b85534ff1e92c43c74431f7ce72046060fcf7a95c37e148f78c77255"
                                                ).unwrap()).unwrap(),
                                        short_channel_id: (66051 << 40) | (263430 << 16) | 1800,
@@ -148,7 +148,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                        cltv_expiry_delta: 3,
                                        htlc_maximum_msat: None, htlc_minimum_msat: None,
                                }, RouteHintHop {
-                                       src_node_id: PublicKey::from_slice(&hex::decode(
+                                       src_node_id: PublicKey::from_slice(&<Vec<u8>>::from_hex(
                                                        "039e03a901b85534ff1e92c43c74431f7ce72046060fcf7a95c37e148f78c77255"
                                                ).unwrap()).unwrap(),
                                        short_channel_id: (197637 << 40) | (395016 << 16) | 2314,
@@ -160,7 +160,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .unwrap()
                                .sign(|_| {
                                        RecoverableSignature::from_compact(
-                                               &hex::decode("6a6586db4e8f6d40e3a5bb92e4df5110c627e9ce493af237e20a046b4e86ea200178c59564ecf892f33a9558bf041b6ad2cb8292d7a6c351fbb7f2ae2d16b54e").unwrap(),
+                                               &<Vec<u8>>::from_hex("6a6586db4e8f6d40e3a5bb92e4df5110c627e9ce493af237e20a046b4e86ea200178c59564ecf892f33a9558bf041b6ad2cb8292d7a6c351fbb7f2ae2d16b54e").unwrap(),
                                                RecoveryId::from_i32(0).unwrap()
                                        )
                                }).unwrap(),
@@ -174,7 +174,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .duration_since_epoch(Duration::from_secs(1496314658))
                                .description_hash(sha256::Hash::hash(b"One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon"))
                                .payment_secret(PaymentSecret([0x11; 32]))
-                               .payment_hash(sha256::Hash::from_hex(
+                               .payment_hash(sha256::Hash::from_str(
                                        "0001020304050607080900010203040506070809000102030405060708090102"
                                ).unwrap())
                                .fallback(Fallback::ScriptHash(ScriptHash::from_slice(&[143, 85, 86, 59, 154, 25, 243, 33, 194, 17, 233, 185, 243, 140, 223, 104, 110, 160, 120, 69]).unwrap()))
@@ -182,7 +182,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .unwrap()
                                .sign(|_| {
                                        RecoverableSignature::from_compact(
-                                               &hex::decode("16810439d1a9bfd5a65acc61340dc92448bb2d456a80b58ce012b73cb5202438020500c9ab7ef5573a4d174c811f669885ae27f895bb3a3be52c243589f87518").unwrap(),
+                                               &<Vec<u8>>::from_hex("16810439d1a9bfd5a65acc61340dc92448bb2d456a80b58ce012b73cb5202438020500c9ab7ef5573a4d174c811f669885ae27f895bb3a3be52c243589f87518").unwrap(),
                                                RecoveryId::from_i32(1).unwrap()
                                        )
                                }).unwrap(),
@@ -196,7 +196,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .duration_since_epoch(Duration::from_secs(1496314658))
                                .description_hash(sha256::Hash::hash(b"One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon"))
                                .payment_secret(PaymentSecret([0x11; 32]))
-                               .payment_hash(sha256::Hash::from_hex(
+                               .payment_hash(sha256::Hash::from_str(
                                        "0001020304050607080900010203040506070809000102030405060708090102"
                                ).unwrap())
                                .fallback(Fallback::SegWitProgram { version: WitnessVersion::V0,
@@ -206,7 +206,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .unwrap()
                                .sign(|_| {
                                        RecoverableSignature::from_compact(
-                                               &hex::decode("5a8bd7b97c1cc9055ee60cf2356621f8752248e037a953886a1782b44a58f5ff2d94e6bc89b7b514541a3603bb33722b6c08aa1a3639d34becc549a99fea6eae").unwrap(),
+                                               &<Vec<u8>>::from_hex("5a8bd7b97c1cc9055ee60cf2356621f8752248e037a953886a1782b44a58f5ff2d94e6bc89b7b514541a3603bb33722b6c08aa1a3639d34becc549a99fea6eae").unwrap(),
                                                RecoveryId::from_i32(0).unwrap()
                                        )
                                }).unwrap(),
@@ -220,7 +220,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .duration_since_epoch(Duration::from_secs(1496314658))
                                .description_hash(sha256::Hash::hash(b"One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon"))
                                .payment_secret(PaymentSecret([0x11; 32]))
-                               .payment_hash(sha256::Hash::from_hex(
+                               .payment_hash(sha256::Hash::from_str(
                                        "0001020304050607080900010203040506070809000102030405060708090102"
                                ).unwrap())
                                .fallback(Fallback::SegWitProgram { version: WitnessVersion::V0,
@@ -230,7 +230,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .unwrap()
                                .sign(|_| {
                                        RecoverableSignature::from_compact(
-                                               &hex::decode("2b3ec248f80301a421817369194f012cdd8af8df1c279981420f9e901e20fa3309d791e11355e609b59ce4a220852a0cd55ab862b1785a83b206c90fa74d01c8").unwrap(),
+                                               &<Vec<u8>>::from_hex("2b3ec248f80301a421817369194f012cdd8af8df1c279981420f9e901e20fa3309d791e11355e609b59ce4a220852a0cd55ab862b1785a83b206c90fa74d01c8").unwrap(),
                                                RecoveryId::from_i32(1).unwrap()
                                        )
                                }).unwrap(),
@@ -243,14 +243,14 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .amount_milli_satoshis(967878534)
                                .duration_since_epoch(Duration::from_secs(1572468703))
                                .payment_secret(PaymentSecret([0x11; 32]))
-                               .payment_hash(sha256::Hash::from_hex(
+                               .payment_hash(sha256::Hash::from_str(
                                        "462264ede7e14047e9b249da94fefc47f41f7d02ee9b091815a5506bc8abf75f"
                                ).unwrap())
                                .expiry_time(Duration::from_secs(604800))
                                .min_final_cltv_expiry_delta(10)
                                .description("Blockstream Store: 88.85 USD for Blockstream Ledger Nano S x 1, \"Back In My Day\" Sticker x 2, \"I Got Lightning Working\" Sticker x 2 and 1 more items".to_owned())
                                .private_route(RouteHint(vec![RouteHintHop {
-                                       src_node_id: PublicKey::from_slice(&hex::decode(
+                                       src_node_id: PublicKey::from_slice(&<Vec<u8>>::from_hex(
                                                        "03d06758583bb5154774a6eb221b1276c9e82d65bbaceca806d90e20c108f4b1c7"
                                                ).unwrap()).unwrap(),
                                        short_channel_id: (589390 << 40) | (3312 << 16) | 1,
@@ -262,7 +262,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .unwrap()
                                .sign(|_| {
                                        RecoverableSignature::from_compact(
-                                               &hex::decode("1b1160cf6186b55722c1ac7ea502086baaccaabdc76b326e666b7f309d972b15069bfca11cd365304b36f48230cc12f3f13a017aab65f7c165a169df32282a58").unwrap(),
+                                               &<Vec<u8>>::from_hex("1b1160cf6186b55722c1ac7ea502086baaccaabdc76b326e666b7f309d972b15069bfca11cd365304b36f48230cc12f3f13a017aab65f7c165a169df32282a58").unwrap(),
                                                RecoveryId::from_i32(1).unwrap()
                                        )
                                }).unwrap(),
@@ -275,7 +275,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .amount_milli_satoshis(2_500_000_000)
                                .duration_since_epoch(Duration::from_secs(1496314658))
                                .payment_secret(PaymentSecret([0x11; 32]))
-                               .payment_hash(sha256::Hash::from_hex(
+                               .payment_hash(sha256::Hash::from_str(
                                        "0001020304050607080900010203040506070809000102030405060708090102"
                                ).unwrap())
                                .description("coffee beans".to_owned())
@@ -283,7 +283,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .unwrap()
                                .sign(|_| {
                                        RecoverableSignature::from_compact(
-                                               &hex::decode("5755469bf4b8e6b6ae7a1308d5f9bad5c82812e0855cd24fac242aa323fa820c5c551ede4faeabcb7fb6d5a464ad0e35c86f615589ee0e0c250c216a662198c1").unwrap(),
+                                               &<Vec<u8>>::from_hex("5755469bf4b8e6b6ae7a1308d5f9bad5c82812e0855cd24fac242aa323fa820c5c551ede4faeabcb7fb6d5a464ad0e35c86f615589ee0e0c250c216a662198c1").unwrap(),
                                                RecoveryId::from_i32(1).unwrap()
                                        )
                                }).unwrap(),
@@ -296,7 +296,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .amount_milli_satoshis(2_500_000_000)
                                .duration_since_epoch(Duration::from_secs(1496314658))
                                .payment_secret(PaymentSecret([0x11; 32]))
-                               .payment_hash(sha256::Hash::from_hex(
+                               .payment_hash(sha256::Hash::from_str(
                                        "0001020304050607080900010203040506070809000102030405060708090102"
                                ).unwrap())
                                .description("coffee beans".to_owned())
@@ -304,7 +304,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .unwrap()
                                .sign(|_| {
                                        RecoverableSignature::from_compact(
-                                               &hex::decode("5755469bf4b8e6b6ae7a1308d5f9bad5c82812e0855cd24fac242aa323fa820c5c551ede4faeabcb7fb6d5a464ad0e35c86f615589ee0e0c250c216a662198c1").unwrap(),
+                                               &<Vec<u8>>::from_hex("5755469bf4b8e6b6ae7a1308d5f9bad5c82812e0855cd24fac242aa323fa820c5c551ede4faeabcb7fb6d5a464ad0e35c86f615589ee0e0c250c216a662198c1").unwrap(),
                                                RecoveryId::from_i32(1).unwrap()
                                        )
                                }).unwrap(),
@@ -317,7 +317,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .amount_milli_satoshis(2_500_000_000)
                                .duration_since_epoch(Duration::from_secs(1496314658))
                                .payment_secret(PaymentSecret([0x11; 32]))
-                               .payment_hash(sha256::Hash::from_hex(
+                               .payment_hash(sha256::Hash::from_str(
                                        "0001020304050607080900010203040506070809000102030405060708090102"
                                ).unwrap())
                                .description("coffee beans".to_owned())
@@ -325,7 +325,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .unwrap()
                                .sign(|_| {
                                        RecoverableSignature::from_compact(
-                                               &hex::decode("150a5252308f25bc2641a186de87470189bb003774326beee33b9a2a720d1584386631c5dda6fc3195f97464bfc93d2574868eadd767d6da1078329c4349c837").unwrap(),
+                                               &<Vec<u8>>::from_hex("150a5252308f25bc2641a186de87470189bb003774326beee33b9a2a720d1584386631c5dda6fc3195f97464bfc93d2574868eadd767d6da1078329c4349c837").unwrap(),
                                                RecoveryId::from_i32(0).unwrap()
                                        )
                                }).unwrap(),
@@ -337,13 +337,13 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                        InvoiceBuilder::new(Currency::Bitcoin)
                                .amount_milli_satoshis(1_000_000_000)
                                .duration_since_epoch(Duration::from_secs(1496314658))
-                               .payment_hash(sha256::Hash::from_hex(
+                               .payment_hash(sha256::Hash::from_str(
                                        "0001020304050607080900010203040506070809000102030405060708090102"
                                ).unwrap())
                                .description("payment metadata inside".to_owned())
-                               .payment_metadata(hex::decode("01fafaf0").unwrap())
+                               .payment_metadata(<Vec<u8>>::from_hex("01fafaf0").unwrap())
                                .require_payment_metadata()
-                               .payee_pub_key(PublicKey::from_slice(&hex::decode(
+                               .payee_pub_key(PublicKey::from_slice(&<Vec<u8>>::from_hex(
                                                "03e7156ae33b0a208d0744199163177e909e80176e55d97a2f221ede0f934dd9ad"
                                        ).unwrap()).unwrap())
                                .payment_secret(PaymentSecret([0x11; 32]))
@@ -351,7 +351,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                                .unwrap()
                                .sign(|_| {
                                        RecoverableSignature::from_compact(
-                                               &hex::decode("2150ed137ddb54f9736c6a0290ded709d22bddb7261d1d6518dffb467c6b1eef02afc182491bdacd00b65c83554c914a1c53c61b0a4ef04eccccdfb4365ed259").unwrap(),
+                                               &<Vec<u8>>::from_hex("2150ed137ddb54f9736c6a0290ded709d22bddb7261d1d6518dffb467c6b1eef02afc182491bdacd00b65c83554c914a1c53c61b0a4ef04eccccdfb4365ed259").unwrap(),
                                                RecoveryId::from_i32(1).unwrap()
                                        )
                                }).unwrap(),
@@ -363,18 +363,18 @@ fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
                        InvoiceBuilder::new(Currency::Bitcoin)
                                .amount_milli_satoshis(1_000_000_000)
                                .duration_since_epoch(Duration::from_secs(1496314658))
-                               .payment_hash(sha256::Hash::from_hex(
+                               .payment_hash(sha256::Hash::from_str(
                                        "0001020304050607080900010203040506070809000102030405060708090102"
                                ).unwrap())
                                .description("payment metadata inside".to_owned())
-                               .payment_metadata(hex::decode("01fafaf0").unwrap())
+                               .payment_metadata(<Vec<u8>>::from_hex("01fafaf0").unwrap())
                                .require_payment_metadata()
                                .payment_secret(PaymentSecret([0x11; 32]))
                                .build_raw()
                                .unwrap()
                                .sign(|_| {
                                        RecoverableSignature::from_compact(
-                                               &hex::decode("f5d27be7d9c27d3aa521bc35d77cabd6bda18f1f61716445b19e27e4e17a887508ea8de5a8e1d94f561248f65434e61a221160dac1f1991b9c0f1057b269d898").unwrap(),
+                                               &<Vec<u8>>::from_hex("f5d27be7d9c27d3aa521bc35d77cabd6bda18f1f61716445b19e27e4e17a887508ea8de5a8e1d94f561248f65434e61a221160dac1f1991b9c0f1057b269d898").unwrap(),
                                                RecoveryId::from_i32(1).unwrap()
                                        )
                                }).unwrap(),
index 6cd3a1fa38276bddd344cd368218e4623992f0dd..247481fcfc853e5da507cd91b2cb96e0c016fd5d 100644 (file)
@@ -15,7 +15,7 @@ all-features = true
 rustdoc-args = ["--cfg", "docsrs"]
 
 [dependencies]
-bitcoin = "0.29.0"
+bitcoin = "0.30.2"
 lightning = { version = "0.0.118", path = "../lightning" }
 tokio = { version = "1.0", features = [ "rt", "sync", "net", "time" ] }
 
index 525b9507329b5385352e76a1e473adbf57c437d4..387366bff0e9f4826af513633f126d42b1e9253c 100644 (file)
@@ -14,7 +14,7 @@ all-features = true
 rustdoc-args = ["--cfg", "docsrs"]
 
 [dependencies]
-bitcoin = "0.29.0"
+bitcoin = "0.30.2"
 lightning = { version = "0.0.118", path = "../lightning" }
 
 [target.'cfg(windows)'.dependencies]
@@ -25,4 +25,4 @@ criterion = { version = "0.4", optional = true, default-features = false }
 
 [dev-dependencies]
 lightning = { version = "0.0.118", path = "../lightning", features = ["_test_utils"] }
-bitcoin = { version = "0.29.0", default-features = false }
+bitcoin = { version = "0.30.2", default-features = false }
index c665d8083cb194e2934263e6eef982585bb37b67..118cf9af7ba0e9554ca23514534007ca8c824e0a 100644 (file)
@@ -369,7 +369,6 @@ mod tests {
        use super::*;
        use crate::test_utils::{do_read_write_remove_list_persist, do_test_store};
 
-       use bitcoin::hashes::hex::FromHex;
        use bitcoin::Txid;
 
        use lightning::chain::ChannelMonitorUpdateStatus;
@@ -381,6 +380,7 @@ mod tests {
        use lightning::util::test_utils;
        use lightning::util::persist::read_channel_monitors;
        use std::fs;
+       use std::str::FromStr;
        #[cfg(target_os = "windows")]
        use {
                lightning::get_event_msg,
@@ -466,7 +466,7 @@ mod tests {
                fs::set_permissions(path, perms).unwrap();
 
                let test_txo = OutPoint {
-                       txid: Txid::from_hex("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(),
+                       txid: Txid::from_str("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(),
                        index: 0
                };
                match store.persist_new_channel(test_txo, &added_monitors[0].1, update_id.2) {
@@ -503,7 +503,7 @@ mod tests {
                let store = FilesystemStore::new(":<>/".into());
 
                let test_txo = OutPoint {
-                       txid: Txid::from_hex("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(),
+                       txid: Txid::from_str("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(),
                        index: 0
                };
                match store.persist_new_channel(test_txo, &added_monitors[0].1, update_id.2) {
index 7853c32e70caedd6f059eae4a9295e594f43ae3c..2018e3b24836094684c9b5f4848b6f28c808abee 100644 (file)
@@ -16,7 +16,7 @@ std = ["lightning/std"]
 
 [dependencies]
 lightning = { version = "0.0.118", path = "../lightning", default-features = false }
-bitcoin = { version = "0.29.0", default-features = false }
+bitcoin = { version = "0.30.2", default-features = false }
 
 [target.'cfg(ldk_bench)'.dependencies]
 criterion = { version = "0.4", optional = true, default-features = false }
index 24f9c687a085a7403aea357ab533defa0d1a0cd7..782c4b7033e91f089ded4f178484e9f28b426ec9 100644 (file)
@@ -22,14 +22,14 @@ async-interface = []
 
 [dependencies]
 lightning = { version = "0.0.118", path = "../lightning", default-features = false }
-bitcoin = { version = "0.29.0", default-features = false }
+bitcoin = { version = "0.30.2", default-features = false }
 bdk-macros = "0.6"
 futures = { version = "0.3", optional = true }
-esplora-client = { version = "0.4", default-features = false, optional = true }
+esplora-client = { version = "0.6", default-features = false, optional = true }
 reqwest = { version = "0.11", optional = true, default-features = false, features = ["json"] }
 
 [dev-dependencies]
 lightning = { version = "0.0.118", path = "../lightning", features = ["std"] }
-electrsd = { version = "0.22.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_23_0"] }
-electrum-client = "0.12.0"
+electrsd = { version = "0.26.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_25_0"] }
+electrum-client = "0.18.0"
 tokio = { version = "1.14.0", features = ["full"] }
index a6ee61e90f268f620caab6c059b2badee58e69d9..45f18afb99bb07632c9590c1bc4e97c686dcab90 100644 (file)
@@ -1,5 +1,6 @@
 use lightning::chain::WatchedOutput;
-use bitcoin::{Txid, BlockHash, Transaction, BlockHeader, OutPoint};
+use bitcoin::{Txid, BlockHash, Transaction, OutPoint};
+use bitcoin::blockdata::block::Header;
 
 use std::collections::{HashSet, HashMap};
 
@@ -69,7 +70,7 @@ impl FilterQueue {
 
 pub(crate) struct ConfirmedTx {
        pub tx: Transaction,
-       pub block_header: BlockHeader,
+       pub block_header: Header,
        pub block_height: u32,
        pub pos: usize,
 }
index 617b1213e89d368903b1903f151176bbc5b9e50e..8a69dce3f3db1d4f7003193e0b039bb4b9d8836d 100644 (file)
@@ -5,12 +5,13 @@ use lightning::chain::transaction::TransactionData;
 use lightning::util::logger::{Logger, Record};
 
 use electrsd::{bitcoind, bitcoind::BitcoinD, ElectrsD};
-use bitcoin::{Amount, Txid, BlockHash, BlockHeader};
+use bitcoin::{Amount, Txid, BlockHash};
+use bitcoin::blockdata::block::Header;
 use bitcoin::blockdata::constants::genesis_block;
 use bitcoin::network::constants::Network;
 use electrsd::bitcoind::bitcoincore_rpc::bitcoincore_rpc_json::AddressType;
 use bitcoind::bitcoincore_rpc::RpcApi;
-use electrum_client::ElectrumApi;
+use electrsd::electrum_client::ElectrumApi;
 
 use std::env;
 use std::sync::Mutex;
@@ -42,21 +43,22 @@ pub fn generate_blocks_and_wait(bitcoind: &BitcoinD, electrsd: &ElectrsD, num: u
        let address = bitcoind
                .client
                .get_new_address(Some("test"), Some(AddressType::Legacy))
-               .expect("failed to get new address");
+               .expect("failed to get new address")
+               .assume_checked();
        // TODO: expect this Result once the WouldBlock issue is resolved upstream.
        let _block_hashes_res = bitcoind.client.generate_to_address(num as u64, &address);
        wait_for_block(electrsd, cur_height as usize + num);
 }
 
 pub fn wait_for_block(electrsd: &ElectrsD, min_height: usize) {
-       let mut header = match electrsd.client.block_headers_subscribe() {
+       let mut header = match electrsd.client.block_headers_subscribe_raw() {
                Ok(header) => header,
                Err(_) => {
                        // While subscribing should succeed the first time around, we ran into some cases where
                        // it didn't. Since we can't proceed without subscribing, we try again after a delay
                        // and panic if it still fails.
                        std::thread::sleep(Duration::from_secs(1));
-                       electrsd.client.block_headers_subscribe().expect("failed to subscribe to block headers")
+                       electrsd.client.block_headers_subscribe_raw().expect("failed to subscribe to block headers")
                }
        };
        loop {
@@ -66,7 +68,7 @@ pub fn wait_for_block(electrsd: &ElectrsD, min_height: usize) {
                header = exponential_backoff_poll(|| {
                        electrsd.trigger().expect("failed to trigger electrsd");
                        electrsd.client.ping().expect("failed to ping electrsd");
-                       electrsd.client.block_headers_pop().expect("failed to pop block header")
+                       electrsd.client.block_headers_pop_raw().expect("failed to pop block header")
                });
        }
 }
@@ -119,7 +121,7 @@ impl TestConfirmable {
 }
 
 impl Confirm for TestConfirmable {
-       fn transactions_confirmed(&self, header: &BlockHeader, txdata: &TransactionData<'_>, height: u32) {
+       fn transactions_confirmed(&self, header: &Header, txdata: &TransactionData<'_>, height: u32) {
                for (_, tx) in txdata {
                        let txid = tx.txid();
                        let block_hash = header.block_hash();
@@ -135,7 +137,7 @@ impl Confirm for TestConfirmable {
                self.events.lock().unwrap().push(TestConfirmableEvent::Unconfirmed(*txid));
        }
 
-       fn best_block_updated(&self, header: &BlockHeader, height: u32) {
+       fn best_block_updated(&self, header: &Header, height: u32) {
                let block_hash = header.block_hash();
                *self.best_block.lock().unwrap() = (block_hash, height);
                self.events.lock().unwrap().push(TestConfirmableEvent::BestBlockUpdated(block_hash, height));
@@ -176,9 +178,9 @@ fn test_esplora_syncs() {
        assert_eq!(events.len(), 1);
 
        // Check registered confirmed transactions are marked confirmed
-       let new_address = bitcoind.client.get_new_address(Some("test"), Some(AddressType::Legacy)).unwrap();
+       let new_address = bitcoind.client.get_new_address(Some("test"), Some(AddressType::Legacy)).unwrap().assume_checked();
        let txid = bitcoind.client.send_to_address(&new_address, Amount::from_sat(5000), None, None, None, None, None, None).unwrap();
-       tx_sync.register_tx(&txid, &new_address.script_pubkey());
+       tx_sync.register_tx(&txid, &new_address.payload.script_pubkey());
 
        tx_sync.sync(vec![&confirmable]).unwrap();
 
@@ -259,9 +261,9 @@ async fn test_esplora_syncs() {
        assert_eq!(events.len(), 1);
 
        // Check registered confirmed transactions are marked confirmed
-       let new_address = bitcoind.client.get_new_address(Some("test"), Some(AddressType::Legacy)).unwrap();
+       let new_address = bitcoind.client.get_new_address(Some("test"), Some(AddressType::Legacy)).unwrap().assume_checked();
        let txid = bitcoind.client.send_to_address(&new_address, Amount::from_sat(5000), None, None, None, None, None, None).unwrap();
-       tx_sync.register_tx(&txid, &new_address.script_pubkey());
+       tx_sync.register_tx(&txid, &new_address.payload.script_pubkey());
 
        tx_sync.sync(vec![&confirmable]).await.unwrap();
 
index b4a0a1124c7f2d4994f3043f0a6df29e19d35c9c..76d751af39192754c67575bdc27650ab89aa88e3 100644 (file)
@@ -17,7 +17,7 @@ rustdoc-args = ["--cfg", "docsrs"]
 
 [features]
 # Internal test utilities exposed to other repo crates
-_test_utils = ["hex", "regex", "bitcoin/bitcoinconsensus"]
+_test_utils = ["regex", "bitcoin/bitcoinconsensus"]
 # Unlog messages superior at targeted level.
 max_level_off = []
 max_level_error = []
@@ -40,21 +40,20 @@ grind_signatures = []
 default = ["std", "grind_signatures"]
 
 [dependencies]
-bitcoin = { version = "0.29.0", default-features = false, features = ["secp-recovery"] }
+bitcoin = { version = "0.30.2", default-features = false, features = ["secp-recovery"] }
 
 hashbrown = { version = "0.8", optional = true }
-hex = { version = "0.4", optional = true }
+hex = { package = "hex-conservative", version = "0.1.1", default-features = false }
 regex = { version = "1.5.6", optional = true }
 backtrace = { version = "0.3", optional = true }
 
 core2 = { version = "0.3.0", optional = true, default-features = false }
 
 [dev-dependencies]
-hex = "0.4"
 regex = "1.5.6"
 
 [dev-dependencies.bitcoin]
-version = "0.29.0"
+version = "0.30.2"
 default-features = false
 features = ["bitcoinconsensus", "secp-recovery"]
 
@@ -62,4 +61,4 @@ features = ["bitcoinconsensus", "secp-recovery"]
 criterion = { version = "0.4", optional = true, default-features = false }
 
 [target.'cfg(taproot)'.dependencies]
-musig2 = { git = "https://github.com/arik-so/rust-musig2", rev = "dc05904" }
+musig2 = { git = "https://github.com/arik-so/rust-musig2", rev = "cff11e3" }
index 33a2cde8c8f6666702b860a0b856bdf1d3c46ff2..2e691898dc26cc187504fee5e774d4f8ce9a4af7 100644 (file)
@@ -49,7 +49,7 @@ where
                                let hop_pk_blinding_factor = {
                                        let mut hmac = HmacEngine::<Sha256>::new(b"blinded_node_id");
                                        hmac.input(encrypted_data_ss.as_ref());
-                                       Hmac::from_engine(hmac).into_inner()
+                                       Hmac::from_engine(hmac).to_byte_array()
                                };
                                $pk.mul_tweak(secp_ctx, &Scalar::from_be_bytes(hop_pk_blinding_factor).unwrap())?
                        };
@@ -70,7 +70,7 @@ where
                                let mut sha = Sha256::engine();
                                sha.input(&msg_blinding_point.serialize()[..]);
                                sha.input(encrypted_data_ss.as_ref());
-                               Sha256::from_engine(sha).into_inner()
+                               Sha256::from_engine(sha).to_byte_array()
                        };
 
                        msg_blinding_point_priv = msg_blinding_point_priv.mul_tweak(&Scalar::from_be_bytes(msg_blinding_point_blinding_factor).unwrap())?;
@@ -80,7 +80,7 @@ where
                                let mut sha = Sha256::engine();
                                sha.input(&onion_packet_pubkey.serialize()[..]);
                                sha.input(onion_packet_ss.as_ref());
-                               Sha256::from_engine(sha).into_inner()
+                               Sha256::from_engine(sha).to_byte_array()
                        };
                        onion_packet_pubkey_priv = onion_packet_pubkey_priv.mul_tweak(&Scalar::from_be_bytes(onion_packet_pubkey_blinding_factor).unwrap())?;
                        onion_packet_pubkey = PublicKey::from_secret_key(secp_ctx, &onion_packet_pubkey_priv);
index 0f128af4afffaf48cb4de4b384030bca4c547575..0186ac374884c82bdbfe4f0d63e1bc4ba0c37343 100644 (file)
@@ -23,7 +23,7 @@
 //! events. The remote server would make use of [`ChainMonitor`] for block processing and for
 //! servicing [`ChannelMonitor`] updates from the client.
 
-use bitcoin::blockdata::block::BlockHeader;
+use bitcoin::blockdata::block::Header;
 use bitcoin::hash_types::{Txid, BlockHash};
 
 use crate::chain;
@@ -312,7 +312,7 @@ where C::Target: chain::Filter,
        /// updated `txdata`.
        ///
        /// Calls which represent a new blockchain tip height should set `best_height`.
-       fn process_chain_data<FN>(&self, header: &BlockHeader, best_height: Option<u32>, txdata: &TransactionData, process: FN)
+       fn process_chain_data<FN>(&self, header: &Header, best_height: Option<u32>, txdata: &TransactionData, process: FN)
        where
                FN: Fn(&ChannelMonitor<ChannelSigner>, &TransactionData) -> Vec<TransactionOutputs>
        {
@@ -355,7 +355,7 @@ where C::Target: chain::Filter,
        }
 
        fn update_monitor_with_chain_data<FN>(
-               &self, header: &BlockHeader, best_height: Option<u32>, txdata: &TransactionData,
+               &self, header: &Header, best_height: Option<u32>, txdata: &TransactionData,
                process: FN, funding_outpoint: &OutPoint, monitor_state: &MonitorHolder<ChannelSigner>
        ) -> Result<(), ()> where FN: Fn(&ChannelMonitor<ChannelSigner>, &TransactionData) -> Vec<TransactionOutputs> {
                let monitor = &monitor_state.monitor;
@@ -635,7 +635,7 @@ where
        L::Target: Logger,
        P::Target: Persist<ChannelSigner>,
 {
-       fn filtered_block_connected(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) {
+       fn filtered_block_connected(&self, header: &Header, txdata: &TransactionData, height: u32) {
                log_debug!(self.logger, "New best block {} at height {} provided via block_connected", header.block_hash(), height);
                self.process_chain_data(header, Some(height), &txdata, |monitor, txdata| {
                        monitor.block_connected(
@@ -643,7 +643,7 @@ where
                });
        }
 
-       fn block_disconnected(&self, header: &BlockHeader, height: u32) {
+       fn block_disconnected(&self, header: &Header, height: u32) {
                let monitor_states = self.monitors.read().unwrap();
                log_debug!(self.logger, "Latest block {} at height {} removed via block_disconnected", header.block_hash(), height);
                for monitor_state in monitor_states.values() {
@@ -662,7 +662,7 @@ where
        L::Target: Logger,
        P::Target: Persist<ChannelSigner>,
 {
-       fn transactions_confirmed(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) {
+       fn transactions_confirmed(&self, header: &Header, txdata: &TransactionData, height: u32) {
                log_debug!(self.logger, "{} provided transactions confirmed at height {} in block {}", txdata.len(), height, header.block_hash());
                self.process_chain_data(header, None, txdata, |monitor, txdata| {
                        monitor.transactions_confirmed(
@@ -678,7 +678,7 @@ where
                }
        }
 
-       fn best_block_updated(&self, header: &BlockHeader, height: u32) {
+       fn best_block_updated(&self, header: &Header, height: u32) {
                log_debug!(self.logger, "New best block {} at height {} provided via best_block_updated", header.block_hash(), height);
                self.process_chain_data(header, Some(height), &[], |monitor, txdata| {
                        // While in practice there shouldn't be any recursive calls when given empty txdata,
index af0f56d882ad591531163df08f9aa05516af92a3..d78f40f3facf3bccec9ced5e483e74bb4bea969d 100644 (file)
@@ -20,9 +20,9 @@
 //! security-domain-separated system design, you should consider having multiple paths for
 //! ChannelMonitors to get out of the HSM and onto monitoring devices.
 
-use bitcoin::blockdata::block::BlockHeader;
+use bitcoin::blockdata::block::Header;
 use bitcoin::blockdata::transaction::{OutPoint as BitcoinOutPoint, TxOut, Transaction};
-use bitcoin::blockdata::script::Script;
+use bitcoin::blockdata::script::{Script, ScriptBuf};
 
 use bitcoin::hashes::Hash;
 use bitcoin::hashes::sha256::Hash as Sha256;
@@ -30,7 +30,8 @@ use bitcoin::hash_types::{Txid, BlockHash};
 
 use bitcoin::secp256k1::{Secp256k1, ecdsa::Signature};
 use bitcoin::secp256k1::{SecretKey, PublicKey};
-use bitcoin::{secp256k1, EcdsaSighashType};
+use bitcoin::secp256k1;
+use bitcoin::sighash::EcdsaSighashType;
 
 use crate::ln::channel::INITIAL_COMMITMENT_NUMBER;
 use crate::ln::{PaymentHash, PaymentPreimage};
@@ -516,7 +517,7 @@ pub(crate) enum ChannelMonitorUpdateStep {
                should_broadcast: bool,
        },
        ShutdownScript {
-               scriptpubkey: Script,
+               scriptpubkey: ScriptBuf,
        },
 }
 
@@ -750,19 +751,19 @@ pub(crate) struct ChannelMonitorImpl<Signer: WriteableEcdsaChannelSigner> {
        latest_update_id: u64,
        commitment_transaction_number_obscure_factor: u64,
 
-       destination_script: Script,
-       broadcasted_holder_revokable_script: Option<(Script, PublicKey, PublicKey)>,
-       counterparty_payment_script: Script,
-       shutdown_script: Option<Script>,
+       destination_script: ScriptBuf,
+       broadcasted_holder_revokable_script: Option<(ScriptBuf, PublicKey, PublicKey)>,
+       counterparty_payment_script: ScriptBuf,
+       shutdown_script: Option<ScriptBuf>,
 
        channel_keys_id: [u8; 32],
        holder_revocation_basepoint: PublicKey,
-       funding_info: (OutPoint, Script),
+       funding_info: (OutPoint, ScriptBuf),
        current_counterparty_commitment_txid: Option<Txid>,
        prev_counterparty_commitment_txid: Option<Txid>,
 
        counterparty_commitment_params: CounterpartyCommitmentParameters,
-       funding_redeemscript: Script,
+       funding_redeemscript: ScriptBuf,
        channel_value_satoshis: u64,
        // first is the idx of the first of the two per-commitment points
        their_cur_per_commitment_points: Option<(u64, PublicKey, Option<PublicKey>)>,
@@ -831,7 +832,7 @@ pub(crate) struct ChannelMonitorImpl<Signer: WriteableEcdsaChannelSigner> {
        // 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<Txid, Vec<(u32, Script)>>,
+       outputs_to_watch: HashMap<Txid, Vec<(u32, ScriptBuf)>>,
 
        #[cfg(test)]
        pub onchain_tx_handler: OnchainTxHandler<Signer>,
@@ -940,7 +941,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signe
                self.counterparty_payment_script.write(writer)?;
                match &self.shutdown_script {
                        Some(script) => script.write(writer)?,
-                       None => Script::new().write(writer)?,
+                       None => ScriptBuf::new().write(writer)?,
                }
 
                self.channel_keys_id.write(writer)?;
@@ -1132,10 +1133,10 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
                ChannelMonitor { inner: Mutex::new(imp) }
        }
 
-       pub(crate) fn new(secp_ctx: Secp256k1<secp256k1::All>, keys: Signer, shutdown_script: Option<Script>,
-                         on_counterparty_tx_csv: u16, destination_script: &Script, funding_info: (OutPoint, Script),
+       pub(crate) fn new(secp_ctx: Secp256k1<secp256k1::All>, keys: Signer, shutdown_script: Option<ScriptBuf>,
+                         on_counterparty_tx_csv: u16, destination_script: &Script, funding_info: (OutPoint, ScriptBuf),
                          channel_parameters: &ChannelTransactionParameters,
-                         funding_redeemscript: Script, channel_value_satoshis: u64,
+                         funding_redeemscript: ScriptBuf, channel_value_satoshis: u64,
                          commitment_transaction_number_obscure_factor: u64,
                          initial_holder_commitment_tx: HolderCommitmentTransaction,
                          best_block: BestBlock, counterparty_node_id: PublicKey) -> ChannelMonitor<Signer> {
@@ -1174,7 +1175,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
                };
 
                let onchain_tx_handler = OnchainTxHandler::new(
-                       channel_value_satoshis, channel_keys_id, destination_script.clone(), keys,
+                       channel_value_satoshis, channel_keys_id, destination_script.into(), keys,
                        channel_parameters.clone(), initial_holder_commitment_tx, secp_ctx
                );
 
@@ -1185,7 +1186,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
                        latest_update_id: 0,
                        commitment_transaction_number_obscure_factor,
 
-                       destination_script: destination_script.clone(),
+                       destination_script: destination_script.into(),
                        broadcasted_holder_revokable_script: None,
                        counterparty_payment_script,
                        shutdown_script,
@@ -1331,13 +1332,13 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
        }
 
        /// Gets the funding transaction outpoint of the channel this ChannelMonitor is monitoring for.
-       pub fn get_funding_txo(&self) -> (OutPoint, Script) {
+       pub fn get_funding_txo(&self) -> (OutPoint, ScriptBuf) {
                self.inner.lock().unwrap().get_funding_txo().clone()
        }
 
        /// 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) -> Vec<(Txid, Vec<(u32, Script)>)> {
+       pub fn get_outputs_to_watch(&self) -> Vec<(Txid, Vec<(u32, ScriptBuf)>)> {
                self.inner.lock().unwrap().get_outputs_to_watch()
                        .iter().map(|(txid, outputs)| (*txid, outputs.clone())).collect()
        }
@@ -1525,7 +1526,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
        /// [`get_outputs_to_watch`]: #method.get_outputs_to_watch
        pub fn block_connected<B: Deref, F: Deref, L: Deref>(
                &self,
-               header: &BlockHeader,
+               header: &Header,
                txdata: &TransactionData,
                height: u32,
                broadcaster: B,
@@ -1545,7 +1546,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
        /// appropriately.
        pub fn block_disconnected<B: Deref, F: Deref, L: Deref>(
                &self,
-               header: &BlockHeader,
+               header: &Header,
                height: u32,
                broadcaster: B,
                fee_estimator: F,
@@ -1568,7 +1569,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
        /// [`block_connected`]: Self::block_connected
        pub fn transactions_confirmed<B: Deref, F: Deref, L: Deref>(
                &self,
-               header: &BlockHeader,
+               header: &Header,
                txdata: &TransactionData,
                height: u32,
                broadcaster: B,
@@ -1616,7 +1617,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
        /// [`block_connected`]: Self::block_connected
        pub fn best_block_updated<B: Deref, F: Deref, L: Deref>(
                &self,
-               header: &BlockHeader,
+               header: &Header,
                height: u32,
                broadcaster: B,
                fee_estimator: F,
@@ -1706,12 +1707,12 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
        }
 
        #[cfg(test)]
-       pub fn get_counterparty_payment_script(&self) -> Script{
+       pub fn get_counterparty_payment_script(&self) -> ScriptBuf {
                self.inner.lock().unwrap().counterparty_payment_script.clone()
        }
 
        #[cfg(test)]
-       pub fn set_counterparty_payment_script(&self, script: Script) {
+       pub fn set_counterparty_payment_script(&self, script: ScriptBuf) {
                self.inner.lock().unwrap().counterparty_payment_script = script;
        }
 }
@@ -2675,7 +2676,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
                                },
                                ChannelMonitorUpdateStep::PaymentPreimage { payment_preimage } => {
                                        log_trace!(logger, "Updating ChannelMonitor with payment preimage");
-                                       self.provide_payment_preimage(&PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner()), &payment_preimage, broadcaster, &bounded_fee_estimator, logger)
+                                       self.provide_payment_preimage(&PaymentHash(Sha256::hash(&payment_preimage.0[..]).to_byte_array()), &payment_preimage, broadcaster, &bounded_fee_estimator, logger)
                                },
                                ChannelMonitorUpdateStep::CommitmentSecret { idx, secret } => {
                                        log_trace!(logger, "Updating ChannelMonitor with commitment secret");
@@ -2766,11 +2767,11 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
                self.latest_update_id
        }
 
-       pub fn get_funding_txo(&self) -> &(OutPoint, Script) {
+       pub fn get_funding_txo(&self) -> &(OutPoint, ScriptBuf) {
                &self.funding_info
        }
 
-       pub fn get_outputs_to_watch(&self) -> &HashMap<Txid, Vec<(u32, Script)>> {
+       pub fn get_outputs_to_watch(&self) -> &HashMap<Txid, Vec<(u32, ScriptBuf)>> {
                // If we've detected a counterparty commitment tx on chain, we must include it in the set
                // of outputs to watch for spends of, otherwise we're likely to lose user funds. Because
                // its trivial to do, double-check that here.
@@ -2986,7 +2987,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
                        };
                }
 
-               let commitment_number = 0xffffffffffff - ((((tx.input[0].sequence.0 as u64 & 0xffffff) << 3*8) | (tx.lock_time.0 as u64 & 0xffffff)) ^ self.commitment_transaction_number_obscure_factor);
+               let commitment_number = 0xffffffffffff - ((((tx.input[0].sequence.0 as u64 & 0xffffff) << 3*8) | (tx.lock_time.to_consensus_u32() as u64 & 0xffffff)) ^ self.commitment_transaction_number_obscure_factor);
                if commitment_number >= self.get_min_seen_secret() {
                        let secret = self.get_secret(commitment_number).unwrap();
                        let per_commitment_key = ignore_error!(SecretKey::from_slice(&secret));
@@ -3203,7 +3204,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
        // Returns (1) `PackageTemplate`s that can be given to the OnchainTxHandler, so that the handler can
        // broadcast transactions claiming holder HTLC commitment outputs and (2) a holder revokable
        // script so we can detect whether a holder transaction has been seen on-chain.
-       fn get_broadcasted_holder_claims(&self, holder_tx: &HolderSignedTx, conf_height: u32) -> (Vec<PackageTemplate>, Option<(Script, PublicKey, PublicKey)>) {
+       fn get_broadcasted_holder_claims(&self, holder_tx: &HolderSignedTx, conf_height: u32) -> (Vec<PackageTemplate>, Option<(ScriptBuf, PublicKey, PublicKey)>) {
                let mut claim_requests = Vec::with_capacity(holder_tx.htlc_outputs.len());
 
                let redeemscript = chan_utils::get_revokeable_redeemscript(&holder_tx.revocation_key, self.on_holder_tx_csv, &holder_tx.delayed_payment_key);
@@ -3366,7 +3367,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
                holder_transactions
        }
 
-       pub fn block_connected<B: Deref, F: Deref, L: Deref>(&mut self, header: &BlockHeader, txdata: &TransactionData, height: u32, broadcaster: B, fee_estimator: F, logger: L) -> Vec<TransactionOutputs>
+       pub fn block_connected<B: Deref, F: Deref, L: Deref>(&mut self, header: &Header, txdata: &TransactionData, height: u32, broadcaster: B, fee_estimator: F, logger: L) -> Vec<TransactionOutputs>
                where B::Target: BroadcasterInterface,
                      F::Target: FeeEstimator,
                                        L::Target: Logger,
@@ -3380,7 +3381,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
 
        fn best_block_updated<B: Deref, F: Deref, L: Deref>(
                &mut self,
-               header: &BlockHeader,
+               header: &Header,
                height: u32,
                broadcaster: B,
                fee_estimator: &LowerBoundedFeeEstimator<F>,
@@ -3406,7 +3407,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
 
        fn transactions_confirmed<B: Deref, F: Deref, L: Deref>(
                &mut self,
-               header: &BlockHeader,
+               header: &Header,
                txdata: &TransactionData,
                height: u32,
                broadcaster: B,
@@ -3475,7 +3476,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
                                                &self.funding_info.0.to_channel_id(), txid);
                                        self.funding_spend_seen = true;
                                        let mut commitment_tx_to_counterparty_output = None;
-                                       if (tx.input[0].sequence.0 >> 8*3) as u8 == 0x80 && (tx.lock_time.0 >> 8*3) as u8 == 0x20 {
+                                       if (tx.input[0].sequence.0 >> 8*3) as u8 == 0x80 && (tx.lock_time.to_consensus_u32() >> 8*3) as u8 == 0x20 {
                                                let (mut new_outpoints, new_outputs, counterparty_output_idx_sats) =
                                                        self.check_spend_counterparty_transaction(&tx, height, &block_hash, &logger);
                                                commitment_tx_to_counterparty_output = counterparty_output_idx_sats;
@@ -3703,7 +3704,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
                watch_outputs
        }
 
-       pub fn block_disconnected<B: Deref, F: Deref, L: Deref>(&mut self, header: &BlockHeader, height: u32, broadcaster: B, fee_estimator: F, logger: L)
+       pub fn block_disconnected<B: Deref, F: Deref, L: Deref>(&mut self, header: &Header, height: u32, broadcaster: B, fee_estimator: F, logger: L)
                where B::Target: BroadcasterInterface,
                      F::Target: FeeEstimator,
                      L::Target: Logger,
@@ -3791,7 +3792,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
                                                                        return true;
                                                                }
 
-                                                               assert_eq!(&bitcoin::Address::p2wsh(&Script::from(input.witness.last().unwrap().to_vec()), bitcoin::Network::Bitcoin).script_pubkey(), _script_pubkey);
+                                                               assert_eq!(&bitcoin::Address::p2wsh(&ScriptBuf::from(input.witness.last().unwrap().to_vec()), bitcoin::Network::Bitcoin).script_pubkey(), _script_pubkey);
                                                        } else if _script_pubkey.is_v0_p2wpkh() {
                                                                assert_eq!(&bitcoin::Address::p2wpkh(&bitcoin::PublicKey::from_slice(&input.witness.last().unwrap()).unwrap(), bitcoin::Network::Bitcoin).unwrap().script_pubkey(), _script_pubkey);
                                                        } else { panic!(); }
@@ -4142,11 +4143,11 @@ where
        F::Target: FeeEstimator,
        L::Target: Logger,
 {
-       fn filtered_block_connected(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) {
+       fn filtered_block_connected(&self, header: &Header, txdata: &TransactionData, height: u32) {
                self.0.block_connected(header, txdata, height, &*self.1, &*self.2, &*self.3);
        }
 
-       fn block_disconnected(&self, header: &BlockHeader, height: u32) {
+       fn block_disconnected(&self, header: &Header, height: u32) {
                self.0.block_disconnected(header, height, &*self.1, &*self.2, &*self.3);
        }
 }
@@ -4158,7 +4159,7 @@ where
        F::Target: FeeEstimator,
        L::Target: Logger,
 {
-       fn transactions_confirmed(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) {
+       fn transactions_confirmed(&self, header: &Header, txdata: &TransactionData, height: u32) {
                self.0.transactions_confirmed(header, txdata, height, &*self.1, &*self.2, &*self.3);
        }
 
@@ -4166,7 +4167,7 @@ where
                self.0.transaction_unconfirmed(txid, &*self.1, &*self.2, &*self.3);
        }
 
-       fn best_block_updated(&self, header: &BlockHeader, height: u32) {
+       fn best_block_updated(&self, header: &Header, height: u32) {
                self.0.best_block_updated(header, height, &*self.1, &*self.2, &*self.3);
        }
 
@@ -4207,9 +4208,9 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
                        1 => { None },
                        _ => return Err(DecodeError::InvalidValue),
                };
-               let mut counterparty_payment_script: Script = Readable::read(reader)?;
+               let mut counterparty_payment_script: ScriptBuf = Readable::read(reader)?;
                let shutdown_script = {
-                       let script = <Script as Readable>::read(reader)?;
+                       let script = <ScriptBuf as Readable>::read(reader)?;
                        if script.is_empty() { None } else { Some(script) }
                };
 
@@ -4315,7 +4316,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
                let mut payment_preimages = HashMap::with_capacity(cmp::min(payment_preimages_len as usize, MAX_ALLOC_SIZE / 32));
                for _ in 0..payment_preimages_len {
                        let preimage: PaymentPreimage = Readable::read(reader)?;
-                       let hash = PaymentHash(Sha256::hash(&preimage.0[..]).into_inner());
+                       let hash = PaymentHash(Sha256::hash(&preimage.0[..]).to_byte_array());
                        if let Some(_) = payment_preimages.insert(hash, preimage) {
                                return Err(DecodeError::InvalidValue);
                        }
@@ -4352,11 +4353,11 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
                }
 
                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::<Txid>() + mem::size_of::<u32>() + 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::<u32>() + mem::size_of::<Vec<ScriptBuf>>())));
                for _ in 0..outputs_to_watch_len {
                        let txid = Readable::read(reader)?;
                        let outputs_len: u64 = Readable::read(reader)?;
-                       let mut outputs = Vec::with_capacity(cmp::min(outputs_len as usize, MAX_ALLOC_SIZE / (mem::size_of::<u32>() + mem::size_of::<Script>())));
+                       let mut outputs = Vec::with_capacity(cmp::min(outputs_len as usize, MAX_ALLOC_SIZE / (mem::size_of::<u32>() + mem::size_of::<ScriptBuf>())));
                        for _ in 0..outputs_len {
                                outputs.push((Readable::read(reader)?, Readable::read(reader)?));
                        }
@@ -4479,11 +4480,13 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
 
 #[cfg(test)]
 mod tests {
-       use bitcoin::blockdata::script::{Script, Builder};
+       use bitcoin::blockdata::locktime::absolute::LockTime;
+       use bitcoin::blockdata::script::{ScriptBuf, Builder};
        use bitcoin::blockdata::opcodes;
-       use bitcoin::blockdata::transaction::{Transaction, TxIn, TxOut, EcdsaSighashType};
+       use bitcoin::blockdata::transaction::{Transaction, TxIn, TxOut};
        use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint;
-       use bitcoin::util::sighash;
+       use bitcoin::sighash;
+       use bitcoin::sighash::EcdsaSighashType;
        use bitcoin::hashes::Hash;
        use bitcoin::hashes::sha256::Hash as Sha256;
        use bitcoin::hashes::hex::FromHex;
@@ -4491,8 +4494,7 @@ mod tests {
        use bitcoin::network::constants::Network;
        use bitcoin::secp256k1::{SecretKey,PublicKey};
        use bitcoin::secp256k1::Secp256k1;
-
-       use hex;
+       use bitcoin::{Sequence, Witness};
 
        use crate::chain::chaininterface::LowerBoundedFeeEstimator;
 
@@ -4514,10 +4516,11 @@ mod tests {
        use crate::util::ser::{ReadableArgs, Writeable};
        use crate::sync::{Arc, Mutex};
        use crate::io;
-       use bitcoin::{PackedLockTime, Sequence, Witness};
        use crate::ln::features::ChannelTypeFeatures;
        use crate::prelude::*;
 
+       use std::str::FromStr;
+
        fn do_test_funding_spend_refuses_updates(use_local_txn: bool) {
                // Previously, monitor updates were allowed freely even after a funding-spend transaction
                // confirmed. This would allow a race condition where we could receive a payment (including
@@ -4617,7 +4620,7 @@ mod tests {
                {
                        for i in 0..20 {
                                let preimage = PaymentPreimage([i; 32]);
-                               let hash = PaymentHash(Sha256::hash(&preimage.0[..]).into_inner());
+                               let hash = PaymentHash(Sha256::hash(&preimage.0[..]).to_byte_array());
                                preimages.push((preimage, hash));
                        }
                }
@@ -4693,18 +4696,18 @@ mod tests {
                let shutdown_pubkey = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
                let best_block = BestBlock::from_network(Network::Testnet);
                let monitor = ChannelMonitor::new(Secp256k1::new(), keys,
-                       Some(ShutdownScript::new_p2wpkh_from_pubkey(shutdown_pubkey).into_inner()), 0, &Script::new(),
-                       (OutPoint { txid: Txid::from_slice(&[43; 32]).unwrap(), index: 0 }, Script::new()),
-                       &channel_parameters, Script::new(), 46, 0, HolderCommitmentTransaction::dummy(&mut Vec::new()),
+                       Some(ShutdownScript::new_p2wpkh_from_pubkey(shutdown_pubkey).into_inner()), 0, &ScriptBuf::new(),
+                       (OutPoint { txid: Txid::from_slice(&[43; 32]).unwrap(), index: 0 }, ScriptBuf::new()),
+                       &channel_parameters, ScriptBuf::new(), 46, 0, HolderCommitmentTransaction::dummy(&mut Vec::new()),
                        best_block, dummy_key);
 
                let mut htlcs = preimages_slice_to_htlcs!(preimages[0..10]);
                let dummy_commitment_tx = HolderCommitmentTransaction::dummy(&mut htlcs);
                monitor.provide_latest_holder_commitment_tx(dummy_commitment_tx.clone(),
                        htlcs.into_iter().map(|(htlc, _)| (htlc, Some(dummy_sig), None)).collect()).unwrap();
-               monitor.provide_latest_counterparty_commitment_tx(Txid::from_inner(Sha256::hash(b"1").into_inner()),
+               monitor.provide_latest_counterparty_commitment_tx(Txid::from_byte_array(Sha256::hash(b"1").to_byte_array()),
                        preimages_slice_to_htlc_outputs!(preimages[5..15]), 281474976710655, dummy_key, &logger);
-               monitor.provide_latest_counterparty_commitment_tx(Txid::from_inner(Sha256::hash(b"2").into_inner()),
+               monitor.provide_latest_counterparty_commitment_tx(Txid::from_byte_array(Sha256::hash(b"2").to_byte_array()),
                        preimages_slice_to_htlc_outputs!(preimages[15..20]), 281474976710654, dummy_key, &logger);
                for &(ref preimage, ref hash) in preimages.iter() {
                        let bounded_fee_estimator = LowerBoundedFeeEstimator::new(&fee_estimator);
@@ -4713,23 +4716,23 @@ mod tests {
 
                // Now provide a secret, pruning preimages 10-15
                let mut secret = [0; 32];
-               secret[0..32].clone_from_slice(&hex::decode("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap());
+               secret[0..32].clone_from_slice(&<Vec<u8>>::from_hex("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap());
                monitor.provide_secret(281474976710655, secret.clone()).unwrap();
                assert_eq!(monitor.inner.lock().unwrap().payment_preimages.len(), 15);
                test_preimages_exist!(&preimages[0..10], monitor);
                test_preimages_exist!(&preimages[15..20], monitor);
 
-               monitor.provide_latest_counterparty_commitment_tx(Txid::from_inner(Sha256::hash(b"3").into_inner()),
+               monitor.provide_latest_counterparty_commitment_tx(Txid::from_byte_array(Sha256::hash(b"3").to_byte_array()),
                        preimages_slice_to_htlc_outputs!(preimages[17..20]), 281474976710653, dummy_key, &logger);
 
                // Now provide a further secret, pruning preimages 15-17
-               secret[0..32].clone_from_slice(&hex::decode("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
+               secret[0..32].clone_from_slice(&<Vec<u8>>::from_hex("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
                monitor.provide_secret(281474976710654, secret.clone()).unwrap();
                assert_eq!(monitor.inner.lock().unwrap().payment_preimages.len(), 13);
                test_preimages_exist!(&preimages[0..10], monitor);
                test_preimages_exist!(&preimages[17..20], monitor);
 
-               monitor.provide_latest_counterparty_commitment_tx(Txid::from_inner(Sha256::hash(b"4").into_inner()),
+               monitor.provide_latest_counterparty_commitment_tx(Txid::from_byte_array(Sha256::hash(b"4").to_byte_array()),
                        preimages_slice_to_htlc_outputs!(preimages[18..20]), 281474976710652, dummy_key, &logger);
 
                // Now update holder commitment tx info, pruning only element 18 as we still care about the
@@ -4738,7 +4741,7 @@ mod tests {
                let dummy_commitment_tx = HolderCommitmentTransaction::dummy(&mut htlcs);
                monitor.provide_latest_holder_commitment_tx(dummy_commitment_tx.clone(),
                        htlcs.into_iter().map(|(htlc, _)| (htlc, Some(dummy_sig), None)).collect()).unwrap();
-               secret[0..32].clone_from_slice(&hex::decode("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
+               secret[0..32].clone_from_slice(&<Vec<u8>>::from_hex("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
                monitor.provide_secret(281474976710653, secret.clone()).unwrap();
                assert_eq!(monitor.inner.lock().unwrap().payment_preimages.len(), 12);
                test_preimages_exist!(&preimages[0..10], monitor);
@@ -4749,7 +4752,7 @@ mod tests {
                let dummy_commitment_tx = HolderCommitmentTransaction::dummy(&mut htlcs);
                monitor.provide_latest_holder_commitment_tx(dummy_commitment_tx,
                        htlcs.into_iter().map(|(htlc, _)| (htlc, Some(dummy_sig), None)).collect()).unwrap();
-               secret[0..32].clone_from_slice(&hex::decode("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
+               secret[0..32].clone_from_slice(&<Vec<u8>>::from_hex("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
                monitor.provide_secret(281474976710652, secret.clone()).unwrap();
                assert_eq!(monitor.inner.lock().unwrap().payment_preimages.len(), 5);
                test_preimages_exist!(&preimages[0..5], monitor);
@@ -4761,7 +4764,7 @@ mod tests {
                // not actual case to avoid sigs and time-lock delays hell variances.
 
                let secp_ctx = Secp256k1::new();
-               let privkey = SecretKey::from_slice(&hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap();
+               let privkey = SecretKey::from_slice(&<Vec<u8>>::from_hex("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap();
                let pubkey = PublicKey::from_secret_key(&secp_ctx, &privkey);
 
                macro_rules! sign_input {
@@ -4778,7 +4781,7 @@ mod tests {
                                let sig = secp_ctx.sign_ecdsa(&sighash, &privkey);
                                let mut ser_sig = sig.serialize_der().to_vec();
                                ser_sig.push(EcdsaSighashType::All as u8);
-                               $sum_actual_sigs += ser_sig.len();
+                               $sum_actual_sigs += ser_sig.len() as u64;
                                let witness = $sighash_parts.witness_mut($idx).unwrap();
                                witness.push(ser_sig);
                                if *$weight == WEIGHT_REVOKED_OUTPUT {
@@ -4799,11 +4802,11 @@ mod tests {
                }
 
                let script_pubkey = Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script();
-               let txid = Txid::from_hex("56944c5d3f98413ef45cf54545538103cc9f298e0575820ad3591376e2e0f65d").unwrap();
+               let txid = Txid::from_str("56944c5d3f98413ef45cf54545538103cc9f298e0575820ad3591376e2e0f65d").unwrap();
 
                // Justice tx with 1 to_holder, 2 revoked offered HTLCs, 1 revoked received HTLCs
                for channel_type_features in [ChannelTypeFeatures::only_static_remote_key(), ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies()].iter() {
-                       let mut claim_tx = Transaction { version: 0, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: Vec::new() };
+                       let mut claim_tx = Transaction { version: 0, lock_time: LockTime::ZERO, input: Vec::new(), output: Vec::new() };
                        let mut sum_actual_sigs = 0;
                        for i in 0..4 {
                                claim_tx.input.push(TxIn {
@@ -4811,7 +4814,7 @@ mod tests {
                                                txid,
                                                vout: i,
                                        },
-                                       script_sig: Script::new(),
+                                       script_sig: ScriptBuf::new(),
                                        sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
                                        witness: Witness::new(),
                                });
@@ -4820,7 +4823,7 @@ mod tests {
                                script_pubkey: script_pubkey.clone(),
                                value: 0,
                        });
-                       let base_weight = claim_tx.weight();
+                       let base_weight = claim_tx.weight().to_wu();
                        let inputs_weight = vec![WEIGHT_REVOKED_OUTPUT, weight_revoked_offered_htlc(channel_type_features), weight_revoked_offered_htlc(channel_type_features), weight_revoked_received_htlc(channel_type_features)];
                        let mut inputs_total_weight = 2; // count segwit flags
                        {
@@ -4830,12 +4833,12 @@ mod tests {
                                        inputs_total_weight += inp;
                                }
                        }
-                       assert_eq!(base_weight + inputs_total_weight as usize,  claim_tx.weight() + /* max_length_sig */ (73 * inputs_weight.len() - sum_actual_sigs));
+                       assert_eq!(base_weight + inputs_total_weight, claim_tx.weight().to_wu() + /* max_length_sig */ (73 * inputs_weight.len() as u64 - sum_actual_sigs));
                }
 
                // Claim tx with 1 offered HTLCs, 3 received HTLCs
                for channel_type_features in [ChannelTypeFeatures::only_static_remote_key(), ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies()].iter() {
-                       let mut claim_tx = Transaction { version: 0, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: Vec::new() };
+                       let mut claim_tx = Transaction { version: 0, lock_time: LockTime::ZERO, input: Vec::new(), output: Vec::new() };
                        let mut sum_actual_sigs = 0;
                        for i in 0..4 {
                                claim_tx.input.push(TxIn {
@@ -4843,7 +4846,7 @@ mod tests {
                                                txid,
                                                vout: i,
                                        },
-                                       script_sig: Script::new(),
+                                       script_sig: ScriptBuf::new(),
                                        sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
                                        witness: Witness::new(),
                                });
@@ -4852,7 +4855,7 @@ mod tests {
                                script_pubkey: script_pubkey.clone(),
                                value: 0,
                        });
-                       let base_weight = claim_tx.weight();
+                       let base_weight = claim_tx.weight().to_wu();
                        let inputs_weight = vec![weight_offered_htlc(channel_type_features), weight_received_htlc(channel_type_features), weight_received_htlc(channel_type_features), weight_received_htlc(channel_type_features)];
                        let mut inputs_total_weight = 2; // count segwit flags
                        {
@@ -4862,19 +4865,19 @@ mod tests {
                                        inputs_total_weight += inp;
                                }
                        }
-                       assert_eq!(base_weight + inputs_total_weight as usize,  claim_tx.weight() + /* max_length_sig */ (73 * inputs_weight.len() - sum_actual_sigs));
+                       assert_eq!(base_weight + inputs_total_weight, claim_tx.weight().to_wu() + /* max_length_sig */ (73 * inputs_weight.len() as u64 - sum_actual_sigs));
                }
 
                // Justice tx with 1 revoked HTLC-Success tx output
                for channel_type_features in [ChannelTypeFeatures::only_static_remote_key(), ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies()].iter() {
-                       let mut claim_tx = Transaction { version: 0, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: Vec::new() };
+                       let mut claim_tx = Transaction { version: 0, lock_time: LockTime::ZERO, input: Vec::new(), output: Vec::new() };
                        let mut sum_actual_sigs = 0;
                        claim_tx.input.push(TxIn {
                                previous_output: BitcoinOutPoint {
                                        txid,
                                        vout: 0,
                                },
-                               script_sig: Script::new(),
+                               script_sig: ScriptBuf::new(),
                                sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
                                witness: Witness::new(),
                        });
@@ -4882,7 +4885,7 @@ mod tests {
                                script_pubkey: script_pubkey.clone(),
                                value: 0,
                        });
-                       let base_weight = claim_tx.weight();
+                       let base_weight = claim_tx.weight().to_wu();
                        let inputs_weight = vec![WEIGHT_REVOKED_OUTPUT];
                        let mut inputs_total_weight = 2; // count segwit flags
                        {
@@ -4892,7 +4895,7 @@ mod tests {
                                        inputs_total_weight += inp;
                                }
                        }
-                       assert_eq!(base_weight + inputs_total_weight as usize, claim_tx.weight() + /* max_length_isg */ (73 * inputs_weight.len() - sum_actual_sigs));
+                       assert_eq!(base_weight + inputs_total_weight, claim_tx.weight().to_wu() + /* max_length_isg */ (73 * inputs_weight.len() as u64 - sum_actual_sigs));
                }
        }
 
index 89e0b155cf68b2db3f24c1a0b23f1e01aacb67b1..239f7c91dbc5d09c433db0ccf53306ca43385034 100644 (file)
@@ -9,9 +9,9 @@
 
 //! Structs and traits which allow other parts of rust-lightning to interact with the blockchain.
 
-use bitcoin::blockdata::block::{Block, BlockHeader};
+use bitcoin::blockdata::block::{Block, Header};
 use bitcoin::blockdata::constants::genesis_block;
-use bitcoin::blockdata::script::Script;
+use bitcoin::blockdata::script::{Script, ScriptBuf};
 use bitcoin::hash_types::{BlockHash, Txid};
 use bitcoin::network::constants::Network;
 use bitcoin::secp256k1::PublicKey;
@@ -73,7 +73,7 @@ impl BestBlock {
 pub trait Listen {
        /// Notifies the listener that a block was added at the given height, with the transaction data
        /// possibly filtered.
-       fn filtered_block_connected(&self, header: &BlockHeader, txdata: &TransactionData, height: u32);
+       fn filtered_block_connected(&self, header: &Header, txdata: &TransactionData, height: u32);
 
        /// Notifies the listener that a block was added at the given height.
        fn block_connected(&self, block: &Block, height: u32) {
@@ -82,7 +82,7 @@ pub trait Listen {
        }
 
        /// Notifies the listener that a block was removed at the given height.
-       fn block_disconnected(&self, header: &BlockHeader, height: u32);
+       fn block_disconnected(&self, header: &Header, height: u32);
 }
 
 /// The `Confirm` trait is used to notify LDK when relevant transactions have been confirmed on
@@ -135,7 +135,7 @@ pub trait Confirm {
        ///
        /// [chain order]: Confirm#order
        /// [`best_block_updated`]: Self::best_block_updated
-       fn transactions_confirmed(&self, header: &BlockHeader, txdata: &TransactionData, height: u32);
+       fn transactions_confirmed(&self, header: &Header, txdata: &TransactionData, height: u32);
        /// Notifies LDK of a transaction that is no longer confirmed as result of a chain reorganization.
        ///
        /// Must be called for any transaction returned by [`get_relevant_txids`] if it has been
@@ -150,7 +150,7 @@ pub trait Confirm {
        ///
        /// Must be called whenever a new chain tip becomes available. May be skipped for intermediary
        /// blocks.
-       fn best_block_updated(&self, header: &BlockHeader, height: u32);
+       fn best_block_updated(&self, header: &Header, height: u32);
        /// Returns transactions that must be monitored for reorganization out of the chain along
        /// with the hash of the block as part of which it had been previously confirmed.
        ///
@@ -354,15 +354,15 @@ pub struct WatchedOutput {
        pub outpoint: OutPoint,
 
        /// Spending condition of the transaction output.
-       pub script_pubkey: Script,
+       pub script_pubkey: ScriptBuf,
 }
 
 impl<T: Listen> Listen for core::ops::Deref<Target = T> {
-       fn filtered_block_connected(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) {
+       fn filtered_block_connected(&self, header: &Header, txdata: &TransactionData, height: u32) {
                (**self).filtered_block_connected(header, txdata, height);
        }
 
-       fn block_disconnected(&self, header: &BlockHeader, height: u32) {
+       fn block_disconnected(&self, header: &Header, height: u32) {
                (**self).block_disconnected(header, height);
        }
 }
@@ -372,12 +372,12 @@ where
        T::Target: Listen,
        U::Target: Listen,
 {
-       fn filtered_block_connected(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) {
+       fn filtered_block_connected(&self, header: &Header, txdata: &TransactionData, height: u32) {
                self.0.filtered_block_connected(header, txdata, height);
                self.1.filtered_block_connected(header, txdata, height);
        }
 
-       fn block_disconnected(&self, header: &BlockHeader, height: u32) {
+       fn block_disconnected(&self, header: &Header, height: u32) {
                self.0.block_disconnected(header, height);
                self.1.block_disconnected(header, height);
        }
index 5aba6593834cf3a37848fe1c9763e6b5f6de7f3a..2573854898cf278c7e63dbad331d531cc313c641 100644 (file)
 //! OnchainTxHandler objects are fully-part of ChannelMonitor and encapsulates all
 //! building, tracking, bumping and notifications functions.
 
-use bitcoin::PackedLockTime;
+use bitcoin::blockdata::locktime::absolute::LockTime;
 use bitcoin::blockdata::transaction::Transaction;
 use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint;
-use bitcoin::blockdata::script::Script;
+use bitcoin::blockdata::script::{Script, ScriptBuf};
 use bitcoin::hashes::{Hash, HashEngine};
 use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::hash_types::{Txid, BlockHash};
@@ -196,7 +196,7 @@ pub(crate) enum ClaimEvent {
        BumpHTLC {
                target_feerate_sat_per_1000_weight: u32,
                htlcs: Vec<ExternalHTLCClaim>,
-               tx_lock_time: PackedLockTime,
+               tx_lock_time: LockTime,
        },
 }
 
@@ -216,7 +216,7 @@ pub(crate) enum OnchainClaim {
 pub struct OnchainTxHandler<ChannelSigner: WriteableEcdsaChannelSigner> {
        channel_value_satoshis: u64,
        channel_keys_id: [u8; 32],
-       destination_script: Script,
+       destination_script: ScriptBuf,
        holder_commitment: HolderCommitmentTransaction,
        prev_holder_commitment: Option<HolderCommitmentTransaction>,
 
@@ -433,7 +433,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
 
 impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
        pub(crate) fn new(
-               channel_value_satoshis: u64, channel_keys_id: [u8; 32], destination_script: Script,
+               channel_value_satoshis: u64, channel_keys_id: [u8; 32], destination_script: ScriptBuf,
                signer: ChannelSigner, channel_parameters: ChannelTransactionParameters,
                holder_commitment: HolderCommitmentTransaction, secp_ctx: Secp256k1<secp256k1::All>
        ) -> Self {
@@ -589,7 +589,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
                                                OnchainClaim::Event(ClaimEvent::BumpHTLC {
                                                        target_feerate_sat_per_1000_weight,
                                                        htlcs,
-                                                       tx_lock_time: PackedLockTime(cached_request.package_locktime(cur_height)),
+                                                       tx_lock_time: LockTime::from_consensus(cached_request.package_locktime(cur_height)),
                                                }),
                                        ));
                                } else {
@@ -608,7 +608,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
                                        cur_height, self, output_value, self.destination_script.clone(), logger
                                ).unwrap();
                                log_trace!(logger, "...with timer {} and feerate {}", new_timer, new_feerate);
-                               assert!(predicted_weight >= transaction.weight());
+                               assert!(predicted_weight >= transaction.weight().to_wu());
                                return Some((new_timer, new_feerate, OnchainClaim::Tx(transaction)));
                        }
                } else {
@@ -637,7 +637,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
                                        if let Some(input_amount_sat) = output.funding_amount {
                                                let fee_sat = input_amount_sat - tx.output.iter().map(|output| output.value).sum::<u64>();
                                                let commitment_tx_feerate_sat_per_1000_weight =
-                                                       compute_feerate_sat_per_1000_weight(fee_sat, tx.weight() as u64);
+                                                       compute_feerate_sat_per_1000_weight(fee_sat, tx.weight().to_wu());
                                                if commitment_tx_feerate_sat_per_1000_weight >= package_target_feerate_sat_per_1000_weight {
                                                        log_debug!(logger, "Pre-signed {} already has feerate {} sat/kW above required {} sat/kW",
                                                                log_tx!(tx), commitment_tx_feerate_sat_per_1000_weight,
@@ -763,7 +763,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
                                        OnchainClaim::Tx(tx) => {
                                                log_info!(logger, "Broadcasting onchain {}", log_tx!(tx));
                                                broadcaster.broadcast_transactions(&[&tx]);
-                                               ClaimId(tx.txid().into_inner())
+                                               ClaimId(tx.txid().to_byte_array())
                                        },
                                        OnchainClaim::Event(claim_event) => {
                                                log_info!(logger, "Yielding onchain event to spend inputs {:?}", req.outpoints());
@@ -771,7 +771,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
                                                        ClaimEvent::BumpCommitment { ref commitment_tx, .. } =>
                                                                // For commitment claims, we can just use their txid as it should
                                                                // already be unique.
-                                                               ClaimId(commitment_tx.txid().into_inner()),
+                                                               ClaimId(commitment_tx.txid().to_byte_array()),
                                                        ClaimEvent::BumpHTLC { ref htlcs, .. } => {
                                                                // For HTLC claims, commit to the entire set of HTLC outputs to
                                                                // claim, which will always be unique per request. Once a claim ID
@@ -779,10 +779,10 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
                                                                // underlying set of HTLCs changes.
                                                                let mut engine = Sha256::engine();
                                                                for htlc in htlcs {
-                                                                       engine.input(&htlc.commitment_txid.into_inner());
+                                                                       engine.input(&htlc.commitment_txid.to_byte_array());
                                                                        engine.input(&htlc.htlc.transaction_output_index.unwrap().to_be_bytes());
                                                                }
-                                                               ClaimId(Sha256::from_engine(engine).into_inner())
+                                                               ClaimId(Sha256::from_engine(engine).to_byte_array())
                                                        },
                                                };
                                                debug_assert!(self.pending_claim_requests.get(&claim_id).is_none());
index 1b938d98137ef76cf4a4d2db82019027f504a8bf..5fb893d8adf7c552da516e6685e7efec245fdb3c 100644 (file)
 //! packages are attached metadata, guiding their aggregable or fee-bumping re-schedule. This file
 //! also includes witness weight computation and fee computation methods.
 
+
+use bitcoin::{Sequence, Witness};
 use bitcoin::blockdata::constants::WITNESS_SCALE_FACTOR;
-use bitcoin::blockdata::transaction::{TxOut,TxIn, Transaction, EcdsaSighashType};
+use bitcoin::blockdata::locktime::absolute::LockTime;
+use bitcoin::blockdata::transaction::{TxOut,TxIn, Transaction};
 use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint;
-use bitcoin::blockdata::script::Script;
-
+use bitcoin::blockdata::script::{Script, ScriptBuf};
 use bitcoin::hash_types::Txid;
-
 use bitcoin::secp256k1::{SecretKey,PublicKey};
+use bitcoin::sighash::EcdsaSighashType;
 
 use crate::ln::PaymentPreimage;
 use crate::ln::chan_utils::{TxCreationKeys, HTLCOutputInCommitment};
 use crate::ln::chan_utils;
+use crate::ln::features::ChannelTypeFeatures;
 use crate::ln::msgs::DecodeError;
 use crate::chain::chaininterface::{FeeEstimator, ConfirmationTarget, MIN_RELAY_FEE_SAT_PER_1000_WEIGHT, compute_feerate_sat_per_1000_weight, FEERATE_FLOOR_SATS_PER_KW};
 use crate::sign::WriteableEcdsaChannelSigner;
@@ -36,8 +39,6 @@ use core::cmp;
 use core::convert::TryInto;
 use core::mem;
 use core::ops::Deref;
-use bitcoin::{PackedLockTime, Sequence, Witness};
-use crate::ln::features::ChannelTypeFeatures;
 
 use super::chaininterface::LowerBoundedFeeEstimator;
 
@@ -428,14 +429,14 @@ impl Readable for HolderHTLCOutput {
 /// Note that on upgrades, some features of existing outputs may be missed.
 #[derive(Clone, PartialEq, Eq)]
 pub(crate) struct HolderFundingOutput {
-       funding_redeemscript: Script,
+       funding_redeemscript: ScriptBuf,
        pub(crate) funding_amount: Option<u64>,
        channel_type_features: ChannelTypeFeatures,
 }
 
 
 impl HolderFundingOutput {
-       pub(crate) fn build(funding_redeemscript: Script, funding_amount: u64, channel_type_features: ChannelTypeFeatures) -> Self {
+       pub(crate) fn build(funding_redeemscript: ScriptBuf, funding_amount: u64, channel_type_features: ChannelTypeFeatures) -> Self {
                HolderFundingOutput {
                        funding_redeemscript,
                        funding_amount: Some(funding_amount),
@@ -572,7 +573,7 @@ impl PackageSolvingData {
                };
                TxIn {
                        previous_output,
-                       script_sig: Script::new(),
+                       script_sig: ScriptBuf::new(),
                        sequence,
                        witness: Witness::new(),
                }
@@ -875,7 +876,7 @@ impl PackageTemplate {
 
                locktime
        }
-       pub(crate) fn package_weight(&self, destination_script: &Script) -> usize {
+       pub(crate) fn package_weight(&self, destination_script: &Script) -> u64 {
                let mut inputs_weight = 0;
                let mut witnesses_weight = 2; // count segwit flags
                for (_, outp) in self.inputs.iter() {
@@ -887,7 +888,7 @@ impl PackageTemplate {
                let transaction_weight = 10 * WITNESS_SCALE_FACTOR;
                // value: 8 bytes ; var_int: 1 byte ; pk_script: `destination_script.len()`
                let output_weight = (8 + 1 + destination_script.len()) * WITNESS_SCALE_FACTOR;
-               inputs_weight + witnesses_weight + transaction_weight + output_weight
+               (inputs_weight + witnesses_weight + transaction_weight + output_weight) as u64
        }
        pub(crate) fn construct_malleable_package_with_external_funding<Signer: WriteableEcdsaChannelSigner>(
                &self, onchain_handler: &mut OnchainTxHandler<Signer>,
@@ -909,12 +910,12 @@ impl PackageTemplate {
        }
        pub(crate) fn finalize_malleable_package<L: Deref, Signer: WriteableEcdsaChannelSigner>(
                &self, current_height: u32, onchain_handler: &mut OnchainTxHandler<Signer>, value: u64,
-               destination_script: Script, logger: &L
+               destination_script: ScriptBuf, logger: &L
        ) -> Option<Transaction> where L::Target: Logger {
                debug_assert!(self.is_malleable());
                let mut bumped_tx = Transaction {
                        version: 2,
-                       lock_time: PackedLockTime(self.package_locktime(current_height)),
+                       lock_time: LockTime::from_consensus(self.package_locktime(current_height)),
                        input: vec![],
                        output: vec![TxOut {
                                script_pubkey: destination_script,
@@ -962,7 +963,7 @@ impl PackageTemplate {
        /// which was used to generate the value. Will not return less than `dust_limit_sats` for the
        /// value.
        pub(crate) fn compute_package_output<F: Deref, L: Deref>(
-               &self, predicted_weight: usize, dust_limit_sats: u64, force_feerate_bump: bool,
+               &self, predicted_weight: u64, dust_limit_sats: u64, force_feerate_bump: bool,
                fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
        ) -> Option<(u64, u64)>
        where
@@ -1110,21 +1111,21 @@ impl Readable for PackageTemplate {
 ///
 /// [`OnChainSweep`]: crate::chain::chaininterface::ConfirmationTarget::OnChainSweep
 /// [`FEERATE_FLOOR_SATS_PER_KW`]: crate::chain::chaininterface::MIN_RELAY_FEE_SAT_PER_1000_WEIGHT
-fn compute_fee_from_spent_amounts<F: Deref, L: Deref>(input_amounts: u64, predicted_weight: usize, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L) -> Option<(u64, u64)>
+fn compute_fee_from_spent_amounts<F: Deref, L: Deref>(input_amounts: u64, predicted_weight: u64, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L) -> Option<(u64, u64)>
        where F::Target: FeeEstimator,
              L::Target: Logger,
 {
        let sweep_feerate = fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::OnChainSweep);
-       let fee_rate = cmp::min(sweep_feerate, compute_feerate_sat_per_1000_weight(input_amounts / 2, predicted_weight as u64)) as u64;
-       let fee = fee_rate * (predicted_weight as u64) / 1000;
+       let fee_rate = cmp::min(sweep_feerate, compute_feerate_sat_per_1000_weight(input_amounts / 2, predicted_weight));
+       let fee = fee_rate as u64 * (predicted_weight) / 1000;
 
        // if the fee rate is below the floor, we don't sweep
-       if fee_rate < FEERATE_FLOOR_SATS_PER_KW as u64 {
+       if fee_rate < FEERATE_FLOOR_SATS_PER_KW {
                log_error!(logger, "Failed to generate an on-chain tx with fee ({} sat/kw) was less than the floor ({} sat/kw)",
                                        fee_rate, FEERATE_FLOOR_SATS_PER_KW);
                None
        } else {
-               Some((fee, fee_rate))
+               Some((fee, fee_rate as u64))
        }
 }
 
@@ -1135,7 +1136,7 @@ fn compute_fee_from_spent_amounts<F: Deref, L: Deref>(input_amounts: u64, predic
 /// verify that those bumping heuristics respect BIP125 rules 3) and 4) and if required adjust the
 /// new fee to meet the RBF policy requirement.
 fn feerate_bump<F: Deref, L: Deref>(
-       predicted_weight: usize, input_amounts: u64, previous_feerate: u64, force_feerate_bump: bool,
+       predicted_weight: u64, input_amounts: u64, previous_feerate: u64, force_feerate_bump: bool,
        fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
 ) -> Option<(u64, u64)>
 where
@@ -1147,12 +1148,12 @@ where
                if new_feerate > previous_feerate {
                        (new_fee, new_feerate)
                } else if !force_feerate_bump {
-                       let previous_fee = previous_feerate * (predicted_weight as u64) / 1000;
+                       let previous_fee = previous_feerate * predicted_weight / 1000;
                        (previous_fee, previous_feerate)
                } else {
                        // ...else just increase the previous feerate by 25% (because that's a nice number)
                        let bumped_feerate = previous_feerate + (previous_feerate / 4);
-                       let bumped_fee = bumped_feerate * (predicted_weight as u64) / 1000;
+                       let bumped_fee = bumped_feerate * predicted_weight / 1000;
                        if input_amounts <= bumped_fee {
                                log_warn!(logger, "Can't 25% bump new claiming tx, amount {} is too small", input_amounts);
                                return None;
@@ -1171,8 +1172,8 @@ where
                return Some((new_fee, new_feerate));
        }
 
-       let previous_fee = previous_feerate * (predicted_weight as u64) / 1000;
-       let min_relay_fee = MIN_RELAY_FEE_SAT_PER_1000_WEIGHT * (predicted_weight as u64) / 1000;
+       let previous_fee = previous_feerate * predicted_weight / 1000;
+       let min_relay_fee = MIN_RELAY_FEE_SAT_PER_1000_WEIGHT * predicted_weight / 1000;
        // BIP 125 Opt-in Full Replace-by-Fee Signaling
        //      * 3. The replacement transaction pays an absolute fee of at least the sum paid by the original transactions.
        //      * 4. The replacement transaction must also pay for its own bandwidth at or above the rate set by the node's minimum relay fee setting.
@@ -1181,7 +1182,7 @@ where
        } else {
                new_fee
        };
-       Some((new_fee, new_fee * 1000 / (predicted_weight as u64)))
+       Some((new_fee, new_fee * 1000 / predicted_weight))
 }
 
 #[cfg(test)]
@@ -1192,7 +1193,7 @@ mod tests {
        use crate::ln::{PaymentPreimage, PaymentHash};
 
        use bitcoin::blockdata::constants::WITNESS_SCALE_FACTOR;
-       use bitcoin::blockdata::script::Script;
+       use bitcoin::blockdata::script::ScriptBuf;
        use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint;
 
        use bitcoin::hashes::hex::FromHex;
@@ -1201,10 +1202,12 @@ mod tests {
        use bitcoin::secp256k1::Secp256k1;
        use crate::ln::features::ChannelTypeFeatures;
 
+       use std::str::FromStr;
+
        macro_rules! dumb_revk_output {
                ($secp_ctx: expr, $is_counterparty_balance_on_anchors: expr) => {
                        {
-                               let dumb_scalar = SecretKey::from_slice(&hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap();
+                               let dumb_scalar = SecretKey::from_slice(&<Vec<u8>>::from_hex("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap();
                                let dumb_point = PublicKey::from_secret_key(&$secp_ctx, &dumb_scalar);
                                PackageSolvingData::RevokedOutput(RevokedOutput::build(dumb_point, dumb_point, dumb_point, dumb_scalar, 0, 0, $is_counterparty_balance_on_anchors))
                        }
@@ -1214,7 +1217,7 @@ mod tests {
        macro_rules! dumb_counterparty_output {
                ($secp_ctx: expr, $amt: expr, $opt_anchors: expr) => {
                        {
-                               let dumb_scalar = SecretKey::from_slice(&hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap();
+                               let dumb_scalar = SecretKey::from_slice(&<Vec<u8>>::from_hex("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap();
                                let dumb_point = PublicKey::from_secret_key(&$secp_ctx, &dumb_scalar);
                                let hash = PaymentHash([1; 32]);
                                let htlc = HTLCOutputInCommitment { offered: true, amount_msat: $amt, cltv_expiry: 0, payment_hash: hash, transaction_output_index: None };
@@ -1226,7 +1229,7 @@ mod tests {
        macro_rules! dumb_counterparty_offered_output {
                ($secp_ctx: expr, $amt: expr, $opt_anchors: expr) => {
                        {
-                               let dumb_scalar = SecretKey::from_slice(&hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap();
+                               let dumb_scalar = SecretKey::from_slice(&<Vec<u8>>::from_hex("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap();
                                let dumb_point = PublicKey::from_secret_key(&$secp_ctx, &dumb_scalar);
                                let hash = PaymentHash([1; 32]);
                                let preimage = PaymentPreimage([2;32]);
@@ -1248,7 +1251,7 @@ mod tests {
        #[test]
        #[should_panic]
        fn test_package_differing_heights() {
-               let txid = Txid::from_hex("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
+               let txid = Txid::from_str("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
                let secp_ctx = Secp256k1::new();
                let revk_outp = dumb_revk_output!(secp_ctx, false);
 
@@ -1260,7 +1263,7 @@ mod tests {
        #[test]
        #[should_panic]
        fn test_package_untractable_merge_to() {
-               let txid = Txid::from_hex("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
+               let txid = Txid::from_str("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
                let secp_ctx = Secp256k1::new();
                let revk_outp = dumb_revk_output!(secp_ctx, false);
                let htlc_outp = dumb_htlc_output!();
@@ -1273,7 +1276,7 @@ mod tests {
        #[test]
        #[should_panic]
        fn test_package_untractable_merge_from() {
-               let txid = Txid::from_hex("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
+               let txid = Txid::from_str("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
                let secp_ctx = Secp256k1::new();
                let htlc_outp = dumb_htlc_output!();
                let revk_outp = dumb_revk_output!(secp_ctx, false);
@@ -1286,7 +1289,7 @@ mod tests {
        #[test]
        #[should_panic]
        fn test_package_noaggregation_to() {
-               let txid = Txid::from_hex("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
+               let txid = Txid::from_str("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
                let secp_ctx = Secp256k1::new();
                let revk_outp = dumb_revk_output!(secp_ctx, false);
                let revk_outp_counterparty_balance = dumb_revk_output!(secp_ctx, true);
@@ -1299,7 +1302,7 @@ mod tests {
        #[test]
        #[should_panic]
        fn test_package_noaggregation_from() {
-               let txid = Txid::from_hex("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
+               let txid = Txid::from_str("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
                let secp_ctx = Secp256k1::new();
                let revk_outp = dumb_revk_output!(secp_ctx, false);
                let revk_outp_counterparty_balance = dumb_revk_output!(secp_ctx, true);
@@ -1312,7 +1315,7 @@ mod tests {
        #[test]
        #[should_panic]
        fn test_package_empty() {
-               let txid = Txid::from_hex("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
+               let txid = Txid::from_str("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
                let secp_ctx = Secp256k1::new();
                let revk_outp = dumb_revk_output!(secp_ctx, false);
 
@@ -1325,7 +1328,7 @@ mod tests {
        #[test]
        #[should_panic]
        fn test_package_differing_categories() {
-               let txid = Txid::from_hex("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
+               let txid = Txid::from_str("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
                let secp_ctx = Secp256k1::new();
                let revk_outp = dumb_revk_output!(secp_ctx, false);
                let counterparty_outp = dumb_counterparty_output!(secp_ctx, 0, ChannelTypeFeatures::only_static_remote_key());
@@ -1337,7 +1340,7 @@ mod tests {
 
        #[test]
        fn test_package_split_malleable() {
-               let txid = Txid::from_hex("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
+               let txid = Txid::from_str("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
                let secp_ctx = Secp256k1::new();
                let revk_outp_one = dumb_revk_output!(secp_ctx, false);
                let revk_outp_two = dumb_revk_output!(secp_ctx, false);
@@ -1365,7 +1368,7 @@ mod tests {
 
        #[test]
        fn test_package_split_untractable() {
-               let txid = Txid::from_hex("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
+               let txid = Txid::from_str("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
                let htlc_outp_one = dumb_htlc_output!();
 
                let mut package_one = PackageTemplate::build_package(txid, 0, htlc_outp_one, 1000, 100);
@@ -1375,7 +1378,7 @@ mod tests {
 
        #[test]
        fn test_package_timer() {
-               let txid = Txid::from_hex("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
+               let txid = Txid::from_str("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
                let secp_ctx = Secp256k1::new();
                let revk_outp = dumb_revk_output!(secp_ctx, false);
 
@@ -1387,7 +1390,7 @@ mod tests {
 
        #[test]
        fn test_package_amounts() {
-               let txid = Txid::from_hex("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
+               let txid = Txid::from_str("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
                let secp_ctx = Secp256k1::new();
                let counterparty_outp = dumb_counterparty_output!(secp_ctx, 1_000_000, ChannelTypeFeatures::only_static_remote_key());
 
@@ -1397,23 +1400,23 @@ mod tests {
 
        #[test]
        fn test_package_weight() {
-               let txid = Txid::from_hex("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
+               let txid = Txid::from_str("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap();
                let secp_ctx = Secp256k1::new();
 
                // (nVersion (4) + nLocktime (4) + count_tx_in (1) + prevout (36) + sequence (4) + script_length (1) + count_tx_out (1) + value (8) + var_int (1)) * WITNESS_SCALE_FACTOR + witness marker (2)
-               let weight_sans_output = (4 + 4 + 1 + 36 + 4 + 1 + 1 + 8 + 1) * WITNESS_SCALE_FACTOR + 2;
+               let weight_sans_output = (4 + 4 + 1 + 36 + 4 + 1 + 1 + 8 + 1) * WITNESS_SCALE_FACTOR as u64 + 2;
 
                {
                        let revk_outp = dumb_revk_output!(secp_ctx, false);
                        let package = PackageTemplate::build_package(txid, 0, revk_outp, 0, 100);
-                       assert_eq!(package.package_weight(&Script::new()),  weight_sans_output + WEIGHT_REVOKED_OUTPUT as usize);
+                       assert_eq!(package.package_weight(&ScriptBuf::new()),  weight_sans_output + WEIGHT_REVOKED_OUTPUT);
                }
 
                {
                        for channel_type_features in [ChannelTypeFeatures::only_static_remote_key(), ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies()].iter() {
                                let counterparty_outp = dumb_counterparty_output!(secp_ctx, 1_000_000, channel_type_features.clone());
                                let package = PackageTemplate::build_package(txid, 0, counterparty_outp, 1000, 100);
-                               assert_eq!(package.package_weight(&Script::new()), weight_sans_output + weight_received_htlc(channel_type_features) as usize);
+                               assert_eq!(package.package_weight(&ScriptBuf::new()), weight_sans_output + weight_received_htlc(channel_type_features));
                        }
                }
 
@@ -1421,7 +1424,7 @@ mod tests {
                        for channel_type_features in [ChannelTypeFeatures::only_static_remote_key(), ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies()].iter() {
                                let counterparty_outp = dumb_counterparty_offered_output!(secp_ctx, 1_000_000, channel_type_features.clone());
                                let package = PackageTemplate::build_package(txid, 0, counterparty_outp, 1000, 100);
-                               assert_eq!(package.package_weight(&Script::new()), weight_sans_output + weight_offered_htlc(channel_type_features) as usize);
+                               assert_eq!(package.package_weight(&ScriptBuf::new()), weight_sans_output + weight_offered_htlc(channel_type_features));
                        }
                }
        }
index 39a0a5449ac7cf1a4f5dc636363b0ad9c0245c6f..5bef97792d3944252837f67d8e7ebefe8a797e57 100644 (file)
@@ -60,7 +60,7 @@ pub struct OutPoint {
 impl OutPoint {
        /// Convert an `OutPoint` to a lightning channel id.
        pub fn to_channel_id(&self) -> ChannelId {
-               ChannelId::v1_from_funding_txid(&self.txid.as_inner(), self.index)
+               ChannelId::v1_from_funding_txid(self.txid.as_byte_array(), self.index)
        }
 
        /// Converts this OutPoint into the OutPoint field as used by rust-bitcoin
@@ -89,19 +89,18 @@ mod tests {
 
        use bitcoin::blockdata::transaction::Transaction;
        use bitcoin::consensus::encode;
-
-       use hex;
+       use bitcoin::hashes::hex::FromHex;
 
        #[test]
        fn test_channel_id_calculation() {
-               let tx: Transaction = encode::deserialize(&hex::decode("020000000001010e0adef48412e4361325ac1c6e36411299ab09d4f083b9d8ddb55fbc06e1b0c00000000000feffffff0220a1070000000000220020f81d95e040bd0a493e38bae27bff52fe2bb58b93b293eb579c01c31b05c5af1dc072cfee54a3000016001434b1d6211af5551905dc2642d05f5b04d25a8fe80247304402207f570e3f0de50546aad25a872e3df059d277e776dda4269fa0d2cc8c2ee6ec9a022054e7fae5ca94d47534c86705857c24ceea3ad51c69dd6051c5850304880fc43a012103cb11a1bacc223d98d91f1946c6752e358a5eb1a1c983b3e6fb15378f453b76bd00000000").unwrap()[..]).unwrap();
+               let tx: Transaction = encode::deserialize(&<Vec<u8>>::from_hex("020000000001010e0adef48412e4361325ac1c6e36411299ab09d4f083b9d8ddb55fbc06e1b0c00000000000feffffff0220a1070000000000220020f81d95e040bd0a493e38bae27bff52fe2bb58b93b293eb579c01c31b05c5af1dc072cfee54a3000016001434b1d6211af5551905dc2642d05f5b04d25a8fe80247304402207f570e3f0de50546aad25a872e3df059d277e776dda4269fa0d2cc8c2ee6ec9a022054e7fae5ca94d47534c86705857c24ceea3ad51c69dd6051c5850304880fc43a012103cb11a1bacc223d98d91f1946c6752e358a5eb1a1c983b3e6fb15378f453b76bd00000000").unwrap()[..]).unwrap();
                assert_eq!(&OutPoint {
                        txid: tx.txid(),
                        index: 0
-               }.to_channel_id().0[..], &hex::decode("3e88dd7165faf7be58b3c5bb2c9c452aebef682807ea57080f62e6f6e113c25e").unwrap()[..]);
+               }.to_channel_id().0[..], &<Vec<u8>>::from_hex("3e88dd7165faf7be58b3c5bb2c9c452aebef682807ea57080f62e6f6e113c25e").unwrap()[..]);
                assert_eq!(&OutPoint {
                        txid: tx.txid(),
                        index: 1
-               }.to_channel_id().0[..], &hex::decode("3e88dd7165faf7be58b3c5bb2c9c452aebef682807ea57080f62e6f6e113c25f").unwrap()[..]);
+               }.to_channel_id().0[..], &<Vec<u8>>::from_hex("3e88dd7165faf7be58b3c5bb2c9c452aebef682807ea57080f62e6f6e113c25f").unwrap()[..]);
        }
 }
index 1fd533d2fd27f1e9637096d8de287139456b3b9d..7c6cc6c6a5688181b6465fbb7f775c255aa0261f 100644 (file)
@@ -31,8 +31,9 @@ use crate::sign::{
 use crate::sync::Mutex;
 use crate::util::logger::Logger;
 
-use bitcoin::{OutPoint, PackedLockTime, PubkeyHash, Sequence, Script, Transaction, TxIn, TxOut, Witness, WPubkeyHash};
+use bitcoin::{OutPoint, PubkeyHash, Sequence, ScriptBuf, Transaction, TxIn, TxOut, Witness, WPubkeyHash};
 use bitcoin::blockdata::constants::WITNESS_SCALE_FACTOR;
+use bitcoin::blockdata::locktime::absolute::LockTime;
 use bitcoin::consensus::Encodable;
 use bitcoin::secp256k1;
 use bitcoin::secp256k1::Secp256k1;
@@ -69,14 +70,14 @@ impl AnchorDescriptor {
        pub fn unsigned_tx_input(&self) -> TxIn {
                TxIn {
                        previous_output: self.outpoint.clone(),
-                       script_sig: Script::new(),
+                       script_sig: ScriptBuf::new(),
                        sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
                        witness: Witness::new(),
                }
        }
 
        /// Returns the witness script of the anchor output in the commitment transaction.
-       pub fn witness_script(&self) -> Script {
+       pub fn witness_script(&self) -> ScriptBuf {
                let channel_params = self.channel_derivation_parameters.transaction_parameters.as_holder_broadcastable();
                chan_utils::get_anchor_redeemscript(&channel_params.broadcaster_pubkeys().funding_pubkey)
        }
@@ -211,7 +212,7 @@ pub enum BumpTransactionEvent {
                /// by the same transaction.
                htlc_descriptors: Vec<HTLCDescriptor>,
                /// The locktime required for the resulting HTLC transaction.
-               tx_lock_time: PackedLockTime,
+               tx_lock_time: LockTime,
        },
 }
 
@@ -256,7 +257,7 @@ impl Utxo {
                        outpoint,
                        output: TxOut {
                                value,
-                               script_pubkey: Script::new_p2pkh(pubkey_hash),
+                               script_pubkey: ScriptBuf::new_p2pkh(pubkey_hash),
                        },
                        satisfaction_weight: script_sig_size * WITNESS_SCALE_FACTOR as u64 + 1 /* empty witness */,
                }
@@ -272,7 +273,7 @@ impl Utxo {
                        outpoint,
                        output: TxOut {
                                value,
-                               script_pubkey: Script::new_p2sh(&Script::new_v0_p2wpkh(pubkey_hash).script_hash()),
+                               script_pubkey: ScriptBuf::new_p2sh(&ScriptBuf::new_v0_p2wpkh(pubkey_hash).script_hash()),
                        },
                        satisfaction_weight: script_sig_size * WITNESS_SCALE_FACTOR as u64 + P2WPKH_WITNESS_WEIGHT,
                }
@@ -284,7 +285,7 @@ impl Utxo {
                        outpoint,
                        output: TxOut {
                                value,
-                               script_pubkey: Script::new_v0_p2wpkh(pubkey_hash),
+                               script_pubkey: ScriptBuf::new_v0_p2wpkh(pubkey_hash),
                        },
                        satisfaction_weight: EMPTY_SCRIPT_SIG_WEIGHT + P2WPKH_WITNESS_WEIGHT,
                }
@@ -352,7 +353,7 @@ pub trait WalletSource {
        fn list_confirmed_utxos(&self) -> Result<Vec<Utxo>, ()>;
        /// Returns a script to use for change above dust resulting from a successful coin selection
        /// attempt.
-       fn get_change_script(&self) -> Result<Script, ()>;
+       fn get_change_script(&self) -> Result<ScriptBuf, ()>;
        /// Signs and provides the full [`TxIn::script_sig`] and [`TxIn::witness`] for all inputs within
        /// the transaction known to the wallet (i.e., any provided via
        /// [`WalletSource::list_confirmed_utxos`]).
@@ -408,7 +409,7 @@ where
                                }
                        }
                        let fee_to_spend_utxo = fee_for_weight(
-                               target_feerate_sat_per_1000_weight, BASE_INPUT_WEIGHT as u64 + utxo.satisfaction_weight,
+                               target_feerate_sat_per_1000_weight, BASE_INPUT_WEIGHT + utxo.satisfaction_weight,
                        );
                        let should_spend = if tolerate_high_network_feerates {
                                utxo.output.value > fee_to_spend_utxo
@@ -552,7 +553,7 @@ where
                for utxo in coin_selection.confirmed_utxos.drain(..) {
                        tx.input.push(TxIn {
                                previous_output: utxo.outpoint,
-                               script_sig: Script::new(),
+                               script_sig: ScriptBuf::new(),
                                sequence: Sequence::ZERO,
                                witness: Witness::new(),
                        });
@@ -567,7 +568,7 @@ where
                        log_debug!(self.logger, "Including dummy OP_RETURN output since an output is needed and a change output was not provided");
                        tx.output.push(TxOut {
                                value: 0,
-                               script_pubkey: Script::new_op_return(&[]),
+                               script_pubkey: ScriptBuf::new_op_return(&[]),
                        });
                }
        }
@@ -587,7 +588,7 @@ where
                let must_spend = vec![Input {
                        outpoint: anchor_descriptor.outpoint,
                        previous_utxo: anchor_utxo,
-                       satisfaction_weight: commitment_tx.weight() as u64 + ANCHOR_INPUT_WITNESS_WEIGHT + EMPTY_SCRIPT_SIG_WEIGHT,
+                       satisfaction_weight: commitment_tx.weight().to_wu() + ANCHOR_INPUT_WITNESS_WEIGHT + EMPTY_SCRIPT_SIG_WEIGHT,
                }];
                #[cfg(debug_assertions)]
                let must_spend_amount = must_spend.iter().map(|input| input.previous_utxo.value).sum::<u64>();
@@ -600,7 +601,7 @@ where
 
                let mut anchor_tx = Transaction {
                        version: 2,
-                       lock_time: PackedLockTime::ZERO, // TODO: Use next best height.
+                       lock_time: LockTime::ZERO, // TODO: Use next best height.
                        input: vec![anchor_descriptor.unsigned_tx_input()],
                        output: vec![],
                };
@@ -617,7 +618,7 @@ where
 
                debug_assert_eq!(anchor_tx.output.len(), 1);
                #[cfg(debug_assertions)]
-               let unsigned_tx_weight = anchor_tx.weight() as u64 - (anchor_tx.input.len() as u64 * EMPTY_SCRIPT_SIG_WEIGHT);
+               let unsigned_tx_weight = anchor_tx.weight().to_wu() - (anchor_tx.input.len() as u64 * EMPTY_SCRIPT_SIG_WEIGHT);
 
                log_debug!(self.logger, "Signing anchor transaction {}", anchor_txid);
                anchor_tx = self.utxo_source.sign_tx(anchor_tx)?;
@@ -627,7 +628,7 @@ where
                anchor_tx.input[0].witness = anchor_descriptor.tx_input_witness(&anchor_sig);
 
                #[cfg(debug_assertions)] {
-                       let signed_tx_weight = anchor_tx.weight() as u64;
+                       let signed_tx_weight = anchor_tx.weight().to_wu();
                        let expected_signed_tx_weight = unsigned_tx_weight + total_satisfaction_weight;
                        // Our estimate should be within a 1% error margin of the actual weight and we should
                        // never underestimate.
@@ -635,7 +636,7 @@ where
                                expected_signed_tx_weight - (expected_signed_tx_weight / 100) <= signed_tx_weight);
 
                        let expected_package_fee = fee_for_weight(package_target_feerate_sat_per_1000_weight,
-                               signed_tx_weight + commitment_tx.weight() as u64);
+                               signed_tx_weight + commitment_tx.weight().to_wu());
                        let package_fee = total_input_amount -
                                anchor_tx.output.iter().map(|output| output.value).sum::<u64>();
                        // Our fee should be within a 5% error margin of the expected fee based on the
@@ -655,7 +656,7 @@ where
        /// fully-signed, fee-bumped HTLC transaction that is broadcast to the network.
        fn handle_htlc_resolution(
                &self, claim_id: ClaimId, target_feerate_sat_per_1000_weight: u32,
-               htlc_descriptors: &[HTLCDescriptor], tx_lock_time: PackedLockTime,
+               htlc_descriptors: &[HTLCDescriptor], tx_lock_time: LockTime,
        ) -> Result<(), ()> {
                let mut htlc_tx = Transaction {
                        version: 2,
@@ -703,7 +704,7 @@ where
                self.process_coin_selection(&mut htlc_tx, coin_selection);
 
                #[cfg(debug_assertions)]
-               let unsigned_tx_weight = htlc_tx.weight() as u64 - (htlc_tx.input.len() as u64 * EMPTY_SCRIPT_SIG_WEIGHT);
+               let unsigned_tx_weight = htlc_tx.weight().to_wu() - (htlc_tx.input.len() as u64 * EMPTY_SCRIPT_SIG_WEIGHT);
 
                log_debug!(self.logger, "Signing HTLC transaction {}", htlc_tx.txid());
                htlc_tx = self.utxo_source.sign_tx(htlc_tx)?;
@@ -718,7 +719,7 @@ where
                }
 
                #[cfg(debug_assertions)] {
-                       let signed_tx_weight = htlc_tx.weight() as u64;
+                       let signed_tx_weight = htlc_tx.weight().to_wu();
                        let expected_signed_tx_weight = unsigned_tx_weight + total_satisfaction_weight;
                        // Our estimate should be within a 1% error margin of the actual weight and we should
                        // never underestimate.
index 4fbb2c9000cd5e9a8e36aee5565f8e48a64ee926..adbc7faf7e0f9d0acf1fa3349495733669d41193 100644 (file)
@@ -30,8 +30,9 @@ use crate::util::ser::{BigSize, FixedLengthReader, Writeable, Writer, MaybeReada
 use crate::util::string::UntrustedString;
 use crate::routing::router::{BlindedTail, Path, RouteHop, RouteParameters};
 
-use bitcoin::{PackedLockTime, Transaction, OutPoint};
-use bitcoin::blockdata::script::Script;
+use bitcoin::{Transaction, OutPoint};
+use bitcoin::blockdata::locktime::absolute::LockTime;
+use bitcoin::blockdata::script::ScriptBuf;
 use bitcoin::hashes::Hash;
 use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::secp256k1::PublicKey;
@@ -384,7 +385,7 @@ pub enum Event {
                /// The value, in satoshis, that the output should have.
                channel_value_satoshis: u64,
                /// The script which should be used in the transaction output.
-               output_script: Script,
+               output_script: ScriptBuf,
                /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
                /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
                /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
@@ -1253,7 +1254,7 @@ impl MaybeReadable for Event {
                                                (5, fee_paid_msat, option),
                                        });
                                        if payment_hash.is_none() {
-                                               payment_hash = Some(PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner()));
+                                               payment_hash = Some(PaymentHash(Sha256::hash(&payment_preimage.0[..]).to_byte_array()));
                                        }
                                        Ok(Some(Event::PaymentSent {
                                                payment_id,
@@ -1395,7 +1396,7 @@ impl MaybeReadable for Event {
                        11u8 => {
                                let f = || {
                                        let mut channel_id = ChannelId::new_zero();
-                                       let mut transaction = Transaction{ version: 2, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: Vec::new() };
+                                       let mut transaction = Transaction{ version: 2, lock_time: LockTime::ZERO, input: Vec::new(), output: Vec::new() };
                                        read_tlv_fields!(reader, {
                                                (0, channel_id, required),
                                                (2, transaction, required),
index cf0a04aab081f458b586e1c9f87c0ab7cc305e55..df1bb1a2a2f2ef807f55e72f9bb50f96380e17c7 100644 (file)
@@ -66,7 +66,7 @@ extern crate bitcoin;
 #[cfg(any(test, feature = "std"))]
 extern crate core;
 
-#[cfg(any(test, feature = "_test_utils"))] extern crate hex;
+extern crate hex;
 #[cfg(any(test, feature = "_test_utils"))] extern crate regex;
 
 #[cfg(not(feature = "std"))] extern crate core2;
index 1c068025b8f0853340dfc54e89ba347411cdf20a..8dc31115f96d7dc93cdbc6d9b0cf5cd4e8d0c366 100644 (file)
 //! Various utilities for building scripts and deriving keys related to channels. These are
 //! largely of interest for those implementing the traits on [`crate::sign`] by hand.
 
-use bitcoin::blockdata::script::{Script,Builder};
+use bitcoin::blockdata::script::{Script, ScriptBuf, Builder};
 use bitcoin::blockdata::opcodes;
-use bitcoin::blockdata::transaction::{TxIn,TxOut,OutPoint,Transaction, EcdsaSighashType};
-use bitcoin::util::sighash;
-use bitcoin::util::address::Payload;
+use bitcoin::blockdata::transaction::{TxIn,TxOut,OutPoint,Transaction};
+use bitcoin::sighash;
+use bitcoin::sighash::EcdsaSighashType;
+use bitcoin::address::Payload;
 
 use bitcoin::hashes::{Hash, HashEngine};
 use bitcoin::hashes::sha256::Hash as Sha256;
@@ -29,9 +30,10 @@ use crate::ln::msgs::DecodeError;
 use crate::util::ser::{Readable, RequiredWrapper, Writeable, Writer};
 use crate::util::transaction_utils;
 
+use bitcoin::blockdata::locktime::absolute::LockTime;
 use bitcoin::secp256k1::{SecretKey, PublicKey, Scalar};
 use bitcoin::secp256k1::{Secp256k1, ecdsa::Signature, Message};
-use bitcoin::{PackedLockTime, secp256k1, Sequence, Witness};
+use bitcoin::{secp256k1, Sequence, Witness};
 use bitcoin::PublicKey as BitcoinPublicKey;
 
 use crate::io;
@@ -174,19 +176,19 @@ pub fn build_commitment_secret(commitment_seed: &[u8; 32], idx: u64) -> [u8; 32]
                let bitpos = 47 - i;
                if idx & (1 << bitpos) == (1 << bitpos) {
                        res[bitpos / 8] ^= 1 << (bitpos & 7);
-                       res = Sha256::hash(&res).into_inner();
+                       res = Sha256::hash(&res).to_byte_array();
                }
        }
        res
 }
 
 /// Build a closing transaction
-pub fn build_closing_transaction(to_holder_value_sat: u64, to_counterparty_value_sat: u64, to_holder_script: Script, to_counterparty_script: Script, funding_outpoint: OutPoint) -> Transaction {
+pub fn build_closing_transaction(to_holder_value_sat: u64, to_counterparty_value_sat: u64, to_holder_script: ScriptBuf, to_counterparty_script: ScriptBuf, funding_outpoint: OutPoint) -> Transaction {
        let txins = {
                let mut ins: Vec<TxIn> = Vec::new();
                ins.push(TxIn {
                        previous_output: funding_outpoint,
-                       script_sig: Script::new(),
+                       script_sig: ScriptBuf::new(),
                        sequence: Sequence::MAX,
                        witness: Witness::new(),
                });
@@ -218,7 +220,7 @@ pub fn build_closing_transaction(to_holder_value_sat: u64, to_counterparty_value
 
        Transaction {
                version: 2,
-               lock_time: PackedLockTime::ZERO,
+               lock_time: LockTime::ZERO,
                input: txins,
                output: outputs,
        }
@@ -282,7 +284,7 @@ impl CounterpartyCommitmentSecrets {
                        let bitpos = bits - 1 - i;
                        if idx & (1 << bitpos) == (1 << bitpos) {
                                res[(bitpos / 8) as usize] ^= 1 << (bitpos & 7);
-                               res = Sha256::hash(&res).into_inner();
+                               res = Sha256::hash(&res).to_byte_array();
                        }
                }
                res
@@ -346,7 +348,7 @@ pub fn derive_private_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1<T>, per_co
        let mut sha = Sha256::engine();
        sha.input(&per_commitment_point.serialize());
        sha.input(&PublicKey::from_secret_key(&secp_ctx, &base_secret).serialize());
-       let res = Sha256::from_engine(sha).into_inner();
+       let res = Sha256::from_engine(sha).to_byte_array();
 
        base_secret.clone().add_tweak(&Scalar::from_be_bytes(res).unwrap())
                .expect("Addition only fails if the tweak is the inverse of the key. This is not possible when the tweak contains the hash of the key.")
@@ -359,7 +361,7 @@ pub fn derive_public_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1<T>, per_com
        let mut sha = Sha256::engine();
        sha.input(&per_commitment_point.serialize());
        sha.input(&base_point.serialize());
-       let res = Sha256::from_engine(sha).into_inner();
+       let res = Sha256::from_engine(sha).to_byte_array();
 
        let hashkey = PublicKey::from_secret_key(&secp_ctx,
                &SecretKey::from_slice(&res).expect("Hashes should always be valid keys unless SHA-256 is broken"));
@@ -384,14 +386,14 @@ pub fn derive_private_revocation_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1
                sha.input(&countersignatory_revocation_base_point.serialize());
                sha.input(&per_commitment_point.serialize());
 
-               Sha256::from_engine(sha).into_inner()
+               Sha256::from_engine(sha).to_byte_array()
        };
        let commit_append_rev_hash_key = {
                let mut sha = Sha256::engine();
                sha.input(&per_commitment_point.serialize());
                sha.input(&countersignatory_revocation_base_point.serialize());
 
-               Sha256::from_engine(sha).into_inner()
+               Sha256::from_engine(sha).to_byte_array()
        };
 
        let countersignatory_contrib = countersignatory_revocation_base_secret.clone().mul_tweak(&Scalar::from_be_bytes(rev_append_commit_hash_key).unwrap())
@@ -421,14 +423,14 @@ pub fn derive_public_revocation_key<T: secp256k1::Verification>(secp_ctx: &Secp2
                sha.input(&countersignatory_revocation_base_point.serialize());
                sha.input(&per_commitment_point.serialize());
 
-               Sha256::from_engine(sha).into_inner()
+               Sha256::from_engine(sha).to_byte_array()
        };
        let commit_append_rev_hash_key = {
                let mut sha = Sha256::engine();
                sha.input(&per_commitment_point.serialize());
                sha.input(&countersignatory_revocation_base_point.serialize());
 
-               Sha256::from_engine(sha).into_inner()
+               Sha256::from_engine(sha).to_byte_array()
        };
 
        let countersignatory_contrib = countersignatory_revocation_base_point.clone().mul_tweak(&secp_ctx, &Scalar::from_be_bytes(rev_append_commit_hash_key).unwrap())
@@ -541,7 +543,7 @@ pub const REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH: usize = 6 + 3 + 34*2;
 /// A script either spendable by the revocation
 /// key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.
 /// Encumbering a `to_holder` output on a commitment transaction or 2nd-stage HTLC transactions.
-pub fn get_revokeable_redeemscript(revocation_key: &PublicKey, contest_delay: u16, broadcaster_delayed_payment_key: &PublicKey) -> Script {
+pub fn get_revokeable_redeemscript(revocation_key: &PublicKey, contest_delay: u16, broadcaster_delayed_payment_key: &PublicKey) -> ScriptBuf {
        let res = Builder::new().push_opcode(opcodes::all::OP_IF)
                      .push_slice(&revocation_key.serialize())
                      .push_opcode(opcodes::all::OP_ELSE)
@@ -558,11 +560,11 @@ pub fn get_revokeable_redeemscript(revocation_key: &PublicKey, contest_delay: u1
 
 /// Returns the script for the counterparty's output on a holder's commitment transaction based on
 /// the channel type.
-pub fn get_counterparty_payment_script(channel_type_features: &ChannelTypeFeatures, payment_key: &PublicKey) -> Script {
+pub fn get_counterparty_payment_script(channel_type_features: &ChannelTypeFeatures, payment_key: &PublicKey) -> ScriptBuf {
        if channel_type_features.supports_anchors_zero_fee_htlc_tx() {
                get_to_countersignatory_with_anchors_redeemscript(payment_key).to_v0_p2wsh()
        } else {
-               Script::new_v0_p2wpkh(&WPubkeyHash::hash(&payment_key.serialize()))
+               ScriptBuf::new_v0_p2wpkh(&WPubkeyHash::hash(&payment_key.serialize()))
        }
 }
 
@@ -596,17 +598,17 @@ impl_writeable_tlv_based!(HTLCOutputInCommitment, {
 });
 
 #[inline]
-pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommitment, channel_type_features: &ChannelTypeFeatures, broadcaster_htlc_key: &PublicKey, countersignatory_htlc_key: &PublicKey, revocation_key: &PublicKey) -> Script {
-       let payment_hash160 = Ripemd160::hash(&htlc.payment_hash.0[..]).into_inner();
+pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommitment, channel_type_features: &ChannelTypeFeatures, broadcaster_htlc_key: &PublicKey, countersignatory_htlc_key: &PublicKey, revocation_key: &PublicKey) -> ScriptBuf {
+       let payment_hash160 = Ripemd160::hash(&htlc.payment_hash.0[..]).to_byte_array();
        if htlc.offered {
                let mut bldr = Builder::new().push_opcode(opcodes::all::OP_DUP)
                              .push_opcode(opcodes::all::OP_HASH160)
-                             .push_slice(&PubkeyHash::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)
                              .push_opcode(opcodes::all::OP_ELSE)
-                             .push_slice(&countersignatory_htlc_key.serialize()[..])
+                             .push_slice(countersignatory_htlc_key.serialize())
                              .push_opcode(opcodes::all::OP_SWAP)
                              .push_opcode(opcodes::all::OP_SIZE)
                              .push_int(32)
@@ -615,7 +617,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
                              .push_opcode(opcodes::all::OP_DROP)
                              .push_int(2)
                              .push_opcode(opcodes::all::OP_SWAP)
-                             .push_slice(&broadcaster_htlc_key.serialize()[..])
+                             .push_slice(broadcaster_htlc_key.serialize())
                              .push_int(2)
                              .push_opcode(opcodes::all::OP_CHECKMULTISIG)
                              .push_opcode(opcodes::all::OP_ELSE)
@@ -634,12 +636,12 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
        } else {
                        let mut bldr = Builder::new().push_opcode(opcodes::all::OP_DUP)
                              .push_opcode(opcodes::all::OP_HASH160)
-                             .push_slice(&PubkeyHash::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)
                              .push_opcode(opcodes::all::OP_ELSE)
-                             .push_slice(&countersignatory_htlc_key.serialize()[..])
+                             .push_slice(countersignatory_htlc_key.serialize())
                              .push_opcode(opcodes::all::OP_SWAP)
                              .push_opcode(opcodes::all::OP_SIZE)
                              .push_int(32)
@@ -650,7 +652,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
                              .push_opcode(opcodes::all::OP_EQUALVERIFY)
                              .push_int(2)
                              .push_opcode(opcodes::all::OP_SWAP)
-                             .push_slice(&broadcaster_htlc_key.serialize()[..])
+                             .push_slice(broadcaster_htlc_key.serialize())
                              .push_int(2)
                              .push_opcode(opcodes::all::OP_CHECKMULTISIG)
                              .push_opcode(opcodes::all::OP_ELSE)
@@ -673,20 +675,20 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
 /// Gets the witness redeemscript for an HTLC output in a commitment transaction. Note that htlc
 /// does not need to have its previous_output_index filled.
 #[inline]
-pub fn get_htlc_redeemscript(htlc: &HTLCOutputInCommitment, channel_type_features: &ChannelTypeFeatures, keys: &TxCreationKeys) -> Script {
+pub fn get_htlc_redeemscript(htlc: &HTLCOutputInCommitment, channel_type_features: &ChannelTypeFeatures, keys: &TxCreationKeys) -> ScriptBuf {
        get_htlc_redeemscript_with_explicit_keys(htlc, channel_type_features, &keys.broadcaster_htlc_key, &keys.countersignatory_htlc_key, &keys.revocation_key)
 }
 
 /// Gets the redeemscript for a funding output from the two funding public keys.
 /// Note that the order of funding public keys does not matter.
-pub fn make_funding_redeemscript(broadcaster: &PublicKey, countersignatory: &PublicKey) -> Script {
+pub fn make_funding_redeemscript(broadcaster: &PublicKey, countersignatory: &PublicKey) -> ScriptBuf {
        let broadcaster_funding_key = broadcaster.serialize();
        let countersignatory_funding_key = countersignatory.serialize();
 
        make_funding_redeemscript_from_slices(&broadcaster_funding_key, &countersignatory_funding_key)
 }
 
-pub(crate) fn make_funding_redeemscript_from_slices(broadcaster_funding_key: &[u8], countersignatory_funding_key: &[u8]) -> Script {
+pub(crate) fn make_funding_redeemscript_from_slices(broadcaster_funding_key: &[u8; 33], countersignatory_funding_key: &[u8; 33]) -> ScriptBuf {
        let builder = Builder::new().push_opcode(opcodes::all::OP_PUSHNUM_2);
        if broadcaster_funding_key[..] < countersignatory_funding_key[..] {
                builder.push_slice(broadcaster_funding_key)
@@ -716,7 +718,7 @@ pub fn build_htlc_transaction(commitment_txid: &Txid, feerate_per_kw: u32, conte
 
        Transaction {
                version: 2,
-               lock_time: PackedLockTime(if htlc.offered { htlc.cltv_expiry } else { 0 }),
+               lock_time: LockTime::from_consensus(if htlc.offered { htlc.cltv_expiry } else { 0 }),
                input: txins,
                output: txouts,
        }
@@ -728,7 +730,7 @@ pub(crate) fn build_htlc_input(commitment_txid: &Txid, htlc: &HTLCOutputInCommit
                        txid: commitment_txid.clone(),
                        vout: htlc.transaction_output_index.expect("Can't build an HTLC transaction for a dust output"),
                },
-               script_sig: Script::new(),
+               script_sig: ScriptBuf::new(),
                sequence: Sequence(if channel_type_features.supports_anchors_zero_fee_htlc_tx() { 1 } else { 0 }),
                witness: Witness::new(),
        }
@@ -814,9 +816,9 @@ pub(crate) fn legacy_deserialization_prevention_marker_for_channel_type_features
 
 /// Gets the witnessScript for the to_remote output when anchors are enabled.
 #[inline]
-pub fn get_to_countersignatory_with_anchors_redeemscript(payment_point: &PublicKey) -> Script {
+pub fn get_to_countersignatory_with_anchors_redeemscript(payment_point: &PublicKey) -> ScriptBuf {
        Builder::new()
-               .push_slice(&payment_point.serialize()[..])
+               .push_slice(payment_point.serialize())
                .push_opcode(opcodes::all::OP_CHECKSIGVERIFY)
                .push_int(1)
                .push_opcode(opcodes::all::OP_CSV)
@@ -830,8 +832,8 @@ pub fn get_to_countersignatory_with_anchors_redeemscript(payment_point: &PublicK
 /// <>
 /// (empty vector required to satisfy compliance with MINIMALIF-standard rule)
 #[inline]
-pub fn get_anchor_redeemscript(funding_pubkey: &PublicKey) -> Script {
-       Builder::new().push_slice(&funding_pubkey.serialize()[..])
+pub fn get_anchor_redeemscript(funding_pubkey: &PublicKey) -> ScriptBuf {
+       Builder::new().push_slice(funding_pubkey.serialize())
                .push_opcode(opcodes::all::OP_CHECKSIG)
                .push_opcode(opcodes::all::OP_IFDUP)
                .push_opcode(opcodes::all::OP_NOTIF)
@@ -1194,8 +1196,8 @@ impl BuiltCommitmentTransaction {
 pub struct ClosingTransaction {
        to_holder_value_sat: u64,
        to_counterparty_value_sat: u64,
-       to_holder_script: Script,
-       to_counterparty_script: Script,
+       to_holder_script: ScriptBuf,
+       to_counterparty_script: ScriptBuf,
        built: Transaction,
 }
 
@@ -1204,8 +1206,8 @@ impl ClosingTransaction {
        pub fn new(
                to_holder_value_sat: u64,
                to_counterparty_value_sat: u64,
-               to_holder_script: Script,
-               to_counterparty_script: Script,
+               to_holder_script: ScriptBuf,
+               to_counterparty_script: ScriptBuf,
                funding_outpoint: OutPoint,
        ) -> Self {
                let built = build_closing_transaction(
@@ -1461,7 +1463,7 @@ impl CommitmentTransaction {
        fn make_transaction(obscured_commitment_transaction_number: u64, txins: Vec<TxIn>, outputs: Vec<TxOut>) -> Transaction {
                Transaction {
                        version: 2,
-                       lock_time: PackedLockTime(((0x20 as u32) << 8 * 3) | ((obscured_commitment_transaction_number & 0xffffffu64) as u32)),
+                       lock_time: LockTime::from_consensus(((0x20 as u32) << 8 * 3) | ((obscured_commitment_transaction_number & 0xffffffu64) as u32)),
                        input: txins,
                        output: outputs,
                }
@@ -1584,7 +1586,7 @@ impl CommitmentTransaction {
                        let mut ins: Vec<TxIn> = Vec::new();
                        ins.push(TxIn {
                                previous_output: channel_parameters.funding_outpoint(),
-                               script_sig: Script::new(),
+                               script_sig: ScriptBuf::new(),
                                sequence: Sequence(((0x80 as u32) << 8 * 3)
                                        | ((obscured_commitment_transaction_number >> 3 * 8) as u32)),
                                witness: Witness::new(),
@@ -1794,7 +1796,7 @@ impl<'a> TrustedCommitmentTransaction<'a> {
        /// The built transaction will allow fee bumping with RBF, and this method takes
        /// `feerate_per_kw` as an input such that multiple copies of a justice transaction at different
        /// fee rates may be built.
-       pub fn build_to_local_justice_tx(&self, feerate_per_kw: u64, destination_script: Script)
+       pub fn build_to_local_justice_tx(&self, feerate_per_kw: u64, destination_script: ScriptBuf)
        -> Result<Transaction, ()> {
                let output_idx = self.revokeable_output_index().ok_or(())?;
                let input = vec![TxIn {
@@ -1802,7 +1804,7 @@ impl<'a> TrustedCommitmentTransaction<'a> {
                                txid: self.trust().txid(),
                                vout: output_idx as u32,
                        },
-                       script_sig: Script::new(),
+                       script_sig: ScriptBuf::new(),
                        sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
                        witness: Witness::new(),
                }];
@@ -1813,11 +1815,11 @@ impl<'a> TrustedCommitmentTransaction<'a> {
                }];
                let mut justice_tx = Transaction {
                        version: 2,
-                       lock_time: PackedLockTime::ZERO,
+                       lock_time: LockTime::ZERO,
                        input,
                        output,
                };
-               let weight = justice_tx.weight() as u64 + WEIGHT_REVOKED_OUTPUT;
+               let weight = justice_tx.weight().to_wu() + WEIGHT_REVOKED_OUTPUT;
                let fee = fee_for_weight(feerate_per_kw as u32, weight);
                justice_tx.output[0].value = value.checked_sub(fee).ok_or(())?;
                Ok(justice_tx)
@@ -1845,7 +1847,7 @@ pub fn get_commitment_transaction_number_obscure_factor(
                sha.input(&countersignatory_payment_basepoint.serialize());
                sha.input(&broadcaster_payment_basepoint.serialize());
        }
-       let res = Sha256::from_engine(sha).into_inner();
+       let res = Sha256::from_engine(sha).to_byte_array();
 
        ((res[26] as u64) << 5 * 8)
                | ((res[27] as u64) << 4 * 8)
@@ -1858,17 +1860,17 @@ pub fn get_commitment_transaction_number_obscure_factor(
 #[cfg(test)]
 mod tests {
        use super::{CounterpartyCommitmentSecrets, ChannelPublicKeys};
-       use crate::{hex, chain};
+       use crate::chain;
        use crate::prelude::*;
        use crate::ln::chan_utils::{get_htlc_redeemscript, get_to_countersignatory_with_anchors_redeemscript, CommitmentTransaction, TxCreationKeys, ChannelTransactionParameters, CounterpartyChannelTransactionParameters, HTLCOutputInCommitment};
        use bitcoin::secp256k1::{PublicKey, SecretKey, Secp256k1};
        use crate::util::test_utils;
        use crate::sign::{ChannelSigner, SignerProvider};
-       use bitcoin::{Network, Txid, Script};
+       use bitcoin::{Network, Txid, ScriptBuf};
        use bitcoin::hashes::Hash;
+       use bitcoin::hashes::hex::FromHex;
        use crate::ln::PaymentHash;
-       use bitcoin::hashes::hex::ToHex;
-       use bitcoin::util::address::Payload;
+       use bitcoin::address::Payload;
        use bitcoin::PublicKey as BitcoinPublicKey;
        use crate::ln::features::ChannelTypeFeatures;
 
@@ -1892,7 +1894,7 @@ mod tests {
                        let signer = keys_provider.derive_channel_signer(3000, keys_provider.generate_channel_keys_id(false, 1_000_000, 0));
                        let counterparty_signer = keys_provider.derive_channel_signer(3000, keys_provider.generate_channel_keys_id(true, 1_000_000, 1));
                        let delayed_payment_base = &signer.pubkeys().delayed_payment_basepoint;
-                       let per_commitment_secret = SecretKey::from_slice(&hex::decode("1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100").unwrap()[..]).unwrap();
+                       let per_commitment_secret = SecretKey::from_slice(&<Vec<u8>>::from_hex("1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100").unwrap()[..]).unwrap();
                        let per_commitment_point = PublicKey::from_secret_key(&secp_ctx, &per_commitment_secret);
                        let htlc_basepoint = &signer.pubkeys().htlc_basepoint;
                        let holder_pubkeys = signer.pubkeys();
@@ -1978,9 +1980,9 @@ mod tests {
                assert_eq!(tx.built.transaction.output.len(), 3);
                assert_eq!(tx.built.transaction.output[0].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_v0_p2wsh());
                assert_eq!(tx.built.transaction.output[1].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_v0_p2wsh());
-               assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_v0_p2wsh().to_hex(),
+               assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_v0_p2wsh().to_hex_string(),
                                   "0020e43a7c068553003fe68fcae424fb7b28ec5ce48cd8b6744b3945631389bad2fb");
-               assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_v0_p2wsh().to_hex(),
+               assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_v0_p2wsh().to_hex_string(),
                                   "0020215d61bba56b19e9eadb6107f5a85d7f99c40f65992443f69229c290165bc00d");
 
                // Generate broadcaster output and received and offered HTLC outputs,  with anchors
@@ -1990,9 +1992,9 @@ mod tests {
                assert_eq!(tx.built.transaction.output.len(), 5);
                assert_eq!(tx.built.transaction.output[2].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_v0_p2wsh());
                assert_eq!(tx.built.transaction.output[3].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_v0_p2wsh());
-               assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_v0_p2wsh().to_hex(),
+               assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_v0_p2wsh().to_hex_string(),
                                   "0020b70d0649c72b38756885c7a30908d912a7898dd5d79457a7280b8e9a20f3f2bc");
-               assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_v0_p2wsh().to_hex(),
+               assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_v0_p2wsh().to_hex_string(),
                                   "002087a3faeb1950a469c0e2db4a79b093a41b9526e5a6fc6ef5cb949bde3be379c7");
        }
 
@@ -2023,22 +2025,22 @@ mod tests {
                // Revokeable output not present (our balance is dust)
                let tx = builder.build(0, 2000);
                assert_eq!(tx.built.transaction.output.len(), 1);
-               assert!(tx.trust().build_to_local_justice_tx(253, Script::new()).is_err());
+               assert!(tx.trust().build_to_local_justice_tx(253, ScriptBuf::new()).is_err());
 
                // Revokeable output present
                let tx = builder.build(1000, 2000);
                assert_eq!(tx.built.transaction.output.len(), 2);
 
                // Too high feerate
-               assert!(tx.trust().build_to_local_justice_tx(100_000, Script::new()).is_err());
+               assert!(tx.trust().build_to_local_justice_tx(100_000, ScriptBuf::new()).is_err());
 
                // Generate a random public key for destination script
                let secret_key = SecretKey::from_slice(
-                       &hex::decode("1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100")
+                       &<Vec<u8>>::from_hex("1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100")
                        .unwrap()[..]).unwrap();
                let pubkey_hash = BitcoinPublicKey::new(
                        PublicKey::from_secret_key(&Secp256k1::new(), &secret_key)).wpubkey_hash().unwrap();
-               let destination_script = Script::new_v0_p2wpkh(&pubkey_hash);
+               let destination_script = ScriptBuf::new_v0_p2wpkh(&pubkey_hash);
 
                let justice_tx = tx.trust().build_to_local_justice_tx(253, destination_script.clone()).unwrap();
                assert_eq!(justice_tx.input.len(), 1);
@@ -2075,42 +2077,42 @@ mod tests {
                        secrets.clear();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap());
                        monitor.provide_secret(281474976710655, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
                        monitor.provide_secret(281474976710654, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
                        monitor.provide_secret(281474976710653, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
                        monitor.provide_secret(281474976710652, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c65716add7aa98ba7acb236352d665cab17345fe45b55fb879ff80e6bd0c41dd").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("c65716add7aa98ba7acb236352d665cab17345fe45b55fb879ff80e6bd0c41dd").unwrap());
                        monitor.provide_secret(281474976710651, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("969660042a28f32d9be17344e09374b379962d03db1574df5a8a5a47e19ce3f2").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("969660042a28f32d9be17344e09374b379962d03db1574df5a8a5a47e19ce3f2").unwrap());
                        monitor.provide_secret(281474976710650, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("a5a64476122ca0925fb344bdc1854c1c0a59fc614298e50a33e331980a220f32").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("a5a64476122ca0925fb344bdc1854c1c0a59fc614298e50a33e331980a220f32").unwrap());
                        monitor.provide_secret(281474976710649, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("05cde6323d949933f7f7b78776bcc1ea6d9b31447732e3802e1f7ac44b650e17").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("05cde6323d949933f7f7b78776bcc1ea6d9b31447732e3802e1f7ac44b650e17").unwrap());
                        monitor.provide_secret(281474976710648, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
                }
@@ -2121,12 +2123,12 @@ mod tests {
                        secrets.clear();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("02a40c85b6f28da08dfdbe0926c53fab2de6d28c10301f8f7c4073d5e42e3148").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("02a40c85b6f28da08dfdbe0926c53fab2de6d28c10301f8f7c4073d5e42e3148").unwrap());
                        monitor.provide_secret(281474976710655, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
                        assert!(monitor.provide_secret(281474976710654, secrets.last().unwrap().clone()).is_err());
                }
 
@@ -2136,22 +2138,22 @@ mod tests {
                        secrets.clear();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("02a40c85b6f28da08dfdbe0926c53fab2de6d28c10301f8f7c4073d5e42e3148").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("02a40c85b6f28da08dfdbe0926c53fab2de6d28c10301f8f7c4073d5e42e3148").unwrap());
                        monitor.provide_secret(281474976710655, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("dddc3a8d14fddf2b68fa8c7fbad2748274937479dd0f8930d5ebb4ab6bd866a3").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("dddc3a8d14fddf2b68fa8c7fbad2748274937479dd0f8930d5ebb4ab6bd866a3").unwrap());
                        monitor.provide_secret(281474976710654, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
                        monitor.provide_secret(281474976710653, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
                        assert!(monitor.provide_secret(281474976710652, secrets.last().unwrap().clone()).is_err());
                }
 
@@ -2161,22 +2163,22 @@ mod tests {
                        secrets.clear();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap());
                        monitor.provide_secret(281474976710655, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
                        monitor.provide_secret(281474976710654, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c51a18b13e8527e579ec56365482c62f180b7d5760b46e9477dae59e87ed423a").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("c51a18b13e8527e579ec56365482c62f180b7d5760b46e9477dae59e87ed423a").unwrap());
                        monitor.provide_secret(281474976710653, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
                        assert!(monitor.provide_secret(281474976710652, secrets.last().unwrap().clone()).is_err());
                }
 
@@ -2186,42 +2188,42 @@ mod tests {
                        secrets.clear();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("02a40c85b6f28da08dfdbe0926c53fab2de6d28c10301f8f7c4073d5e42e3148").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("02a40c85b6f28da08dfdbe0926c53fab2de6d28c10301f8f7c4073d5e42e3148").unwrap());
                        monitor.provide_secret(281474976710655, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("dddc3a8d14fddf2b68fa8c7fbad2748274937479dd0f8930d5ebb4ab6bd866a3").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("dddc3a8d14fddf2b68fa8c7fbad2748274937479dd0f8930d5ebb4ab6bd866a3").unwrap());
                        monitor.provide_secret(281474976710654, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c51a18b13e8527e579ec56365482c62f180b7d5760b46e9477dae59e87ed423a").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("c51a18b13e8527e579ec56365482c62f180b7d5760b46e9477dae59e87ed423a").unwrap());
                        monitor.provide_secret(281474976710653, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("ba65d7b0ef55a3ba300d4e87af29868f394f8f138d78a7011669c79b37b936f4").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("ba65d7b0ef55a3ba300d4e87af29868f394f8f138d78a7011669c79b37b936f4").unwrap());
                        monitor.provide_secret(281474976710652, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c65716add7aa98ba7acb236352d665cab17345fe45b55fb879ff80e6bd0c41dd").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("c65716add7aa98ba7acb236352d665cab17345fe45b55fb879ff80e6bd0c41dd").unwrap());
                        monitor.provide_secret(281474976710651, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("969660042a28f32d9be17344e09374b379962d03db1574df5a8a5a47e19ce3f2").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("969660042a28f32d9be17344e09374b379962d03db1574df5a8a5a47e19ce3f2").unwrap());
                        monitor.provide_secret(281474976710650, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("a5a64476122ca0925fb344bdc1854c1c0a59fc614298e50a33e331980a220f32").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("a5a64476122ca0925fb344bdc1854c1c0a59fc614298e50a33e331980a220f32").unwrap());
                        monitor.provide_secret(281474976710649, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("05cde6323d949933f7f7b78776bcc1ea6d9b31447732e3802e1f7ac44b650e17").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("05cde6323d949933f7f7b78776bcc1ea6d9b31447732e3802e1f7ac44b650e17").unwrap());
                        assert!(monitor.provide_secret(281474976710648, secrets.last().unwrap().clone()).is_err());
                }
 
@@ -2231,32 +2233,32 @@ mod tests {
                        secrets.clear();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap());
                        monitor.provide_secret(281474976710655, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
                        monitor.provide_secret(281474976710654, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
                        monitor.provide_secret(281474976710653, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
                        monitor.provide_secret(281474976710652, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("631373ad5f9ef654bb3dade742d09504c567edd24320d2fcd68e3cc47e2ff6a6").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("631373ad5f9ef654bb3dade742d09504c567edd24320d2fcd68e3cc47e2ff6a6").unwrap());
                        monitor.provide_secret(281474976710651, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("969660042a28f32d9be17344e09374b379962d03db1574df5a8a5a47e19ce3f2").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("969660042a28f32d9be17344e09374b379962d03db1574df5a8a5a47e19ce3f2").unwrap());
                        assert!(monitor.provide_secret(281474976710650, secrets.last().unwrap().clone()).is_err());
                }
 
@@ -2266,42 +2268,42 @@ mod tests {
                        secrets.clear();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap());
                        monitor.provide_secret(281474976710655, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
                        monitor.provide_secret(281474976710654, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
                        monitor.provide_secret(281474976710653, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
                        monitor.provide_secret(281474976710652, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("631373ad5f9ef654bb3dade742d09504c567edd24320d2fcd68e3cc47e2ff6a6").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("631373ad5f9ef654bb3dade742d09504c567edd24320d2fcd68e3cc47e2ff6a6").unwrap());
                        monitor.provide_secret(281474976710651, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("b7e76a83668bde38b373970155c868a653304308f9896692f904a23731224bb1").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("b7e76a83668bde38b373970155c868a653304308f9896692f904a23731224bb1").unwrap());
                        monitor.provide_secret(281474976710650, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("a5a64476122ca0925fb344bdc1854c1c0a59fc614298e50a33e331980a220f32").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("a5a64476122ca0925fb344bdc1854c1c0a59fc614298e50a33e331980a220f32").unwrap());
                        monitor.provide_secret(281474976710649, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("05cde6323d949933f7f7b78776bcc1ea6d9b31447732e3802e1f7ac44b650e17").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("05cde6323d949933f7f7b78776bcc1ea6d9b31447732e3802e1f7ac44b650e17").unwrap());
                        assert!(monitor.provide_secret(281474976710648, secrets.last().unwrap().clone()).is_err());
                }
 
@@ -2311,42 +2313,42 @@ mod tests {
                        secrets.clear();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap());
                        monitor.provide_secret(281474976710655, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
                        monitor.provide_secret(281474976710654, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
                        monitor.provide_secret(281474976710653, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
                        monitor.provide_secret(281474976710652, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c65716add7aa98ba7acb236352d665cab17345fe45b55fb879ff80e6bd0c41dd").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("c65716add7aa98ba7acb236352d665cab17345fe45b55fb879ff80e6bd0c41dd").unwrap());
                        monitor.provide_secret(281474976710651, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("969660042a28f32d9be17344e09374b379962d03db1574df5a8a5a47e19ce3f2").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("969660042a28f32d9be17344e09374b379962d03db1574df5a8a5a47e19ce3f2").unwrap());
                        monitor.provide_secret(281474976710650, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("e7971de736e01da8ed58b94c2fc216cb1dca9e326f3a96e7194fe8ea8af6c0a3").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("e7971de736e01da8ed58b94c2fc216cb1dca9e326f3a96e7194fe8ea8af6c0a3").unwrap());
                        monitor.provide_secret(281474976710649, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("05cde6323d949933f7f7b78776bcc1ea6d9b31447732e3802e1f7ac44b650e17").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("05cde6323d949933f7f7b78776bcc1ea6d9b31447732e3802e1f7ac44b650e17").unwrap());
                        assert!(monitor.provide_secret(281474976710648, secrets.last().unwrap().clone()).is_err());
                }
 
@@ -2356,42 +2358,42 @@ mod tests {
                        secrets.clear();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap());
                        monitor.provide_secret(281474976710655, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
                        monitor.provide_secret(281474976710654, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
                        monitor.provide_secret(281474976710653, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
                        monitor.provide_secret(281474976710652, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c65716add7aa98ba7acb236352d665cab17345fe45b55fb879ff80e6bd0c41dd").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("c65716add7aa98ba7acb236352d665cab17345fe45b55fb879ff80e6bd0c41dd").unwrap());
                        monitor.provide_secret(281474976710651, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("969660042a28f32d9be17344e09374b379962d03db1574df5a8a5a47e19ce3f2").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("969660042a28f32d9be17344e09374b379962d03db1574df5a8a5a47e19ce3f2").unwrap());
                        monitor.provide_secret(281474976710650, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("a5a64476122ca0925fb344bdc1854c1c0a59fc614298e50a33e331980a220f32").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("a5a64476122ca0925fb344bdc1854c1c0a59fc614298e50a33e331980a220f32").unwrap());
                        monitor.provide_secret(281474976710649, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
-                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("a7efbc61aac46d34f77778bac22c8a20c6a46ca460addc49009bda875ec88fa4").unwrap());
+                       secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("a7efbc61aac46d34f77778bac22c8a20c6a46ca460addc49009bda875ec88fa4").unwrap());
                        assert!(monitor.provide_secret(281474976710648, secrets.last().unwrap().clone()).is_err());
                }
        }
index f499127bc36116d52a853fd9039d046aa904f34f..6803b11284b95c1539a7585b5b0f0fced28bfe8e 100644 (file)
@@ -8,9 +8,10 @@
 // licenses.
 
 use bitcoin::blockdata::constants::ChainHash;
-use bitcoin::blockdata::script::{Script,Builder};
-use bitcoin::blockdata::transaction::{Transaction, EcdsaSighashType};
-use bitcoin::util::sighash;
+use bitcoin::blockdata::script::{Script, ScriptBuf, Builder};
+use bitcoin::blockdata::transaction::Transaction;
+use bitcoin::sighash;
+use bitcoin::sighash::EcdsaSighashType;
 use bitcoin::consensus::encode;
 
 use bitcoin::hashes::Hash;
@@ -52,7 +53,6 @@ use core::convert::TryInto;
 use core::ops::Deref;
 #[cfg(any(test, fuzzing, debug_assertions))]
 use crate::sync::Mutex;
-use bitcoin::hashes::hex::ToHex;
 use crate::sign::type_resolver::ChannelSignerType;
 
 #[cfg(test)]
@@ -725,7 +725,7 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
 
        holder_signer: ChannelSignerType<<SP::Target as SignerProvider>::Signer>,
        shutdown_scriptpubkey: Option<ShutdownScript>,
-       destination_script: Script,
+       destination_script: ScriptBuf,
 
        // Our commitment numbers start at 2^48-1 and count down, whereas the ones used in transaction
        // generation start at 0 and count up...this simplifies some parts of implementation at the
@@ -882,7 +882,7 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
        counterparty_prev_commitment_point: Option<PublicKey>,
        counterparty_node_id: PublicKey,
 
-       counterparty_shutdown_scriptpubkey: Option<Script>,
+       counterparty_shutdown_scriptpubkey: Option<ScriptBuf>,
 
        commitment_secrets: CounterpartyCommitmentSecrets,
 
@@ -1568,7 +1568,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider  {
        /// Gets the redeemscript for the funding transaction output (ie the funding transaction output
        /// pays to get_funding_redeemscript().to_v0_p2wsh()).
        /// Panics if called before accept_channel/InboundV1Channel::new
-       pub fn get_funding_redeemscript(&self) -> Script {
+       pub fn get_funding_redeemscript(&self) -> ScriptBuf {
                make_funding_redeemscript(&self.get_holder_pubkeys().funding_pubkey, self.counterparty_funding_pubkey())
        }
 
@@ -2289,7 +2289,7 @@ impl<SP: Deref> Channel<SP> where
        }
 
        #[inline]
-       fn get_closing_scriptpubkey(&self) -> Script {
+       fn get_closing_scriptpubkey(&self) -> ScriptBuf {
                // The shutdown scriptpubkey is set on channel opening when option_upfront_shutdown_script
                // is signaled. Otherwise, it is set when sending a shutdown message. Calling this method
                // outside of those situations will fail.
@@ -2402,7 +2402,7 @@ impl<SP: Deref> Channel<SP> where
                let mut htlc_value_msat = 0;
                for (idx, htlc) in self.context.pending_inbound_htlcs.iter().enumerate() {
                        if htlc.htlc_id == htlc_id_arg {
-                               debug_assert_eq!(htlc.payment_hash, PaymentHash(Sha256::hash(&payment_preimage_arg.0[..]).into_inner()));
+                               debug_assert_eq!(htlc.payment_hash, PaymentHash(Sha256::hash(&payment_preimage_arg.0[..]).to_byte_array()));
                                log_debug!(logger, "Claiming inbound HTLC id {} with payment hash {} with preimage {}",
                                        htlc.htlc_id, htlc.payment_hash, payment_preimage_arg);
                                match htlc.state {
@@ -3012,7 +3012,7 @@ impl<SP: Deref> Channel<SP> where
                                let outcome = match check_preimage {
                                        None => fail_reason.into(),
                                        Some(payment_preimage) => {
-                                               let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner());
+                                               let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).to_byte_array());
                                                if payment_hash != htlc.payment_hash {
                                                        return Err(ChannelError::Close(format!("Remote tried to fulfill HTLC ({}) with an incorrect preimage", htlc_id)));
                                                }
@@ -4473,12 +4473,12 @@ impl<SP: Deref> Channel<SP> where
                assert_eq!(self.context.channel_state & ChannelState::ShutdownComplete as u32, 0);
 
                if !script::is_bolt2_compliant(&msg.scriptpubkey, their_features) {
-                       return Err(ChannelError::Warn(format!("Got a nonstandard scriptpubkey ({}) from remote peer", msg.scriptpubkey.to_bytes().to_hex())));
+                       return Err(ChannelError::Warn(format!("Got a nonstandard scriptpubkey ({}) from remote peer", msg.scriptpubkey.to_hex_string())));
                }
 
                if self.context.counterparty_shutdown_scriptpubkey.is_some() {
                        if Some(&msg.scriptpubkey) != self.context.counterparty_shutdown_scriptpubkey.as_ref() {
-                               return Err(ChannelError::Warn(format!("Got shutdown request with a scriptpubkey ({}) which did not match their previous scriptpubkey.", msg.scriptpubkey.to_bytes().to_hex())));
+                               return Err(ChannelError::Warn(format!("Got shutdown request with a scriptpubkey ({}) which did not match their previous scriptpubkey.", msg.scriptpubkey.to_hex_string())));
                        }
                } else {
                        self.context.counterparty_shutdown_scriptpubkey = Some(msg.scriptpubkey.clone());
@@ -7791,11 +7791,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
 mod tests {
        use std::cmp;
        use bitcoin::blockdata::constants::ChainHash;
-       use bitcoin::blockdata::script::{Script, Builder};
+       use bitcoin::blockdata::script::{ScriptBuf, Builder};
        use bitcoin::blockdata::transaction::{Transaction, TxOut};
        use bitcoin::blockdata::opcodes;
        use bitcoin::network::constants::Network;
-       use hex;
        use crate::ln::PaymentHash;
        use crate::ln::channelmanager::{self, HTLCSource, PaymentId};
        use crate::ln::channel::InitFeatures;
@@ -7820,9 +7819,10 @@ mod tests {
        use bitcoin::secp256k1::{SecretKey,PublicKey};
        use bitcoin::hashes::sha256::Hash as Sha256;
        use bitcoin::hashes::Hash;
+       use bitcoin::hashes::hex::FromHex;
        use bitcoin::hash_types::WPubkeyHash;
-       use bitcoin::PackedLockTime;
-       use bitcoin::util::address::WitnessVersion;
+       use bitcoin::blockdata::locktime::absolute::LockTime;
+       use bitcoin::address::{WitnessProgram, WitnessVersion};
        use crate::prelude::*;
 
        struct TestFeeEstimator {
@@ -7862,30 +7862,31 @@ mod tests {
 
                fn read_chan_signer(&self, _data: &[u8]) -> Result<Self::Signer, DecodeError> { panic!(); }
 
-               fn get_destination_script(&self) -> Result<Script, ()> {
+               fn get_destination_script(&self) -> Result<ScriptBuf, ()> {
                        let secp_ctx = Secp256k1::signing_only();
-                       let channel_monitor_claim_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
+                       let channel_monitor_claim_key = SecretKey::from_slice(&<Vec<u8>>::from_hex("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
                        let channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
-                       Ok(Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&channel_monitor_claim_key_hash[..]).into_script())
+                       Ok(Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(channel_monitor_claim_key_hash).into_script())
                }
 
                fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
                        let secp_ctx = Secp256k1::signing_only();
-                       let channel_close_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
+                       let channel_close_key = SecretKey::from_slice(&<Vec<u8>>::from_hex("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
                        Ok(ShutdownScript::new_p2wpkh_from_pubkey(PublicKey::from_secret_key(&secp_ctx, &channel_close_key)))
                }
        }
 
        #[cfg(all(feature = "_test_vectors", not(feature = "grind_signatures")))]
        fn public_from_secret_hex(secp_ctx: &Secp256k1<bitcoin::secp256k1::All>, hex: &str) -> PublicKey {
-               PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode(hex).unwrap()[..]).unwrap())
+               PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()[..]).unwrap())
        }
 
        #[test]
        fn upfront_shutdown_script_incompatibility() {
                let features = channelmanager::provided_init_features(&UserConfig::default()).clear_shutdown_anysegwit();
-               let non_v0_segwit_shutdown_script =
-                       ShutdownScript::new_witness_program(WitnessVersion::V16, &[0, 40]).unwrap();
+               let non_v0_segwit_shutdown_script = ShutdownScript::new_witness_program(
+                       &WitnessProgram::new(WitnessVersion::V16, &[0, 40]).unwrap(),
+               ).unwrap();
 
                let seed = [42; 32];
                let network = Network::Testnet;
@@ -7963,7 +7964,7 @@ mod tests {
 
                // Node A --> Node B: funding created
                let output_script = node_a_chan.context.get_funding_redeemscript();
-               let tx = Transaction { version: 1, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: vec![TxOut {
+               let tx = Transaction { version: 1, lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut {
                        value: 10000000, script_pubkey: output_script.clone(),
                }]};
                let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
@@ -7978,7 +7979,7 @@ mod tests {
                node_a_chan.context.pending_inbound_htlcs.push(InboundHTLCOutput {
                        htlc_id: 0,
                        amount_msat: htlc_amount_msat,
-                       payment_hash: PaymentHash(Sha256::hash(&[42; 32]).into_inner()),
+                       payment_hash: PaymentHash(Sha256::hash(&[42; 32]).to_byte_array()),
                        cltv_expiry: 300000000,
                        state: InboundHTLCState::Committed,
                });
@@ -7986,12 +7987,12 @@ mod tests {
                node_a_chan.context.pending_outbound_htlcs.push(OutboundHTLCOutput {
                        htlc_id: 1,
                        amount_msat: htlc_amount_msat, // put an amount below A's dust amount but above B's.
-                       payment_hash: PaymentHash(Sha256::hash(&[43; 32]).into_inner()),
+                       payment_hash: PaymentHash(Sha256::hash(&[43; 32]).to_byte_array()),
                        cltv_expiry: 200000000,
                        state: OutboundHTLCState::Committed,
                        source: HTLCSource::OutboundRoute {
                                path: Path { hops: Vec::new(), blinded_tail: None },
-                               session_priv: SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
+                               session_priv: SecretKey::from_slice(&<Vec<u8>>::from_hex("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
                                first_hop_htlc_msat: 548,
                                payment_id: PaymentId([42; 32]),
                        },
@@ -8090,7 +8091,7 @@ mod tests {
 
                // Node A --> Node B: funding created
                let output_script = node_a_chan.context.get_funding_redeemscript();
-               let tx = Transaction { version: 1, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: vec![TxOut {
+               let tx = Transaction { version: 1, lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut {
                        value: 10000000, script_pubkey: output_script.clone(),
                }]};
                let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
@@ -8278,7 +8279,7 @@ mod tests {
 
                // Node A --> Node B: funding created
                let output_script = node_a_chan.context.get_funding_redeemscript();
-               let tx = Transaction { version: 1, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: vec![TxOut {
+               let tx = Transaction { version: 1, lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut {
                        value: 10000000, script_pubkey: output_script.clone(),
                }]};
                let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
@@ -8324,9 +8325,9 @@ mod tests {
        #[cfg(feature = "_test_vectors")]
        #[test]
        fn outbound_commitment_test() {
-               use bitcoin::util::sighash;
+               use bitcoin::sighash;
                use bitcoin::consensus::encode::serialize;
-               use bitcoin::blockdata::transaction::EcdsaSighashType;
+               use bitcoin::sighash::EcdsaSighashType;
                use bitcoin::hashes::hex::FromHex;
                use bitcoin::hash_types::Txid;
                use bitcoin::secp256k1::Message;
@@ -8336,6 +8337,8 @@ mod tests {
                use crate::ln::chan_utils::{ChannelPublicKeys, HolderCommitmentTransaction, CounterpartyChannelTransactionParameters};
                use crate::util::logger::Logger;
                use crate::sync::Arc;
+               use core::str::FromStr;
+               use hex::DisplayHex;
 
                // Test vectors from BOLT 3 Appendices C and F (anchors):
                let feeest = TestFeeEstimator{fee_est: 15000};
@@ -8344,11 +8347,11 @@ mod tests {
 
                let mut signer = InMemorySigner::new(
                        &secp_ctx,
-                       SecretKey::from_slice(&hex::decode("30ff4956bbdd3222d44cc5e8a1261dab1e07957bdac5ae88fe3261ef321f3749").unwrap()[..]).unwrap(),
-                       SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
-                       SecretKey::from_slice(&hex::decode("1111111111111111111111111111111111111111111111111111111111111111").unwrap()[..]).unwrap(),
-                       SecretKey::from_slice(&hex::decode("3333333333333333333333333333333333333333333333333333333333333333").unwrap()[..]).unwrap(),
-                       SecretKey::from_slice(&hex::decode("1111111111111111111111111111111111111111111111111111111111111111").unwrap()[..]).unwrap(),
+                       SecretKey::from_slice(&<Vec<u8>>::from_hex("30ff4956bbdd3222d44cc5e8a1261dab1e07957bdac5ae88fe3261ef321f3749").unwrap()[..]).unwrap(),
+                       SecretKey::from_slice(&<Vec<u8>>::from_hex("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
+                       SecretKey::from_slice(&<Vec<u8>>::from_hex("1111111111111111111111111111111111111111111111111111111111111111").unwrap()[..]).unwrap(),
+                       SecretKey::from_slice(&<Vec<u8>>::from_hex("3333333333333333333333333333333333333333333333333333333333333333").unwrap()[..]).unwrap(),
+                       SecretKey::from_slice(&<Vec<u8>>::from_hex("1111111111111111111111111111111111111111111111111111111111111111").unwrap()[..]).unwrap(),
 
                        // These aren't set in the test vectors:
                        [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
@@ -8358,7 +8361,7 @@ mod tests {
                );
 
                assert_eq!(signer.pubkeys().funding_pubkey.serialize()[..],
-                               hex::decode("023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb").unwrap()[..]);
+                               <Vec<u8>>::from_hex("023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb").unwrap()[..]);
                let keys_provider = Keys { signer: signer.clone() };
 
                let counterparty_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
@@ -8368,11 +8371,11 @@ mod tests {
                chan.context.holder_dust_limit_satoshis = 546;
                chan.context.counterparty_selected_channel_reserve_satoshis = Some(0); // Filled in in accept_channel
 
-               let funding_info = OutPoint{ txid: Txid::from_hex("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(), index: 0 };
+               let funding_info = OutPoint{ txid: Txid::from_str("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(), index: 0 };
 
                let counterparty_pubkeys = ChannelPublicKeys {
                        funding_pubkey: public_from_secret_hex(&secp_ctx, "1552dfba4f6cf29a62a0af13c8d6981d36d0ef8d61ba10fb0fe90da7634d7e13"),
-                       revocation_basepoint: PublicKey::from_slice(&hex::decode("02466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f27").unwrap()[..]).unwrap(),
+                       revocation_basepoint: PublicKey::from_slice(&<Vec<u8>>::from_hex("02466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f27").unwrap()[..]).unwrap(),
                        payment_point: public_from_secret_hex(&secp_ctx, "4444444444444444444444444444444444444444444444444444444444444444"),
                        delayed_payment_basepoint: public_from_secret_hex(&secp_ctx, "1552dfba4f6cf29a62a0af13c8d6981d36d0ef8d61ba10fb0fe90da7634d7e13"),
                        htlc_basepoint: public_from_secret_hex(&secp_ctx, "4444444444444444444444444444444444444444444444444444444444444444")
@@ -8386,19 +8389,19 @@ mod tests {
                signer.provide_channel_parameters(&chan.context.channel_transaction_parameters);
 
                assert_eq!(counterparty_pubkeys.payment_point.serialize()[..],
-                          hex::decode("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991").unwrap()[..]);
+                          <Vec<u8>>::from_hex("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991").unwrap()[..]);
 
                assert_eq!(counterparty_pubkeys.funding_pubkey.serialize()[..],
-                          hex::decode("030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c1").unwrap()[..]);
+                          <Vec<u8>>::from_hex("030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c1").unwrap()[..]);
 
                assert_eq!(counterparty_pubkeys.htlc_basepoint.serialize()[..],
-                          hex::decode("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991").unwrap()[..]);
+                          <Vec<u8>>::from_hex("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991").unwrap()[..]);
 
                // We can't just use build_holder_transaction_keys here as the per_commitment_secret is not
                // derived from a commitment_seed, so instead we copy it here and call
                // build_commitment_transaction.
                let delayed_payment_base = &chan.context.holder_signer.as_ref().pubkeys().delayed_payment_basepoint;
-               let per_commitment_secret = SecretKey::from_slice(&hex::decode("1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100").unwrap()[..]).unwrap();
+               let per_commitment_secret = SecretKey::from_slice(&<Vec<u8>>::from_hex("1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100").unwrap()[..]).unwrap();
                let per_commitment_point = PublicKey::from_secret_key(&secp_ctx, &per_commitment_secret);
                let htlc_basepoint = &chan.context.holder_signer.as_ref().pubkeys().htlc_basepoint;
                let keys = TxCreationKeys::derive_new(&secp_ctx, &per_commitment_point, delayed_payment_base, htlc_basepoint, &counterparty_pubkeys.revocation_basepoint, &counterparty_pubkeys.htlc_basepoint);
@@ -8432,9 +8435,9 @@ mod tests {
                                let trusted_tx = commitment_tx.trust();
                                let unsigned_tx = trusted_tx.built_transaction();
                                let redeemscript = chan.context.get_funding_redeemscript();
-                               let counterparty_signature = Signature::from_der(&hex::decode($counterparty_sig_hex).unwrap()[..]).unwrap();
+                               let counterparty_signature = Signature::from_der(&<Vec<u8>>::from_hex($counterparty_sig_hex).unwrap()[..]).unwrap();
                                let sighash = unsigned_tx.get_sighash_all(&redeemscript, chan.context.channel_value_satoshis);
-                               log_trace!(logger, "unsigned_tx = {}", hex::encode(serialize(&unsigned_tx.transaction)));
+                               log_trace!(logger, "unsigned_tx = {}", serialize(&unsigned_tx.transaction).as_hex());
                                assert!(secp_ctx.verify_ecdsa(&sighash, &counterparty_signature, chan.context.counterparty_funding_pubkey()).is_ok(), "verify counterparty commitment sig");
 
                                let mut per_htlc: Vec<(HTLCOutputInCommitment, Option<Signature>)> = Vec::new();
@@ -8442,7 +8445,7 @@ mod tests {
                                let mut counterparty_htlc_sigs = Vec::new();
                                counterparty_htlc_sigs.clear(); // Don't warn about excess mut for no-HTLC calls
                                $({
-                                       let remote_signature = Signature::from_der(&hex::decode($counterparty_htlc_sig_hex).unwrap()[..]).unwrap();
+                                       let remote_signature = Signature::from_der(&<Vec<u8>>::from_hex($counterparty_htlc_sig_hex).unwrap()[..]).unwrap();
                                        per_htlc.push((htlcs[$htlc_idx].clone(), Some(remote_signature)));
                                        counterparty_htlc_sigs.push(remote_signature);
                                })*
@@ -8456,18 +8459,18 @@ mod tests {
                                        chan.context.counterparty_funding_pubkey()
                                );
                                let holder_sig = signer.sign_holder_commitment(&holder_commitment_tx, &secp_ctx).unwrap();
-                               assert_eq!(Signature::from_der(&hex::decode($sig_hex).unwrap()[..]).unwrap(), holder_sig, "holder_sig");
+                               assert_eq!(Signature::from_der(&<Vec<u8>>::from_hex($sig_hex).unwrap()[..]).unwrap(), holder_sig, "holder_sig");
 
                                let funding_redeemscript = chan.context.get_funding_redeemscript();
                                let tx = holder_commitment_tx.add_holder_sig(&funding_redeemscript, holder_sig);
-                               assert_eq!(serialize(&tx)[..], hex::decode($tx_hex).unwrap()[..], "tx");
+                               assert_eq!(serialize(&tx)[..], <Vec<u8>>::from_hex($tx_hex).unwrap()[..], "tx");
 
                                // ((htlc, counterparty_sig), (index, holder_sig))
                                let mut htlc_counterparty_sig_iter = holder_commitment_tx.counterparty_htlc_sigs.iter();
 
                                $({
                                        log_trace!(logger, "verifying htlc {}", $htlc_idx);
-                                       let remote_signature = Signature::from_der(&hex::decode($counterparty_htlc_sig_hex).unwrap()[..]).unwrap();
+                                       let remote_signature = Signature::from_der(&<Vec<u8>>::from_hex($counterparty_htlc_sig_hex).unwrap()[..]).unwrap();
 
                                        let ref htlc = htlcs[$htlc_idx];
                                        let mut htlc_tx = chan_utils::build_htlc_transaction(&unsigned_tx.txid, chan.context.feerate_per_kw,
@@ -8481,7 +8484,7 @@ mod tests {
                                        let mut preimage: Option<PaymentPreimage> = None;
                                        if !htlc.offered {
                                                for i in 0..5 {
-                                                       let out = PaymentHash(Sha256::hash(&[i; 32]).into_inner());
+                                                       let out = PaymentHash(Sha256::hash(&[i; 32]).to_byte_array());
                                                        if out == htlc.payment_hash {
                                                                preimage = Some(PaymentPreimage([i; 32]));
                                                        }
@@ -8508,12 +8511,12 @@ mod tests {
                                        let num_anchors = if $opt_anchors.supports_anchors_zero_fee_htlc_tx() { 2 } else { 0 };
                                        assert_eq!(htlc.transaction_output_index, Some($htlc_idx + num_anchors), "output index");
 
-                                       let signature = Signature::from_der(&hex::decode($htlc_sig_hex).unwrap()[..]).unwrap();
+                                       let signature = Signature::from_der(&<Vec<u8>>::from_hex($htlc_sig_hex).unwrap()[..]).unwrap();
                                        assert_eq!(signature, htlc_holder_sig, "htlc sig");
                                        let trusted_tx = holder_commitment_tx.trust();
                                        htlc_tx.input[0].witness = trusted_tx.build_htlc_input_witness($htlc_idx, htlc_counterparty_sig, &htlc_holder_sig, &preimage);
-                                       log_trace!(logger, "htlc_tx = {}", hex::encode(serialize(&htlc_tx)));
-                                       assert_eq!(serialize(&htlc_tx)[..], hex::decode($htlc_tx_hex).unwrap()[..], "htlc tx");
+                                       log_trace!(logger, "htlc_tx = {}", serialize(&htlc_tx).as_hex());
+                                       assert_eq!(serialize(&htlc_tx)[..], <Vec<u8>>::from_hex($htlc_tx_hex).unwrap()[..], "htlc tx");
                                })*
                                assert!(htlc_counterparty_sig_iter.next().is_none());
                        } }
@@ -8544,7 +8547,7 @@ mod tests {
                                payment_hash: PaymentHash([0; 32]),
                                state: InboundHTLCState::Committed,
                        };
-                       out.payment_hash.0 = Sha256::hash(&hex::decode("0000000000000000000000000000000000000000000000000000000000000000").unwrap()).into_inner();
+                       out.payment_hash.0 = Sha256::hash(&<Vec<u8>>::from_hex("0000000000000000000000000000000000000000000000000000000000000000").unwrap()).to_byte_array();
                        out
                });
                chan.context.pending_inbound_htlcs.push({
@@ -8555,7 +8558,7 @@ mod tests {
                                payment_hash: PaymentHash([0; 32]),
                                state: InboundHTLCState::Committed,
                        };
-                       out.payment_hash.0 = Sha256::hash(&hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap()).into_inner();
+                       out.payment_hash.0 = Sha256::hash(&<Vec<u8>>::from_hex("0101010101010101010101010101010101010101010101010101010101010101").unwrap()).to_byte_array();
                        out
                });
                chan.context.pending_outbound_htlcs.push({
@@ -8568,7 +8571,7 @@ mod tests {
                                source: HTLCSource::dummy(),
                                skimmed_fee_msat: None,
                        };
-                       out.payment_hash.0 = Sha256::hash(&hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap()).into_inner();
+                       out.payment_hash.0 = Sha256::hash(&<Vec<u8>>::from_hex("0202020202020202020202020202020202020202020202020202020202020202").unwrap()).to_byte_array();
                        out
                });
                chan.context.pending_outbound_htlcs.push({
@@ -8581,7 +8584,7 @@ mod tests {
                                source: HTLCSource::dummy(),
                                skimmed_fee_msat: None,
                        };
-                       out.payment_hash.0 = Sha256::hash(&hex::decode("0303030303030303030303030303030303030303030303030303030303030303").unwrap()).into_inner();
+                       out.payment_hash.0 = Sha256::hash(&<Vec<u8>>::from_hex("0303030303030303030303030303030303030303030303030303030303030303").unwrap()).to_byte_array();
                        out
                });
                chan.context.pending_inbound_htlcs.push({
@@ -8592,7 +8595,7 @@ mod tests {
                                payment_hash: PaymentHash([0; 32]),
                                state: InboundHTLCState::Committed,
                        };
-                       out.payment_hash.0 = Sha256::hash(&hex::decode("0404040404040404040404040404040404040404040404040404040404040404").unwrap()).into_inner();
+                       out.payment_hash.0 = Sha256::hash(&<Vec<u8>>::from_hex("0404040404040404040404040404040404040404040404040404040404040404").unwrap()).to_byte_array();
                        out
                });
 
@@ -8978,7 +8981,7 @@ mod tests {
                                payment_hash: PaymentHash([0; 32]),
                                state: InboundHTLCState::Committed,
                        };
-                       out.payment_hash.0 = Sha256::hash(&hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap()).into_inner();
+                       out.payment_hash.0 = Sha256::hash(&<Vec<u8>>::from_hex("0101010101010101010101010101010101010101010101010101010101010101").unwrap()).to_byte_array();
                        out
                });
                chan.context.pending_outbound_htlcs.clear();
@@ -8992,7 +8995,7 @@ mod tests {
                                source: HTLCSource::dummy(),
                                skimmed_fee_msat: None,
                        };
-                       out.payment_hash.0 = Sha256::hash(&hex::decode("0505050505050505050505050505050505050505050505050505050505050505").unwrap()).into_inner();
+                       out.payment_hash.0 = Sha256::hash(&<Vec<u8>>::from_hex("0505050505050505050505050505050505050505050505050505050505050505").unwrap()).to_byte_array();
                        out
                });
                chan.context.pending_outbound_htlcs.push({
@@ -9005,7 +9008,7 @@ mod tests {
                                source: HTLCSource::dummy(),
                                skimmed_fee_msat: None,
                        };
-                       out.payment_hash.0 = Sha256::hash(&hex::decode("0505050505050505050505050505050505050505050505050505050505050505").unwrap()).into_inner();
+                       out.payment_hash.0 = Sha256::hash(&<Vec<u8>>::from_hex("0505050505050505050505050505050505050505050505050505050505050505").unwrap()).to_byte_array();
                        out
                });
 
@@ -9052,23 +9055,23 @@ mod tests {
                // Test vectors from BOLT 3 Appendix D:
 
                let mut seed = [0; 32];
-               seed[0..32].clone_from_slice(&hex::decode("0000000000000000000000000000000000000000000000000000000000000000").unwrap());
+               seed[0..32].clone_from_slice(&<Vec<u8>>::from_hex("0000000000000000000000000000000000000000000000000000000000000000").unwrap());
                assert_eq!(chan_utils::build_commitment_secret(&seed, 281474976710655),
-                          hex::decode("02a40c85b6f28da08dfdbe0926c53fab2de6d28c10301f8f7c4073d5e42e3148").unwrap()[..]);
+                          <Vec<u8>>::from_hex("02a40c85b6f28da08dfdbe0926c53fab2de6d28c10301f8f7c4073d5e42e3148").unwrap()[..]);
 
-               seed[0..32].clone_from_slice(&hex::decode("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap());
+               seed[0..32].clone_from_slice(&<Vec<u8>>::from_hex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap());
                assert_eq!(chan_utils::build_commitment_secret(&seed, 281474976710655),
-                          hex::decode("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap()[..]);
+                          <Vec<u8>>::from_hex("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap()[..]);
 
                assert_eq!(chan_utils::build_commitment_secret(&seed, 0xaaaaaaaaaaa),
-                          hex::decode("56f4008fb007ca9acf0e15b054d5c9fd12ee06cea347914ddbaed70d1c13a528").unwrap()[..]);
+                          <Vec<u8>>::from_hex("56f4008fb007ca9acf0e15b054d5c9fd12ee06cea347914ddbaed70d1c13a528").unwrap()[..]);
 
                assert_eq!(chan_utils::build_commitment_secret(&seed, 0x555555555555),
-                          hex::decode("9015daaeb06dba4ccc05b91b2f73bd54405f2be9f217fbacd3c5ac2e62327d31").unwrap()[..]);
+                          <Vec<u8>>::from_hex("9015daaeb06dba4ccc05b91b2f73bd54405f2be9f217fbacd3c5ac2e62327d31").unwrap()[..]);
 
-               seed[0..32].clone_from_slice(&hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap());
+               seed[0..32].clone_from_slice(&<Vec<u8>>::from_hex("0101010101010101010101010101010101010101010101010101010101010101").unwrap());
                assert_eq!(chan_utils::build_commitment_secret(&seed, 1),
-                          hex::decode("915c75942a26bb3a433a8ce2cb0427c29ec6c1775cfc78328b57f6ba7bfeaa9c").unwrap()[..]);
+                          <Vec<u8>>::from_hex("915c75942a26bb3a433a8ce2cb0427c29ec6c1775cfc78328b57f6ba7bfeaa9c").unwrap()[..]);
        }
 
        #[test]
@@ -9076,26 +9079,26 @@ mod tests {
                // Test vectors from BOLT 3 Appendix E:
                let secp_ctx = Secp256k1::new();
 
-               let base_secret = SecretKey::from_slice(&hex::decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f").unwrap()[..]).unwrap();
-               let per_commitment_secret = SecretKey::from_slice(&hex::decode("1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100").unwrap()[..]).unwrap();
+               let base_secret = SecretKey::from_slice(&<Vec<u8>>::from_hex("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f").unwrap()[..]).unwrap();
+               let per_commitment_secret = SecretKey::from_slice(&<Vec<u8>>::from_hex("1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100").unwrap()[..]).unwrap();
 
                let base_point = PublicKey::from_secret_key(&secp_ctx, &base_secret);
-               assert_eq!(base_point.serialize()[..], hex::decode("036d6caac248af96f6afa7f904f550253a0f3ef3f5aa2fe6838a95b216691468e2").unwrap()[..]);
+               assert_eq!(base_point.serialize()[..], <Vec<u8>>::from_hex("036d6caac248af96f6afa7f904f550253a0f3ef3f5aa2fe6838a95b216691468e2").unwrap()[..]);
 
                let per_commitment_point = PublicKey::from_secret_key(&secp_ctx, &per_commitment_secret);
-               assert_eq!(per_commitment_point.serialize()[..], hex::decode("025f7117a78150fe2ef97db7cfc83bd57b2e2c0d0dd25eaf467a4a1c2a45ce1486").unwrap()[..]);
+               assert_eq!(per_commitment_point.serialize()[..], <Vec<u8>>::from_hex("025f7117a78150fe2ef97db7cfc83bd57b2e2c0d0dd25eaf467a4a1c2a45ce1486").unwrap()[..]);
 
                assert_eq!(chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &base_point).serialize()[..],
-                               hex::decode("0235f2dbfaa89b57ec7b055afe29849ef7ddfeb1cefdb9ebdc43f5494984db29e5").unwrap()[..]);
+                               <Vec<u8>>::from_hex("0235f2dbfaa89b57ec7b055afe29849ef7ddfeb1cefdb9ebdc43f5494984db29e5").unwrap()[..]);
 
                assert_eq!(chan_utils::derive_private_key(&secp_ctx, &per_commitment_point, &base_secret),
-                               SecretKey::from_slice(&hex::decode("cbced912d3b21bf196a766651e436aff192362621ce317704ea2f75d87e7be0f").unwrap()[..]).unwrap());
+                               SecretKey::from_slice(&<Vec<u8>>::from_hex("cbced912d3b21bf196a766651e436aff192362621ce317704ea2f75d87e7be0f").unwrap()[..]).unwrap());
 
                assert_eq!(chan_utils::derive_public_revocation_key(&secp_ctx, &per_commitment_point, &base_point).serialize()[..],
-                               hex::decode("02916e326636d19c33f13e8c0c3a03dd157f332f3e99c317c141dd865eb01f8ff0").unwrap()[..]);
+                               <Vec<u8>>::from_hex("02916e326636d19c33f13e8c0c3a03dd157f332f3e99c317c141dd865eb01f8ff0").unwrap()[..]);
 
                assert_eq!(chan_utils::derive_private_revocation_key(&secp_ctx, &per_commitment_secret, &base_secret),
-                               SecretKey::from_slice(&hex::decode("d09ffff62ddb2297ab000cc85bcb4283fdeb6aa052affbc9dddcf33b61078110").unwrap()[..]).unwrap());
+                               SecretKey::from_slice(&<Vec<u8>>::from_hex("d09ffff62ddb2297ab000cc85bcb4283fdeb6aa052affbc9dddcf33b61078110").unwrap()[..]).unwrap());
        }
 
        #[test]
@@ -9341,7 +9344,7 @@ mod tests {
                let output_script = node_a_chan.context.get_funding_redeemscript();
                let tx = Transaction {
                        version: 1,
-                       lock_time: PackedLockTime::ZERO,
+                       lock_time: LockTime::ZERO,
                        input: Vec::new(),
                        output: vec![
                                TxOut {
index cdbcd302929c70b1a2a5c59dd51da2d22df39e2e..8df6d75ef5e80b4d4acb2cb39b2358be9c638131 100644 (file)
@@ -13,10 +13,7 @@ use crate::ln::msgs::DecodeError;
 use crate::sign::EntropySource;
 use crate::util::ser::{Readable, Writeable, Writer};
 
-use bitcoin::hashes::hex::ToHex;
-
 use crate::io;
-use crate::prelude::*;
 use core::fmt;
 use core::ops::Deref;
 
@@ -79,12 +76,6 @@ impl Readable for ChannelId {
        }
 }
 
-impl ToHex for ChannelId {
-       fn to_hex(&self) -> String {
-               self.0.to_hex()
-       }
-}
-
 impl fmt::Display for ChannelId {
        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
                crate::util::logger::DebugBytes(&self.0).fmt(f)
@@ -93,17 +84,18 @@ impl fmt::Display for ChannelId {
 
 #[cfg(test)]
 mod tests {
+       use hex::DisplayHex;
+
        use crate::ln::ChannelId;
        use crate::util::ser::{Readable, Writeable};
        use crate::util::test_utils;
-       use bitcoin::hashes::hex::ToHex;
        use crate::prelude::*;
        use crate::io;
 
        #[test]
        fn test_channel_id_v1_from_funding_txid() {
                let channel_id = ChannelId::v1_from_funding_txid(&[2; 32], 1);
-               assert_eq!(channel_id.to_hex(), "0202020202020202020202020202020202020202020202020202020202020203");
+               assert_eq!(channel_id.0.as_hex().to_string(), "0202020202020202020202020202020202020202020202020202020202020203");
        }
 
        #[test]
index bad5e2f12841c811e082c2dafbda528ecbff5250..077f8bc155b0c0bbb6691d45761d18c607721480 100644 (file)
 //! on-chain transactions (it only monitors the chain to watch for any force-closes that might
 //! imply it needs to fail HTLCs/payments/channels it manages).
 
-use bitcoin::blockdata::block::BlockHeader;
+use bitcoin::blockdata::block::Header;
 use bitcoin::blockdata::transaction::Transaction;
 use bitcoin::blockdata::constants::ChainHash;
+use bitcoin::key::constants::SECRET_KEY_SIZE;
 use bitcoin::network::constants::Network;
 
 use bitcoin::hashes::Hash;
@@ -28,7 +29,7 @@ use bitcoin::hash_types::{BlockHash, Txid};
 
 use bitcoin::secp256k1::{SecretKey,PublicKey};
 use bitcoin::secp256k1::Secp256k1;
-use bitcoin::{LockTime, secp256k1, Sequence};
+use bitcoin::{secp256k1, Sequence};
 
 use crate::blinded_path::BlindedPath;
 use crate::blinded_path::payment::{PaymentConstraints, ReceiveTlvs};
@@ -313,7 +314,7 @@ impl Readable for InterceptId {
 /// Uniquely describes an HTLC by its source. Just the guaranteed-unique subset of [`HTLCSource`].
 pub(crate) enum SentHTLCId {
        PreviousHopData { short_channel_id: u64, htlc_id: u64 },
-       OutboundRoute { session_priv: SecretKey },
+       OutboundRoute { session_priv: [u8; SECRET_KEY_SIZE] },
 }
 impl SentHTLCId {
        pub(crate) fn from_source(source: &HTLCSource) -> Self {
@@ -323,7 +324,7 @@ impl SentHTLCId {
                                htlc_id: hop_data.htlc_id,
                        },
                        HTLCSource::OutboundRoute { session_priv, .. } =>
-                               Self::OutboundRoute { session_priv: *session_priv },
+                               Self::OutboundRoute { session_priv: session_priv.secret_bytes() },
                }
        }
 }
@@ -3751,7 +3752,10 @@ where
                        // lower than the next block height. However, the modules constituting our Lightning
                        // node might not have perfect sync about their blockchain views. Thus, if the wallet
                        // module is ahead of LDK, only allow one more block of headroom.
-                       if !funding_transaction.input.iter().all(|input| input.sequence == Sequence::MAX) && LockTime::from(funding_transaction.lock_time).is_block_height() && funding_transaction.lock_time.0 > height + 1 {
+                       if !funding_transaction.input.iter().all(|input| input.sequence == Sequence::MAX) &&
+                               funding_transaction.lock_time.is_block_height() &&
+                               funding_transaction.lock_time.to_consensus_u32() > height + 1
+                       {
                                result = result.and(Err(APIError::APIMisuseError {
                                        err: "Funding transaction absolute timelock is non-final".to_owned()
                                }));
@@ -4140,7 +4144,7 @@ where
                                                                                                ) {
                                                                                                        Ok(res) => res,
                                                                                                        Err(onion_utils::OnionDecodeErr::Malformed { err_msg, err_code }) => {
-                                                                                                               let sha256_of_onion = Sha256::hash(&onion_packet.hop_data).into_inner();
+                                                                                                               let sha256_of_onion = Sha256::hash(&onion_packet.hop_data).to_byte_array();
                                                                                                                // In this scenario, the phantom would have sent us an
                                                                                                                // `update_fail_malformed_htlc`, meaning here we encrypt the error as
                                                                                                                // if it came from us (the second-to-last hop) but contains the sha256
@@ -5163,7 +5167,7 @@ where
        }
 
        fn claim_payment_internal(&self, payment_preimage: PaymentPreimage, custom_tlvs_known: bool) {
-               let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0).into_inner());
+               let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0).to_byte_array());
 
                let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
 
@@ -6556,7 +6560,7 @@ where
                                                        if !is_our_scid && forward_info.incoming_amt_msat.is_some() &&
                                                           fake_scid::is_valid_intercept(&self.fake_scid_rand_bytes, scid, &self.chain_hash)
                                                        {
-                                                               let intercept_id = InterceptId(Sha256::hash(&forward_info.incoming_shared_secret).into_inner());
+                                                               let intercept_id = InterceptId(Sha256::hash(&forward_info.incoming_shared_secret).to_byte_array());
                                                                let mut pending_intercepts = self.pending_intercepted_htlcs.lock().unwrap();
                                                                match pending_intercepts.entry(intercept_id) {
                                                                        hash_map::Entry::Vacant(entry) => {
@@ -7900,7 +7904,7 @@ fn create_recv_pending_htlc_info(
                // could discover the final destination of X, by probing the adjacent nodes on the route
                // with a keysend payment of identical payment hash to X and observing the processing
                // time discrepancies due to a hash collision with X.
-               let hashed_preimage = PaymentHash(Sha256::hash(&payment_preimage.0).into_inner());
+               let hashed_preimage = PaymentHash(Sha256::hash(&payment_preimage.0).to_byte_array());
                if hashed_preimage != payment_hash {
                        return Err(InboundOnionErr {
                                err_code: 0x4000|22,
@@ -8029,7 +8033,7 @@ where
                                return Err(HTLCFailureMsg::Malformed(msgs::UpdateFailMalformedHTLC {
                                        channel_id: msg.channel_id,
                                        htlc_id: msg.htlc_id,
-                                       sha256_of_onion: Sha256::hash(&msg.onion_routing_packet.hop_data).into_inner(),
+                                       sha256_of_onion: Sha256::hash(&msg.onion_routing_packet.hop_data).to_byte_array(),
                                        failure_code: $err_code,
                                }));
                        }
@@ -8231,7 +8235,7 @@ where
        R::Target: Router,
        L::Target: Logger,
 {
-       fn filtered_block_connected(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) {
+       fn filtered_block_connected(&self, header: &Header, txdata: &TransactionData, height: u32) {
                {
                        let best_block = self.best_block.read().unwrap();
                        assert_eq!(best_block.block_hash(), header.prev_blockhash,
@@ -8244,7 +8248,7 @@ where
                self.best_block_updated(header, height);
        }
 
-       fn block_disconnected(&self, header: &BlockHeader, height: u32) {
+       fn block_disconnected(&self, header: &Header, height: u32) {
                let _persistence_guard =
                        PersistenceNotifierGuard::optionally_notify_skipping_background_events(
                                self, || -> NotifyOption { NotifyOption::DoPersist });
@@ -8273,7 +8277,7 @@ where
        R::Target: Router,
        L::Target: Logger,
 {
-       fn transactions_confirmed(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) {
+       fn transactions_confirmed(&self, header: &Header, txdata: &TransactionData, height: u32) {
                // Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
                // during initialization prior to the chain_monitor being fully configured in some cases.
                // See the docs for `ChannelManagerReadArgs` for more.
@@ -8294,7 +8298,7 @@ where
                }
        }
 
-       fn best_block_updated(&self, header: &BlockHeader, height: u32) {
+       fn best_block_updated(&self, header: &Header, height: u32) {
                // Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
                // during initialization prior to the chain_monitor being fully configured in some cases.
                // See the docs for `ChannelManagerReadArgs` for more.
@@ -11468,7 +11472,7 @@ mod tests {
 
                let test_preimage = PaymentPreimage([42; 32]);
                let test_secret = PaymentSecret([43; 32]);
-               let payment_hash = PaymentHash(Sha256::hash(&test_preimage.0).into_inner());
+               let payment_hash = PaymentHash(Sha256::hash(&test_preimage.0).to_byte_array());
                let session_privs = nodes[0].node.test_add_new_pending_payment(payment_hash,
                        RecipientOnionFields::secret_only(test_secret), PaymentId(payment_hash.0), &route).unwrap();
                nodes[0].node.test_send_payment_internal(&route, payment_hash,
@@ -11600,7 +11604,7 @@ mod tests {
                nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel);
 
                let (temporary_channel_id, tx, _funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 1_000_000, 42);
-               let channel_id = ChannelId::from_bytes(tx.txid().into_inner());
+               let channel_id = ChannelId::from_bytes(tx.txid().to_byte_array());
                {
                        // Ensure that the `id_to_peer` map is empty until either party has received the
                        // funding transaction, and have the real `channel_id`.
@@ -12393,7 +12397,7 @@ mod tests {
                let recipient_onion = RecipientOnionFields::secret_only(pay_secret);
                let preimage_bytes = [43; 32];
                let preimage = PaymentPreimage(preimage_bytes);
-               let rhash_bytes = Sha256::hash(&preimage_bytes).into_inner();
+               let rhash_bytes = Sha256::hash(&preimage_bytes).to_byte_array();
                let payment_hash = PaymentHash(rhash_bytes);
                let prng_seed = [44; 32];
 
@@ -12459,9 +12463,10 @@ pub mod bench {
        use crate::util::test_utils;
        use crate::util::config::{UserConfig, MaxDustHTLCExposure};
 
+       use bitcoin::blockdata::locktime::absolute::LockTime;
        use bitcoin::hashes::Hash;
        use bitcoin::hashes::sha256::Hash as Sha256;
-       use bitcoin::{Block, BlockHeader, PackedLockTime, Transaction, TxMerkleNode, TxOut};
+       use bitcoin::{Block, Transaction, TxOut};
 
        use crate::sync::{Arc, Mutex, RwLock};
 
@@ -12538,7 +12543,7 @@ pub mod bench {
 
                let tx;
                if let Event::FundingGenerationReady { temporary_channel_id, output_script, .. } = get_event!(node_a_holder, Event::FundingGenerationReady) {
-                       tx = Transaction { version: 2, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: vec![TxOut {
+                       tx = Transaction { version: 2, lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut {
                                value: 8_000_000, script_pubkey: output_script,
                        }]};
                        node_a.funding_transaction_generated(&temporary_channel_id, &node_b.get_our_node_id(), tx.clone()).unwrap();
@@ -12611,7 +12616,7 @@ pub mod bench {
                                let mut payment_preimage = PaymentPreimage([0; 32]);
                                payment_preimage.0[0..8].copy_from_slice(&payment_count.to_le_bytes());
                                payment_count += 1;
-                               let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner());
+                               let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).to_byte_array());
                                let payment_secret = $node_b.create_inbound_payment_for_hash(payment_hash, None, 7200, None).unwrap();
 
                                $node_a.send_payment(payment_hash, RecipientOnionFields::secret_only(payment_secret),
index 4dadd054ce219bef867e09f9ac01e91e4613665b..f48c9ec7059d2f7d07ad08d2498a2ce2f897337a 100644 (file)
@@ -33,12 +33,14 @@ use crate::util::ser::{ReadableArgs, Writeable};
 #[cfg(test)]
 use crate::util::logger::Logger;
 
-use bitcoin::blockdata::block::{Block, BlockHeader};
-use bitcoin::blockdata::transaction::{Transaction, TxOut};
-use bitcoin::hash_types::BlockHash;
+use bitcoin::blockdata::block::{Block, Header, Version};
+use bitcoin::blockdata::locktime::absolute::LockTime;
+use bitcoin::blockdata::transaction::{Transaction, TxIn, TxOut};
+use bitcoin::hash_types::{BlockHash, TxMerkleNode};
 use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::hashes::Hash as _;
 use bitcoin::network::constants::Network;
+use bitcoin::pow::CompactTarget;
 use bitcoin::secp256k1::{PublicKey, SecretKey};
 
 use crate::io;
@@ -48,7 +50,6 @@ use alloc::rc::Rc;
 use crate::sync::{Arc, Mutex, LockTestExt, RwLock};
 use core::mem;
 use core::iter::repeat;
-use bitcoin::{PackedLockTime, TxIn, TxMerkleNode};
 
 pub const CHAN_CONFIRM_DEPTH: u32 = 10;
 
@@ -80,11 +81,18 @@ pub fn mine_transactions<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, txn: &[&Tra
 pub fn mine_transaction_without_consistency_checks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &Transaction) {
        let height = node.best_block_info().1 + 1;
        let mut block = Block {
-               header: BlockHeader { version: 0x20000000, prev_blockhash: node.best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: height, bits: 42, nonce: 42 },
+               header: Header {
+                       version: Version::NO_SOFT_FORK_SIGNALLING,
+                       prev_blockhash: node.best_block_hash(),
+                       merkle_root: TxMerkleNode::all_zeros(),
+                       time: height,
+                       bits: CompactTarget::from_consensus(42),
+                       nonce: 42,
+               },
                txdata: Vec::new(),
        };
        for _ in 0..*node.network_chan_count.borrow() { // Make sure we don't end up with channels at the same short id by offsetting by chan_count
-               block.txdata.push(Transaction { version: 0, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: Vec::new() });
+               block.txdata.push(Transaction { version: 0, lock_time: LockTime::ZERO, input: Vec::new(), output: Vec::new() });
        }
        block.txdata.push((*tx).clone());
        do_connect_block_without_consistency_checks(node, block, false);
@@ -102,7 +110,7 @@ pub fn confirm_transactions_at<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, txn:
        }
        let mut txdata = Vec::new();
        for _ in 0..*node.network_chan_count.borrow() { // Make sure we don't end up with channels at the same short id by offsetting by chan_count
-               txdata.push(Transaction { version: 0, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: Vec::new() });
+               txdata.push(Transaction { version: 0, lock_time: LockTime::ZERO, input: Vec::new(), output: Vec::new() });
        }
        for tx in txn {
                txdata.push((*tx).clone());
@@ -204,13 +212,13 @@ impl ConnectStyle {
        }
 }
 
-pub fn create_dummy_header(prev_blockhash: BlockHash, time: u32) -> BlockHeader {
-       BlockHeader {
-               version: 0x2000_0000,
+pub fn create_dummy_header(prev_blockhash: BlockHash, time: u32) -> Header {
+       Header {
+               version: Version::NO_SOFT_FORK_SIGNALLING,
                prev_blockhash,
                merkle_root: TxMerkleNode::all_zeros(),
                time,
-               bits: 42,
+               bits: CompactTarget::from_consensus(42),
                nonce: 42,
        }
 }
@@ -435,7 +443,7 @@ impl<'a, 'b, 'c> Node<'a, 'b, 'c> {
        pub fn best_block_info(&self) -> (BlockHash, u32) {
                self.blocks.lock().unwrap().last().map(|(a, b)| (a.block_hash(), *b)).unwrap()
        }
-       pub fn get_block_header(&self, height: u32) -> BlockHeader {
+       pub fn get_block_header(&self, height: u32) -> Header {
                self.blocks.lock().unwrap()[height as usize].0.header
        }
        /// Changes the channel signer's availability for the specified peer and channel.
@@ -1081,7 +1089,7 @@ fn internal_create_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>,
                                Vec::new()
                        };
 
-                       let tx = Transaction { version: chan_id as i32, lock_time: PackedLockTime::ZERO, input, output: vec![TxOut {
+                       let tx = Transaction { version: chan_id as i32, lock_time: LockTime::ZERO, input, output: vec![TxOut {
                                value: *channel_value_satoshis, script_pubkey: output_script.clone(),
                        }]};
                        let funding_outpoint = OutPoint { txid: tx.txid(), index: 0 };
@@ -1407,7 +1415,7 @@ pub fn do_check_spends<F: Fn(&bitcoin::blockdata::transaction::OutPoint) -> Opti
        for output in tx.output.iter() {
                total_value_out += output.value;
        }
-       let min_fee = (tx.weight() as u64 + 3) / 4; // One sat per vbyte (ie per weight/4, rounded up)
+       let min_fee = (tx.weight().to_wu() as u64 + 3) / 4; // One sat per vbyte (ie per weight/4, rounded up)
        // Input amount - output amount = fee, so check that out + min_fee is smaller than input
        assert!(total_value_out + min_fee <= total_value_in);
        tx.verify(get_output).unwrap();
@@ -1923,7 +1931,7 @@ pub fn get_payment_preimage_hash(recipient: &Node, min_value_msat: Option<u64>,
        let mut payment_count = recipient.network_payment_count.borrow_mut();
        let payment_preimage = PaymentPreimage([*payment_count; 32]);
        *payment_count += 1;
-       let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner());
+       let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).to_byte_array());
        let payment_secret = recipient.node.create_inbound_payment_for_hash(payment_hash, min_value_msat, 7200, min_final_cltv_expiry_delta).unwrap();
        (payment_preimage, payment_hash, payment_secret)
 }
@@ -2045,7 +2053,7 @@ pub fn expect_payment_sent<CM: AChannelManager, H: NodeHolder<CM=CM>>(node: &H,
 ) {
        let events = node.node().get_and_clear_pending_events();
        let expected_payment_hash = PaymentHash(
-               bitcoin::hashes::sha256::Hash::hash(&expected_payment_preimage.0).into_inner());
+               bitcoin::hashes::sha256::Hash::hash(&expected_payment_preimage.0).to_byte_array());
        if expect_per_path_claims {
                assert!(events.len() > 1);
        } else {
@@ -2975,9 +2983,9 @@ pub fn test_txn_broadcast<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, chan: &(msgs::Cha
                        if tx.input.len() == 1 && tx.input[0].previous_output.txid == res[0].txid() {
                                check_spends!(tx, res[0]);
                                if has_htlc_tx == HTLCType::TIMEOUT {
-                                       assert!(tx.lock_time.0 != 0);
+                                       assert_ne!(tx.lock_time, LockTime::ZERO);
                                } else {
-                                       assert!(tx.lock_time.0 == 0);
+                                       assert_eq!(tx.lock_time, LockTime::ZERO);
                                }
                                res.push(tx.clone());
                                false
@@ -3485,7 +3493,7 @@ pub fn create_batch_channel_funding<'a, 'b, 'c>(
        // Compose the batch funding transaction and give it to the ChannelManager.
        let tx = Transaction {
                version: 2,
-               lock_time: PackedLockTime::ZERO,
+               lock_time: LockTime::ZERO,
                input: Vec::new(),
                output: tx_outs,
        };
index 98bb83a7f9d466f802499328dcabd9452528f9a9..8e78f48e68561ecb8a861b14ae07866a76b2ff8b 100644 (file)
@@ -38,11 +38,12 @@ use crate::util::string::UntrustedString;
 use crate::util::config::{UserConfig, MaxDustHTLCExposure};
 
 use bitcoin::hash_types::BlockHash;
-use bitcoin::blockdata::script::{Builder, Script};
+use bitcoin::blockdata::locktime::absolute::LockTime;
+use bitcoin::blockdata::script::{Builder, ScriptBuf};
 use bitcoin::blockdata::opcodes;
 use bitcoin::blockdata::constants::ChainHash;
 use bitcoin::network::constants::Network;
-use bitcoin::{PackedLockTime, Sequence, Transaction, TxIn, TxOut, Witness};
+use bitcoin::{Sequence, Transaction, TxIn, TxOut, Witness};
 use bitcoin::OutPoint as BitcoinOutPoint;
 
 use bitcoin::secp256k1::Secp256k1;
@@ -2860,8 +2861,8 @@ fn test_htlc_on_chain_success() {
        assert_eq!(node_txn[1].input[0].witness.clone().last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT);
        assert!(node_txn[0].output[0].script_pubkey.is_v0_p2wsh()); // revokeable output
        assert!(node_txn[1].output[0].script_pubkey.is_v0_p2wsh()); // revokeable output
-       assert_eq!(node_txn[0].lock_time.0, 0);
-       assert_eq!(node_txn[1].lock_time.0, 0);
+       assert_eq!(node_txn[0].lock_time, LockTime::ZERO);
+       assert_eq!(node_txn[1].lock_time, LockTime::ZERO);
 
        // Verify that B's ChannelManager is able to extract preimage from HTLC Success tx and pass it backward
        connect_block(&nodes[1], &create_dummy_block(nodes[1].best_block_hash(), 42, vec![commitment_tx[0].clone(), node_txn[0].clone(), node_txn[1].clone()]));
@@ -2942,8 +2943,8 @@ fn test_htlc_on_chain_success() {
                        // Node[0]: 2 * HTLC-timeout tx
                        check_spends!(node_txn[0], $commitment_tx);
                        check_spends!(node_txn[1], $commitment_tx);
-                       assert_ne!(node_txn[0].lock_time.0, 0);
-                       assert_ne!(node_txn[1].lock_time.0, 0);
+                       assert_ne!(node_txn[0].lock_time, LockTime::ZERO);
+                       assert_ne!(node_txn[1].lock_time, LockTime::ZERO);
                        if $htlc_offered {
                                assert_eq!(node_txn[0].input[0].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT);
                                assert_eq!(node_txn[1].input[0].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT);
@@ -2994,7 +2995,7 @@ fn test_htlc_on_chain_success() {
        assert_eq!(commitment_spend.input.len(), 2);
        assert_eq!(commitment_spend.input[0].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT);
        assert_eq!(commitment_spend.input[1].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT);
-       assert_eq!(commitment_spend.lock_time.0, nodes[1].best_block_info().1);
+       assert_eq!(commitment_spend.lock_time.to_consensus_u32(), nodes[1].best_block_info().1);
        assert!(commitment_spend.output[0].script_pubkey.is_v0_p2wpkh()); // direct payment
        // We don't bother to check that B can claim the HTLC output on its commitment tx here as
        // we already checked the same situation with A.
@@ -3647,7 +3648,7 @@ fn test_force_close_fail_back() {
        assert_eq!(node_txn.len(), 1);
        assert_eq!(node_txn[0].input.len(), 1);
        assert_eq!(node_txn[0].input[0].previous_output.txid, tx.txid());
-       assert_eq!(node_txn[0].lock_time.0, 0); // Must be an HTLC-Success
+       assert_eq!(node_txn[0].lock_time, LockTime::ZERO); // Must be an HTLC-Success
        assert_eq!(node_txn[0].input[0].witness.len(), 5); // Must be an HTLC-Success
 
        check_spends!(node_txn[0], tx);
@@ -4729,7 +4730,7 @@ fn test_static_spendable_outputs_justice_tx_revoked_htlc_timeout_tx() {
        assert_eq!(revoked_htlc_txn[0].input.len(), 1);
        assert_eq!(revoked_htlc_txn[0].input[0].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT);
        check_spends!(revoked_htlc_txn[0], revoked_local_txn[0]);
-       assert_ne!(revoked_htlc_txn[0].lock_time.0, 0); // HTLC-Timeout
+       assert_ne!(revoked_htlc_txn[0].lock_time, LockTime::ZERO); // HTLC-Timeout
 
        // B will generate justice tx from A's revoked commitment/HTLC tx
        connect_block(&nodes[1], &create_dummy_block(nodes[1].best_block_hash(), 42, vec![revoked_local_txn[0].clone(), revoked_htlc_txn[0].clone()]));
@@ -4892,7 +4893,7 @@ fn test_onchain_to_onchain_claim() {
        check_spends!(c_txn[0], commitment_tx[0]);
        assert_eq!(c_txn[0].input[0].witness.clone().last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT);
        assert!(c_txn[0].output[0].script_pubkey.is_v0_p2wsh()); // revokeable output
-       assert_eq!(c_txn[0].lock_time.0, 0); // Success tx
+       assert_eq!(c_txn[0].lock_time, LockTime::ZERO); // Success tx
 
        // So we broadcast C's commitment tx and HTLC-Success on B's chain, we should successfully be able to extract preimage and update downstream monitor
        connect_block(&nodes[1], &create_dummy_block(nodes[1].best_block_hash(), 42, vec![commitment_tx[0].clone(), c_txn[0].clone()]));
@@ -4951,7 +4952,7 @@ fn test_onchain_to_onchain_claim() {
        check_spends!(b_txn[0], commitment_tx[0]);
        assert_eq!(b_txn[0].input[0].witness.clone().last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT);
        assert!(b_txn[0].output[0].script_pubkey.is_v0_p2wpkh()); // direct payment
-       assert_eq!(b_txn[0].lock_time.0, nodes[1].best_block_info().1); // Success tx
+       assert_eq!(b_txn[0].lock_time.to_consensus_u32(), nodes[1].best_block_info().1); // Success tx
 
        check_closed_broadcast!(nodes[1], true);
        check_added_monitors!(nodes[1], 1);
@@ -7122,7 +7123,7 @@ fn do_test_sweep_outbound_htlc_failure_update(revoked: bool, local: bool) {
                if !revoked {
                        assert_eq!(timeout_tx[0].input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT);
                } else {
-                       assert_eq!(timeout_tx[0].lock_time.0, 11);
+                       assert_eq!(timeout_tx[0].lock_time.to_consensus_u32(), 11);
                }
                // We fail non-dust-HTLC 2 by broadcast of local timeout/revocation-claim tx
                mine_transaction(&nodes[0], &timeout_tx[0]);
@@ -7416,7 +7417,7 @@ fn test_bump_penalty_txn_on_revoked_commitment() {
                assert_eq!(node_txn[0].output.len(), 1);
                check_spends!(node_txn[0], revoked_txn[0]);
                let fee_1 = penalty_sum - node_txn[0].output[0].value;
-               feerate_1 = fee_1 * 1000 / node_txn[0].weight() as u64;
+               feerate_1 = fee_1 * 1000 / node_txn[0].weight().to_wu();
                penalty_1 = node_txn[0].txid();
                node_txn.clear();
        };
@@ -7436,7 +7437,7 @@ fn test_bump_penalty_txn_on_revoked_commitment() {
                        // Verify new bumped tx is different from last claiming transaction, we don't want spurrious rebroadcast
                        assert_ne!(penalty_2, penalty_1);
                        let fee_2 = penalty_sum - node_txn[0].output[0].value;
-                       feerate_2 = fee_2 * 1000 / node_txn[0].weight() as u64;
+                       feerate_2 = fee_2 * 1000 / node_txn[0].weight().to_wu();
                        // Verify 25% bump heuristic
                        assert!(feerate_2 * 100 >= feerate_1 * 125);
                        node_txn.clear();
@@ -7459,7 +7460,7 @@ fn test_bump_penalty_txn_on_revoked_commitment() {
                        // Verify new bumped tx is different from last claiming transaction, we don't want spurrious rebroadcast
                        assert_ne!(penalty_3, penalty_2);
                        let fee_3 = penalty_sum - node_txn[0].output[0].value;
-                       feerate_3 = fee_3 * 1000 / node_txn[0].weight() as u64;
+                       feerate_3 = fee_3 * 1000 / node_txn[0].weight().to_wu();
                        // Verify 25% bump heuristic
                        assert!(feerate_3 * 100 >= feerate_2 * 125);
                        node_txn.clear();
@@ -7578,7 +7579,7 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
                first = node_txn[3].txid();
                // Store both feerates for later comparison
                let fee_1 = revoked_htlc_txn[0].output[0].value + revoked_htlc_txn[1].output[0].value - node_txn[3].output[0].value;
-               feerate_1 = fee_1 * 1000 / node_txn[3].weight() as u64;
+               feerate_1 = fee_1 * 1000 / node_txn[3].weight().to_wu();
                penalty_txn = vec![node_txn[2].clone()];
                node_txn.clear();
        }
@@ -7602,7 +7603,7 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
                // Verify bumped tx is different and 25% bump heuristic
                assert_ne!(first, node_txn[0].txid());
                let fee_2 = revoked_htlc_txn[0].output[0].value + revoked_htlc_txn[1].output[0].value - node_txn[0].output[0].value;
-               let feerate_2 = fee_2 * 1000 / node_txn[0].weight() as u64;
+               let feerate_2 = fee_2 * 1000 / node_txn[0].weight().to_wu();
                assert!(feerate_2 * 100 > feerate_1 * 125);
                let txn = vec![node_txn[0].clone()];
                node_txn.clear();
@@ -7678,7 +7679,7 @@ fn test_bump_penalty_txn_on_remote_commitment() {
                preimage = node_txn[0].txid();
                let index = node_txn[0].input[0].previous_output.vout;
                let fee = remote_txn[0].output[index as usize].value - node_txn[0].output[0].value;
-               feerate_preimage = fee * 1000 / node_txn[0].weight() as u64;
+               feerate_preimage = fee * 1000 / node_txn[0].weight().to_wu();
 
                let (preimage_bump_tx, timeout_tx) = if node_txn[2].input[0].previous_output == node_txn[0].input[0].previous_output {
                        (node_txn[2].clone(), node_txn[1].clone())
@@ -7693,7 +7694,7 @@ fn test_bump_penalty_txn_on_remote_commitment() {
                timeout = timeout_tx.txid();
                let index = timeout_tx.input[0].previous_output.vout;
                let fee = remote_txn[0].output[index as usize].value - timeout_tx.output[0].value;
-               feerate_timeout = fee * 1000 / timeout_tx.weight() as u64;
+               feerate_timeout = fee * 1000 / timeout_tx.weight().to_wu();
 
                node_txn.clear();
        };
@@ -7712,13 +7713,13 @@ fn test_bump_penalty_txn_on_remote_commitment() {
 
                let index = preimage_bump.input[0].previous_output.vout;
                let fee = remote_txn[0].output[index as usize].value - preimage_bump.output[0].value;
-               let new_feerate = fee * 1000 / preimage_bump.weight() as u64;
+               let new_feerate = fee * 1000 / preimage_bump.weight().to_wu();
                assert!(new_feerate * 100 > feerate_timeout * 125);
                assert_ne!(timeout, preimage_bump.txid());
 
                let index = node_txn[0].input[0].previous_output.vout;
                let fee = remote_txn[0].output[index as usize].value - node_txn[0].output[0].value;
-               let new_feerate = fee * 1000 / node_txn[0].weight() as u64;
+               let new_feerate = fee * 1000 / node_txn[0].weight().to_wu();
                assert!(new_feerate * 100 > feerate_preimage * 125);
                assert_ne!(preimage, node_txn[0].txid());
 
@@ -9182,10 +9183,10 @@ fn test_invalid_funding_tx() {
        // a panic as we'd try to extract a 32 byte preimage from a witness element without checking
        // its length.
        let mut wit_program: Vec<u8> = channelmonitor::deliberately_bogus_accepted_htlc_witness_program();
-       let wit_program_script: Script = wit_program.into();
+       let wit_program_script: ScriptBuf = wit_program.into();
        for output in tx.output.iter_mut() {
                // Make the confirmed funding transaction have a bogus script_pubkey
-               output.script_pubkey = Script::new_v0_p2wsh(&wit_program_script.wscript_hash());
+               output.script_pubkey = ScriptBuf::new_v0_p2wsh(&wit_program_script.wscript_hash());
        }
 
        nodes[0].node.funding_transaction_generated_unchecked(&temporary_channel_id, &nodes[1].node.get_our_node_id(), tx.clone(), 0).unwrap();
@@ -9223,19 +9224,19 @@ fn test_invalid_funding_tx() {
        // long the ChannelMonitor will try to read 32 bytes from the second-to-last element, panicing
        // as its not 32 bytes long.
        let mut spend_tx = Transaction {
-               version: 2i32, lock_time: PackedLockTime::ZERO,
+               version: 2i32, lock_time: LockTime::ZERO,
                input: tx.output.iter().enumerate().map(|(idx, _)| TxIn {
                        previous_output: BitcoinOutPoint {
                                txid: tx.txid(),
                                vout: idx as u32,
                        },
-                       script_sig: Script::new(),
+                       script_sig: ScriptBuf::new(),
                        sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
-                       witness: Witness::from_vec(channelmonitor::deliberately_bogus_accepted_htlc_witness())
+                       witness: Witness::from_slice(&channelmonitor::deliberately_bogus_accepted_htlc_witness())
                }).collect(),
                output: vec![TxOut {
                        value: 1000,
-                       script_pubkey: Script::new(),
+                       script_pubkey: ScriptBuf::new(),
                }]
        };
        check_spends!(spend_tx, tx);
@@ -9883,12 +9884,12 @@ fn test_non_final_funding_tx() {
 
        let chan_id = *nodes[0].network_chan_count.borrow();
        let events = nodes[0].node.get_and_clear_pending_events();
-       let input = TxIn { previous_output: BitcoinOutPoint::null(), script_sig: bitcoin::Script::new(), sequence: Sequence(1), witness: Witness::from_vec(vec!(vec!(1))) };
+       let input = TxIn { previous_output: BitcoinOutPoint::null(), script_sig: bitcoin::ScriptBuf::new(), sequence: Sequence(1), witness: Witness::from_slice(&[&[1]]) };
        assert_eq!(events.len(), 1);
        let mut tx = match events[0] {
                Event::FundingGenerationReady { ref channel_value_satoshis, ref output_script, .. } => {
                        // Timelock the transaction _beyond_ the best client height + 1.
-                       Transaction { version: chan_id as i32, lock_time: PackedLockTime(best_height + 2), input: vec![input], output: vec![TxOut {
+                       Transaction { version: chan_id as i32, lock_time: LockTime::from_height(best_height + 2).unwrap(), input: vec![input], output: vec![TxOut {
                                value: *channel_value_satoshis, script_pubkey: output_script.clone(),
                        }]}
                },
@@ -9928,12 +9929,12 @@ fn test_non_final_funding_tx_within_headroom() {
 
        let chan_id = *nodes[0].network_chan_count.borrow();
        let events = nodes[0].node.get_and_clear_pending_events();
-       let input = TxIn { previous_output: BitcoinOutPoint::null(), script_sig: bitcoin::Script::new(), sequence: Sequence(1), witness: Witness::from_vec(vec!(vec!(1))) };
+       let input = TxIn { previous_output: BitcoinOutPoint::null(), script_sig: bitcoin::ScriptBuf::new(), sequence: Sequence(1), witness: Witness::from_slice(&[[1]]) };
        assert_eq!(events.len(), 1);
        let mut tx = match events[0] {
                Event::FundingGenerationReady { ref channel_value_satoshis, ref output_script, .. } => {
                        // Timelock the transaction within a +1 headroom from the best block.
-                       Transaction { version: chan_id as i32, lock_time: PackedLockTime(best_height + 1), input: vec![input], output: vec![TxOut {
+                       Transaction { version: chan_id as i32, lock_time: LockTime::from_consensus(best_height + 1), input: vec![input], output: vec![TxOut {
                                value: *channel_value_satoshis, script_pubkey: output_script.clone(),
                        }]}
                },
index f9e10880afbe5f5eae122d48220f5b8e5dcd9757..2ee93a6c46efca8ef2c1d6904f7c7d6553205ca1 100644 (file)
@@ -199,9 +199,9 @@ pub fn create<ES: Deref>(keys: &ExpandedKey, min_value_msat: Option<u64>,
        let mut hmac = HmacEngine::<Sha256>::new(&keys.ldk_pmt_hash_key);
        hmac.input(&iv_bytes);
        hmac.input(&metadata_bytes);
-       let payment_preimage_bytes = Hmac::from_engine(hmac).into_inner();
+       let payment_preimage_bytes = Hmac::from_engine(hmac).to_byte_array();
 
-       let ldk_pmt_hash = PaymentHash(Sha256::hash(&payment_preimage_bytes).into_inner());
+       let ldk_pmt_hash = PaymentHash(Sha256::hash(&payment_preimage_bytes).to_byte_array());
        let payment_secret = construct_payment_secret(&iv_bytes, &metadata_bytes, &keys.metadata_key);
        Ok((ldk_pmt_hash, payment_secret))
 }
@@ -227,7 +227,7 @@ pub fn create_from_hash(keys: &ExpandedKey, min_value_msat: Option<u64>, payment
        let mut hmac = HmacEngine::<Sha256>::new(&keys.user_pmt_hash_key);
        hmac.input(&metadata_bytes);
        hmac.input(&payment_hash.0);
-       let hmac_bytes = Hmac::from_engine(hmac).into_inner();
+       let hmac_bytes = Hmac::from_engine(hmac).to_byte_array();
 
        let mut iv_bytes = [0 as u8; IV_LEN];
        iv_bytes.copy_from_slice(&hmac_bytes[..IV_LEN]);
@@ -350,7 +350,7 @@ pub(super) fn verify<L: Deref>(payment_hash: PaymentHash, payment_data: &msgs::F
                        let mut hmac = HmacEngine::<Sha256>::new(&keys.user_pmt_hash_key);
                        hmac.input(&metadata_bytes[..]);
                        hmac.input(&payment_hash.0);
-                       if !fixed_time_eq(&iv_bytes, &Hmac::from_engine(hmac).into_inner().split_at_mut(IV_LEN).0) {
+                       if !fixed_time_eq(&iv_bytes, &Hmac::from_engine(hmac).to_byte_array().split_at_mut(IV_LEN).0) {
                                log_trace!(logger, "Failing HTLC with user-generated payment_hash {}: unexpected payment_secret", &payment_hash);
                                return Err(())
                        }
@@ -432,8 +432,8 @@ fn derive_ldk_payment_preimage(payment_hash: PaymentHash, iv_bytes: &[u8; IV_LEN
        let mut hmac = HmacEngine::<Sha256>::new(&keys.ldk_pmt_hash_key);
        hmac.input(iv_bytes);
        hmac.input(metadata_bytes);
-       let decoded_payment_preimage = Hmac::from_engine(hmac).into_inner();
-       if !fixed_time_eq(&payment_hash.0, &Sha256::hash(&decoded_payment_preimage).into_inner()) {
+       let decoded_payment_preimage = Hmac::from_engine(hmac).to_byte_array();
+       if !fixed_time_eq(&payment_hash.0, &Sha256::hash(&decoded_payment_preimage).to_byte_array()) {
                return Err(decoded_payment_preimage);
        }
        return Ok(PaymentPreimage(decoded_payment_preimage))
index 60caed4dbdc8c0fe4974137a233bc733e8886603..ad5f03a5cf6b0c4255421a1ceb12e40b58e9575b 100644 (file)
@@ -24,12 +24,13 @@ use crate::util::ser::Writeable;
 use crate::util::scid_utils::block_from_scid;
 use crate::util::test_utils;
 
-use bitcoin::blockdata::transaction::EcdsaSighashType;
+use bitcoin::{Amount, PublicKey, ScriptBuf, Transaction, TxIn, TxOut, Witness};
+use bitcoin::blockdata::locktime::absolute::LockTime;
 use bitcoin::blockdata::script::Builder;
 use bitcoin::blockdata::opcodes;
+use bitcoin::hashes::hex::FromHex;
 use bitcoin::secp256k1::{Secp256k1, SecretKey};
-use bitcoin::{Amount, PublicKey, Script, Transaction, TxIn, TxOut, PackedLockTime, Witness};
-use bitcoin::util::sighash::SighashCache;
+use bitcoin::sighash::{SighashCache, EcdsaSighashType};
 
 use crate::prelude::*;
 
@@ -305,7 +306,7 @@ fn do_test_claim_value_force_close(anchors: bool, prev_commitment_tx: bool) {
 
        let coinbase_tx = Transaction {
                version: 2,
-               lock_time: PackedLockTime::ZERO,
+               lock_time: LockTime::ZERO,
                input: vec![TxIn { ..Default::default() }],
                output: vec![
                        TxOut {
@@ -666,7 +667,7 @@ fn do_test_balances_on_local_commitment_htlcs(anchors: bool) {
 
        let coinbase_tx = Transaction {
                version: 2,
-               lock_time: PackedLockTime::ZERO,
+               lock_time: LockTime::ZERO,
                input: vec![TxIn { ..Default::default() }],
                output: vec![
                        TxOut {
@@ -1223,23 +1224,23 @@ fn do_test_revoked_counterparty_commitment_balances(anchors: bool, confirm_htlc_
        claim_txn.sort_unstable_by_key(|tx| tx.output.iter().map(|output| output.value).sum::<u64>());
 
        // The following constants were determined experimentally
-       const BS_TO_SELF_CLAIM_EXP_WEIGHT: usize = 483;
-       let outbound_htlc_claim_exp_weight: usize = if anchors { 574 } else { 571 };
-       let inbound_htlc_claim_exp_weight: usize = if anchors { 582 } else { 578 };
+       const BS_TO_SELF_CLAIM_EXP_WEIGHT: u64 = 483;
+       let outbound_htlc_claim_exp_weight: u64 = if anchors { 574 } else { 571 };
+       let inbound_htlc_claim_exp_weight: u64 = if anchors { 582 } else { 578 };
 
        // Check that the weight is close to the expected weight. Note that signature sizes vary
        // somewhat so it may not always be exact.
-       fuzzy_assert_eq(claim_txn[0].weight(), outbound_htlc_claim_exp_weight);
-       fuzzy_assert_eq(claim_txn[1].weight(), inbound_htlc_claim_exp_weight);
-       fuzzy_assert_eq(claim_txn[2].weight(), inbound_htlc_claim_exp_weight);
-       fuzzy_assert_eq(claim_txn[3].weight(), BS_TO_SELF_CLAIM_EXP_WEIGHT);
+       fuzzy_assert_eq(claim_txn[0].weight().to_wu(), outbound_htlc_claim_exp_weight);
+       fuzzy_assert_eq(claim_txn[1].weight().to_wu(), inbound_htlc_claim_exp_weight);
+       fuzzy_assert_eq(claim_txn[2].weight().to_wu(), inbound_htlc_claim_exp_weight);
+       fuzzy_assert_eq(claim_txn[3].weight().to_wu(), BS_TO_SELF_CLAIM_EXP_WEIGHT);
 
        let commitment_tx_fee = chan_feerate *
                (channel::commitment_tx_base_weight(&channel_type_features) + 3 * channel::COMMITMENT_TX_WEIGHT_PER_HTLC) / 1000;
        let anchor_outputs_value = if anchors { channel::ANCHOR_OUTPUT_VALUE_SATOSHI * 2 } else { 0 };
-       let inbound_htlc_claim_fee = chan_feerate * inbound_htlc_claim_exp_weight as u64 / 1000;
-       let outbound_htlc_claim_fee = chan_feerate * outbound_htlc_claim_exp_weight as u64 / 1000;
-       let to_self_claim_fee = chan_feerate * claim_txn[3].weight() as u64 / 1000;
+       let inbound_htlc_claim_fee = chan_feerate * inbound_htlc_claim_exp_weight / 1000;
+       let outbound_htlc_claim_fee = chan_feerate * outbound_htlc_claim_exp_weight / 1000;
+       let to_self_claim_fee = chan_feerate * claim_txn[3].weight().to_wu() / 1000;
 
        // The expected balance for the next three checks, with the largest-HTLC and to_self output
        // claim balances separated out.
@@ -1380,7 +1381,7 @@ fn do_test_revoked_counterparty_htlc_tx_balances(anchors: bool) {
 
        let coinbase_tx = Transaction {
                version: 2,
-               lock_time: PackedLockTime::ZERO,
+               lock_time: LockTime::ZERO,
                input: vec![TxIn { ..Default::default() }],
                output: vec![
                        TxOut {
@@ -1442,7 +1443,7 @@ fn do_test_revoked_counterparty_htlc_tx_balances(anchors: bool) {
                check_spends!(txn[0], revoked_local_txn[0], coinbase_tx);
                txn.pop().unwrap()
        };
-       let revoked_htlc_success_fee = chan_feerate * revoked_htlc_success.weight() as u64 / 1000;
+       let revoked_htlc_success_fee = chan_feerate * revoked_htlc_success.weight().to_wu() / 1000;
 
        connect_blocks(&nodes[1], TEST_FINAL_CLTV);
        if anchors {
@@ -1459,8 +1460,8 @@ fn do_test_revoked_counterparty_htlc_tx_balances(anchors: bool) {
        };
        check_spends!(revoked_htlc_timeout, revoked_local_txn[0], coinbase_tx);
        assert_ne!(revoked_htlc_success.input[0].previous_output, revoked_htlc_timeout.input[0].previous_output);
-       assert_eq!(revoked_htlc_success.lock_time.0, 0);
-       assert_ne!(revoked_htlc_timeout.lock_time.0, 0);
+       assert_eq!(revoked_htlc_success.lock_time, LockTime::ZERO);
+       assert_ne!(revoked_htlc_timeout.lock_time, LockTime::ZERO);
 
        // A will generate justice tx from B's revoked commitment/HTLC tx
        mine_transaction(&nodes[0], &revoked_local_txn[0]);
@@ -1530,7 +1531,7 @@ fn do_test_revoked_counterparty_htlc_tx_balances(anchors: bool) {
                sorted_vec(nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances()));
 
        assert_eq!(as_htlc_claim_tx[0].output.len(), 1);
-       let as_revoked_htlc_success_claim_fee = chan_feerate * as_htlc_claim_tx[0].weight() as u64 / 1000;
+       let as_revoked_htlc_success_claim_fee = chan_feerate * as_htlc_claim_tx[0].weight().to_wu() / 1000;
        if anchors {
                // With anchors, B can pay for revoked_htlc_success's fee with additional inputs, rather
                // than with the HTLC itself.
@@ -1580,7 +1581,7 @@ fn do_test_revoked_counterparty_htlc_tx_balances(anchors: bool) {
                }]),
                sorted_vec(nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances()));
 
-       connect_blocks(&nodes[0], revoked_htlc_timeout.lock_time.0 - nodes[0].best_block_info().1);
+       connect_blocks(&nodes[0], revoked_htlc_timeout.lock_time.to_consensus_u32() - nodes[0].best_block_info().1);
        expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore!(&nodes[0],
                [HTLCDestination::FailedPayment { payment_hash: failed_payment_hash }]);
        // As time goes on A may split its revocation claim transaction into multiple.
@@ -1692,7 +1693,7 @@ fn do_test_revoked_counterparty_aggregated_claims(anchors: bool) {
 
        let coinbase_tx = Transaction {
                version: 2,
-               lock_time: PackedLockTime::ZERO,
+               lock_time: LockTime::ZERO,
                input: vec![TxIn { ..Default::default() }],
                output: vec![TxOut {
                        value: Amount::ONE_BTC.to_sat(),
@@ -2010,7 +2011,7 @@ fn do_test_restored_packages_retry(check_old_monitor_retries_after_upgrade: bool
        // Check that we can still rebroadcast these packages/transactions if we're upgrading from an
        // old `ChannelMonitor` that did not exercise said rebroadcasting logic.
        if check_old_monitor_retries_after_upgrade {
-               let serialized_monitor = hex::decode(
+               let serialized_monitor = <Vec<u8>>::from_hex(
                        "0101fffffffffffffffff9550f22c95100160014d5a9aa98b89acc215fc3d23d6fec0ad59ca3665f00002200204c5f18e5e95b184f34d02ba6de8a2a4e36ae3d4ec87299ad81f3284dc7195c6302d7dde8e10a5a22c9bd0d7ef5494d85683ac050253b917615d4f97af633f0a8e2035f5e9d58b4328566223c107d86cf853e6b9fae1d26ff6d969be0178d1423c4ea0016001467822698d782e8421ebdf96d010de99382b7ec2300160014caf6d80fe2bab80473b021f57588a9c384bf23170000000000000000000000004d49e5da0000000000000000000000000000002a0270b20ad0f2c2bb30a55590fc77778495bc1b38c96476901145dda57491237f0f74c52ab4f11296d62b66a6dba9513b04a3e7fb5a09a30cee22fce7294ab55b7e00000022002034c0cc0ad0dd5fe61dcf7ef58f995e3d34f8dbd24aa2a6fae68fefe102bf025c21391732ce658e1fe167300bb689a81e7db5399b9ee4095e217b0e997e8dd3d17a0000000000000000004a002103adde8029d3ee281a32e9db929b39f503ff9d7e93cd308eb157955344dc6def84022103205087e2dc1f6b9937e887dfa712c5bdfa950b01dbda3ebac4c85efdde48ee6a04020090004752210307a78def56cba9fc4db22a25928181de538ee59ba1a475ae113af7790acd0db32103c21e841cbc0b48197d060c71e116c185fa0ac281b7d0aa5924f535154437ca3b52ae00000000000186a0ffffffffffff0291e7c0a3232fb8650a6b4089568a81062b48a768780e5a74bb4a4a74e33aec2c029d5760248ec86c4a76d9df8308555785a06a65472fb995f5b392d520bbd000650090c1c94b11625690c9d84c5daa67b6ad19fcc7f9f23e194384140b08fcab9e8e810000ffffffffffff000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000002167c86cc0e598a6b541f7c9bf9ef17222e4a76f636e2d22185aeadd2b02d029c0000000000000000391732ce658e1fe167300bb689a81e7db5399b9ee4095e217b0e997e8dd3d17a00000000000000010000000000009896800000005166687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f29250500000000a0009d00202d704fbfe342a9ff6eaca14d80a24aaed0e680bbbdd36157b6f2798c61d906910120f9fe5e552aa0fc45020f0505efde432a4e373e5d393863973a6899f8c26d33d102080000000000989680044d4c00210355f8d2238a322d16b602bd0ceaad5b01019fb055971eaadcc9b29226a4da6c2302090007000000000241000408000001000000000006020000080800000000009896800a04000000460000000000000000000000000000000166687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925fffffffffffe01e3002004f8eda5676356f539169a8e9a1e86c7f125283328d6f4bded1b939b52a6a7e30108000000000000c299022103a1f98e85886df54add6908b4fc1ff515e44aedefe9eb9c02879c89994298fa79042103a650bf03971df0176c7b412247390ef717853e8bd487b204dccc2fe2078bb75206210390bbbcebe9f70ba5dfd98866a79f72f75e0a6ea550ef73b202dd87cd6477350a08210284152d57908488e666e872716a286eb670b3d06cbeebf3f2e4ad350e01ec5e5b0a2102295e2de39eb3dcc2882f8cc266df7882a8b6d2c32aa08799f49b693aad3be28e0c04000000fd0e00fd0202002045cfd42d0989e55b953f516ac7fd152bd90ec4438a2fc636f97ddd32a0c8fe0d01080000000000009b5e0221035f5e9d58b4328566223c107d86cf853e6b9fae1d26ff6d969be0178d1423c4ea04210230fde9c031f487db95ff55b7c0acbe0c7c26a8d82615e9184416bd350101616706210225afb4e88eac8b47b67adeaf085f5eb5d37d936f56138f0848de3d104edf113208210208e4687a95c172b86b920c3bc5dbd5f023094ec2cb0abdb74f9b624f45740df90a2102d7dde8e10a5a22c9bd0d7ef5494d85683ac050253b917615d4f97af633f0a8e20c04000000fd0efd011d3b00010102080000000000989680040400000051062066687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925080400000000417e2650c201383711eed2a7cb8652c3e77ee6a395e81849c5c222217ed68b333c0ca9f1e900662ae68a7359efa7ef9d90613f2a62f7c3ff90f8c25e2cc974c9d3a0009d00202d704fbfe342a9ff6eaca14d80a24aaed0e680bbbdd36157b6f2798c61d906910120f9fe5e552aa0fc45020f0505efde432a4e373e5d393863973a6899f8c26d33d102080000000000989680044d4c00210355f8d2238a322d16b602bd0ceaad5b01019fb055971eaadcc9b29226a4da6c2302090007000000000241000408000001000000000006020000080800000000009896800a0400000046fffffffffffefffffffffffe000000000000000000000000000000000000000000000000f1600ef6ea657b8d411d553516ae35cedfe86b0cd48d1f91b32772facbae757d0000000b0000000000000002fd01da002045cfd42d0989e55b953f516ac7fd152bd90ec4438a2fc636f97ddd32a0c8fe0d01fd01840200000000010174c52ab4f11296d62b66a6dba9513b04a3e7fb5a09a30cee22fce7294ab55b7e00000000000f55f9800310270000000000002200208309b406e3b96e76cde414fbb8f5159f5b25b24075656c6382cec797854d53495e9b0000000000002200204c5f18e5e95b184f34d02ba6de8a2a4e36ae3d4ec87299ad81f3284dc7195c6350c300000000000016001425df8ec4a074f80579fed67d4707d5ec8ed7e8d304004730440220671c9badf26bd3a1ebd2d17020c6be20587d7822530daacc52c28839875eaec602204b575a21729ed27311f6d79fdf6fe8702b0a798f7d842e39ede1b56f249a613401473044022016a0da36f70cbf5d889586af88f238982889dc161462c56557125c7acfcb69e9022036ae10c6cc8cbc3b27d9e9ef6babb556086585bc819f252208bd175286699fdd014752210307a78def56cba9fc4db22a25928181de538ee59ba1a475ae113af7790acd0db32103c21e841cbc0b48197d060c71e116c185fa0ac281b7d0aa5924f535154437ca3b52ae50c9222002040000000b0320f1600ef6ea657b8d411d553516ae35cedfe86b0cd48d1f91b32772facbae757d0406030400020090fd02a1002045cfd42d0989e55b953f516ac7fd152bd90ec4438a2fc636f97ddd32a0c8fe0d01fd01840200000000010174c52ab4f11296d62b66a6dba9513b04a3e7fb5a09a30cee22fce7294ab55b7e00000000000f55f9800310270000000000002200208309b406e3b96e76cde414fbb8f5159f5b25b24075656c6382cec797854d53495e9b0000000000002200204c5f18e5e95b184f34d02ba6de8a2a4e36ae3d4ec87299ad81f3284dc7195c6350c300000000000016001425df8ec4a074f80579fed67d4707d5ec8ed7e8d304004730440220671c9badf26bd3a1ebd2d17020c6be20587d7822530daacc52c28839875eaec602204b575a21729ed27311f6d79fdf6fe8702b0a798f7d842e39ede1b56f249a613401473044022016a0da36f70cbf5d889586af88f238982889dc161462c56557125c7acfcb69e9022036ae10c6cc8cbc3b27d9e9ef6babb556086585bc819f252208bd175286699fdd014752210307a78def56cba9fc4db22a25928181de538ee59ba1a475ae113af7790acd0db32103c21e841cbc0b48197d060c71e116c185fa0ac281b7d0aa5924f535154437ca3b52ae50c9222002040000000b0320f1600ef6ea657b8d411d553516ae35cedfe86b0cd48d1f91b32772facbae757d04cd01cb00c901c7002245cfd42d0989e55b953f516ac7fd152bd90ec4438a2fc636f97ddd32a0c8fe0d0001022102d7dde8e10a5a22c9bd0d7ef5494d85683ac050253b917615d4f97af633f0a8e204020090062b5e9b0000000000002200204c5f18e5e95b184f34d02ba6de8a2a4e36ae3d4ec87299ad81f3284dc7195c630821035f5e9d58b4328566223c107d86cf853e6b9fae1d26ff6d969be0178d1423c4ea0a200000000000000000000000004d49e5da0000000000000000000000000000002a0c0800000000000186a0000000000000000274c52ab4f11296d62b66a6dba9513b04a3e7fb5a09a30cee22fce7294ab55b7e0000000000000001000000000022002034c0cc0ad0dd5fe61dcf7ef58f995e3d34f8dbd24aa2a6fae68fefe102bf025c45cfd42d0989e55b953f516ac7fd152bd90ec4438a2fc636f97ddd32a0c8fe0d000000000000000100000000002200208309b406e3b96e76cde414fbb8f5159f5b25b24075656c6382cec797854d5349010100160014d5a9aa98b89acc215fc3d23d6fec0ad59ca3665ffd027100fd01e6fd01e300080000fffffffffffe02080000000000009b5e0408000000000000c3500604000000fd08b0af002102d7dde8e10a5a22c9bd0d7ef5494d85683ac050253b917615d4f97af633f0a8e20221035f5e9d58b4328566223c107d86cf853e6b9fae1d26ff6d969be0178d1423c4ea04210230fde9c031f487db95ff55b7c0acbe0c7c26a8d82615e9184416bd350101616706210225afb4e88eac8b47b67adeaf085f5eb5d37d936f56138f0848de3d104edf113208210208e4687a95c172b86b920c3bc5dbd5f023094ec2cb0abdb74f9b624f45740df90acdcc00a8020000000174c52ab4f11296d62b66a6dba9513b04a3e7fb5a09a30cee22fce7294ab55b7e00000000000f55f9800310270000000000002200208309b406e3b96e76cde414fbb8f5159f5b25b24075656c6382cec797854d53495e9b0000000000002200204c5f18e5e95b184f34d02ba6de8a2a4e36ae3d4ec87299ad81f3284dc7195c6350c300000000000016001425df8ec4a074f80579fed67d4707d5ec8ed7e8d350c92220022045cfd42d0989e55b953f516ac7fd152bd90ec4438a2fc636f97ddd32a0c8fe0d0c3c3b00010102080000000000989680040400000051062066687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f29250804000000000240671c9badf26bd3a1ebd2d17020c6be20587d7822530daacc52c28839875eaec64b575a21729ed27311f6d79fdf6fe8702b0a798f7d842e39ede1b56f249a613404010006407e2650c201383711eed2a7cb8652c3e77ee6a395e81849c5c222217ed68b333c0ca9f1e900662ae68a7359efa7ef9d90613f2a62f7c3ff90f8c25e2cc974c9d3010000000000000001010000000000000000090b2a953d93a124c600ecb1a0ccfed420169cdd37f538ad94a3e4e6318c93c14adf59cdfbb40bdd40950c9f8dd547d29d75a173e1376a7850743394c46dea2dfd01cefd01ca00fd017ffd017c00080000ffffffffffff0208000000000000c2990408000000000000c3500604000000fd08b0af002102295e2de39eb3dcc2882f8cc266df7882a8b6d2c32aa08799f49b693aad3be28e022103a1f98e85886df54add6908b4fc1ff515e44aedefe9eb9c02879c89994298fa79042103a650bf03971df0176c7b412247390ef717853e8bd487b204dccc2fe2078bb75206210390bbbcebe9f70ba5dfd98866a79f72f75e0a6ea550ef73b202dd87cd6477350a08210284152d57908488e666e872716a286eb670b3d06cbeebf3f2e4ad350e01ec5e5b0aa2a1007d020000000174c52ab4f11296d62b66a6dba9513b04a3e7fb5a09a30cee22fce7294ab55b7e00000000000f55f9800299c2000000000000220020740e108cfbc93967b6ab242a351ebee7de51814cf78d366adefd78b10281f17e50c300000000000016001425df8ec4a074f80579fed67d4707d5ec8ed7e8d351c92220022004f8eda5676356f539169a8e9a1e86c7f125283328d6f4bded1b939b52a6a7e30c00024045cb2485594bb1ec08e7bb6af4f89c912bd53f006d7876ea956773e04a4aad4a40e2b8d4fc612102f0b54061b3c1239fb78783053e8e6f9d92b1b99f81ae9ec2040100060000fd019600b0af002103c21e841cbc0b48197d060c71e116c185fa0ac281b7d0aa5924f535154437ca3b02210270b20ad0f2c2bb30a55590fc77778495bc1b38c96476901145dda57491237f0f042103b4e59df102747edc3a3e2283b42b88a8c8218ffd0dcfb52f2524b371d64cadaa062103d902b7b8b3434076d2b210e912c76645048b71e28995aad227a465a65ccd817608210301e9a52f923c157941de4a7692e601f758660969dcf5abdb67817efe84cce2ef0202009004010106b7b600b0af00210307a78def56cba9fc4db22a25928181de538ee59ba1a475ae113af7790acd0db30221034d0f817cb19b4a3bd144b615459bd06cbab3b4bdc96d73e18549a992cee80e8104210380542b59a9679890cba529fe155a9508ef57dac7416d035b23666e3fb98c3814062103adde8029d3ee281a32e9db929b39f503ff9d7e93cd308eb157955344dc6def84082103205087e2dc1f6b9937e887dfa712c5bdfa950b01dbda3ebac4c85efdde48ee6a02020090082274c52ab4f11296d62b66a6dba9513b04a3e7fb5a09a30cee22fce7294ab55b7e000000000287010108d30df34e3a1e00ecdd03a2c843db062479a81752c4dfd0cc4baef0f81e7bc7ef8820990daf8d8e8d30a3b4b08af12c9f5cd71e45c7238103e0c80ca13850862e4fd2c56b69b7195312518de1bfe9aed63c80bb7760d70b2a870d542d815895fd12423d11e2adb0cdf55d776dac8f487c9b3b7ea12f1b150eb15889cf41333ade465692bf1cdc360b9c2a19bf8c1ca4fed7639d8bc953d36c10d8c6c9a8c0a57608788979bcf145e61b308006896e21d03e92084f93bd78740c20639134a7a8fd019afd019600b0af002103c21e841cbc0b48197d060c71e116c185fa0ac281b7d0aa5924f535154437ca3b02210270b20ad0f2c2bb30a55590fc77778495bc1b38c96476901145dda57491237f0f042103b4e59df102747edc3a3e2283b42b88a8c8218ffd0dcfb52f2524b371d64cadaa062103d902b7b8b3434076d2b210e912c76645048b71e28995aad227a465a65ccd817608210301e9a52f923c157941de4a7692e601f758660969dcf5abdb67817efe84cce2ef0202009004010106b7b600b0af00210307a78def56cba9fc4db22a25928181de538ee59ba1a475ae113af7790acd0db30221034d0f817cb19b4a3bd144b615459bd06cbab3b4bdc96d73e18549a992cee80e8104210380542b59a9679890cba529fe155a9508ef57dac7416d035b23666e3fb98c3814062103adde8029d3ee281a32e9db929b39f503ff9d7e93cd308eb157955344dc6def84082103205087e2dc1f6b9937e887dfa712c5bdfa950b01dbda3ebac4c85efdde48ee6a02020090082274c52ab4f11296d62b66a6dba9513b04a3e7fb5a09a30cee22fce7294ab55b7e000000000000000186a00000000000000000000000004d49e5da0000000000000000000000000000002a00000000000000000000000000000000000000000000000001000000510000000000000001000000000000000145cfd42d0989e55b953f516ac7fd152bd90ec4438a2fc636f97ddd32a0c8fe0d00000000041000080000000000989680020400000051160004000000510208000000000000000004040000000b0000000000000000000101300300050007010109210355f8d2238a322d16b602bd0ceaad5b01019fb055971eaadcc9b29226a4da6c230d000f020000",
                ).unwrap();
                reload_node!(nodes[0], &nodes[0].node.encode(), &[&serialized_monitor], persister, new_chain_monitor, node_deserialized);
@@ -2076,7 +2077,7 @@ fn do_test_monitor_rebroadcast_pending_claims(anchors: bool) {
 
        let coinbase_tx = Transaction {
                version: 2,
-               lock_time: PackedLockTime::ZERO,
+               lock_time: LockTime::ZERO,
                input: vec![TxIn { ..Default::default() }],
                output: vec![TxOut { // UTXO to attach fees to `htlc_tx` on anchors
                        value: Amount::ONE_BTC.to_sat(),
@@ -2106,7 +2107,7 @@ fn do_test_monitor_rebroadcast_pending_claims(anchors: bool) {
                                        check_spends!(&htlc_tx, &commitment_txn[0], &coinbase_tx);
                                        let htlc_tx_fee = HTLC_AMT_SAT + coinbase_tx.output[0].value -
                                                htlc_tx.output.iter().map(|output| output.value).sum::<u64>();
-                                       let htlc_tx_weight = htlc_tx.weight() as u64;
+                                       let htlc_tx_weight = htlc_tx.weight().to_wu();
                                        (htlc_tx, compute_feerate_sat_per_1000_weight(htlc_tx_fee, htlc_tx_weight))
                                }
                                _ => panic!("Unexpected event"),
@@ -2121,7 +2122,7 @@ fn do_test_monitor_rebroadcast_pending_claims(anchors: bool) {
                        let htlc_tx = txn.pop().unwrap();
                        check_spends!(htlc_tx, commitment_txn[0]);
                        let htlc_tx_fee = HTLC_AMT_SAT - htlc_tx.output[0].value;
-                       let htlc_tx_weight = htlc_tx.weight() as u64;
+                       let htlc_tx_weight = htlc_tx.weight().to_wu();
                        (htlc_tx, compute_feerate_sat_per_1000_weight(htlc_tx_fee, htlc_tx_weight))
                };
                if should_bump {
@@ -2232,7 +2233,7 @@ fn test_yield_anchors_events() {
                Event::BumpTransaction(event) => {
                        let coinbase_tx = Transaction {
                                version: 2,
-                               lock_time: PackedLockTime::ZERO,
+                               lock_time: LockTime::ZERO,
                                input: vec![TxIn { ..Default::default() }],
                                output: vec![TxOut { // UTXO to attach fees to `anchor_tx`
                                        value: Amount::ONE_BTC.to_sat(),
@@ -2425,7 +2426,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() {
                let utxo_value = Amount::ONE_BTC.to_sat() * (idx + 1) as u64;
                let coinbase_tx = Transaction {
                        version: 2,
-                       lock_time: PackedLockTime::ZERO,
+                       lock_time: LockTime::ZERO,
                        input: vec![TxIn { ..Default::default() }],
                        output: vec![TxOut { // UTXO to attach fees to `anchor_tx`
                                value: utxo_value,
@@ -2491,10 +2492,10 @@ fn test_anchors_aggregated_revoked_htlc_tx() {
        let htlc_tx = {
                let secret_key = SecretKey::from_slice(&[1; 32]).unwrap();
                let public_key = PublicKey::new(secret_key.public_key(&secp));
-               let fee_utxo_script = Script::new_v0_p2wpkh(&public_key.wpubkey_hash().unwrap());
+               let fee_utxo_script = ScriptBuf::new_v0_p2wpkh(&public_key.wpubkey_hash().unwrap());
                let coinbase_tx = Transaction {
                        version: 2,
-                       lock_time: PackedLockTime::ZERO,
+                       lock_time: LockTime::ZERO,
                        input: vec![TxIn { ..Default::default() }],
                        output: vec![TxOut { // UTXO to attach fees to `htlc_tx`
                                value: Amount::ONE_BTC.to_sat(),
@@ -2503,14 +2504,14 @@ fn test_anchors_aggregated_revoked_htlc_tx() {
                };
                let mut htlc_tx = Transaction {
                        version: 2,
-                       lock_time: PackedLockTime::ZERO,
+                       lock_time: LockTime::ZERO,
                        input: vec![TxIn { // Fee input
                                previous_output: bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 0 },
                                ..Default::default()
                        }],
                        output: vec![TxOut { // Fee input change
                                value: coinbase_tx.output[0].value / 2 ,
-                               script_pubkey: Script::new_op_return(&[]),
+                               script_pubkey: ScriptBuf::new_op_return(&[]),
                        }],
                };
                let mut descriptors = Vec::with_capacity(4);
@@ -2538,7 +2539,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() {
                        htlc_tx.input[htlc_input_idx].witness = htlc_descriptor.tx_input_witness(&our_sig, &witness_script);
                }
                let fee_utxo_sig = {
-                       let witness_script = Script::new_p2pkh(&public_key.pubkey_hash());
+                       let witness_script = ScriptBuf::new_p2pkh(&public_key.pubkey_hash());
                        let sighash = hash_to_message!(&SighashCache::new(&htlc_tx).segwit_signature_hash(
                                0, &witness_script, coinbase_tx.output[0].value, EcdsaSighashType::All
                        ).unwrap()[..]);
@@ -2547,7 +2548,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() {
                        sig.push(EcdsaSighashType::All as u8);
                        sig
                };
-               htlc_tx.input[0].witness = Witness::from_vec(vec![fee_utxo_sig, public_key.to_bytes()]);
+               htlc_tx.input[0].witness = Witness::from_slice(&[fee_utxo_sig, public_key.to_bytes()]);
                check_spends!(htlc_tx, coinbase_tx, revoked_commitment_a, revoked_commitment_b);
                htlc_tx
        };
@@ -2603,7 +2604,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() {
                        assert_eq!(outputs.len(), 1);
                        assert!(vec![chan_b.2, chan_a.2].contains(&channel_id.unwrap()));
                        let spend_tx = nodes[0].keys_manager.backing.spend_spendable_outputs(
-                               &[&outputs[0]], Vec::new(), Script::new_op_return(&[]), 253, None, &Secp256k1::new(),
+                               &[&outputs[0]], Vec::new(), ScriptBuf::new_op_return(&[]), 253, None, &Secp256k1::new(),
                        ).unwrap();
 
                        if let SpendableOutputDescriptor::StaticPaymentOutput(_) = &outputs[0] {
@@ -2649,7 +2650,7 @@ fn do_test_anchors_monitor_fixes_counterparty_payment_script_on_reload(confirm_c
        let secp = Secp256k1::new();
        let privkey = bitcoin::PrivateKey::from_slice(&[1; 32], bitcoin::Network::Testnet).unwrap();
        let pubkey = bitcoin::PublicKey::from_private_key(&secp, &privkey);
-       let p2wpkh_script = Script::new_v0_p2wpkh(&pubkey.wpubkey_hash().unwrap());
+       let p2wpkh_script = ScriptBuf::new_v0_p2wpkh(&pubkey.wpubkey_hash().unwrap());
        get_monitor!(nodes[1], chan_id).set_counterparty_payment_script(p2wpkh_script.clone());
        assert_eq!(get_monitor!(nodes[1], chan_id).get_counterparty_payment_script(), p2wpkh_script);
 
@@ -2732,7 +2733,7 @@ fn do_test_monitor_claims_with_random_signatures(anchors: bool, confirm_counterp
 
        let coinbase_tx = Transaction {
                version: 2,
-               lock_time: PackedLockTime::ZERO,
+               lock_time: LockTime::ZERO,
                input: vec![TxIn { ..Default::default() }],
                output: vec![
                        TxOut {
index 9d872a6f53d999ac817cfaf9b6e4aa2a444814d2..d5529e98ba013c4f8d2118edb5de4bebb82470df 100644 (file)
@@ -28,7 +28,7 @@ use bitcoin::blockdata::constants::ChainHash;
 use bitcoin::secp256k1::PublicKey;
 use bitcoin::secp256k1::ecdsa::Signature;
 use bitcoin::{secp256k1, Witness};
-use bitcoin::blockdata::script::Script;
+use bitcoin::blockdata::script::ScriptBuf;
 use bitcoin::hash_types::Txid;
 
 use crate::blinded_path::payment::ReceiveTlvs;
@@ -218,7 +218,7 @@ pub struct OpenChannel {
        /// The channel flags to be used
        pub channel_flags: u8,
        /// A request to pre-set the to-sender output's `scriptPubkey` for when we collaboratively close
-       pub shutdown_scriptpubkey: Option<Script>,
+       pub shutdown_scriptpubkey: Option<ScriptBuf>,
        /// The channel type that this channel will represent
        ///
        /// If this is `None`, we derive the channel type from the intersection of our
@@ -276,7 +276,7 @@ pub struct OpenChannelV2 {
        pub channel_flags: u8,
        /// Optionally, a request to pre-set the to-channel-initiator output's scriptPubkey for when we
        /// collaboratively close
-       pub shutdown_scriptpubkey: Option<Script>,
+       pub shutdown_scriptpubkey: Option<ScriptBuf>,
        /// The channel type that this channel will represent. If none is set, we derive the channel
        /// type from the intersection of our feature bits with our counterparty's feature bits from
        /// the Init message.
@@ -321,7 +321,7 @@ pub struct AcceptChannel {
        /// The first to-be-broadcast-by-sender transaction's per commitment point
        pub first_per_commitment_point: PublicKey,
        /// A request to pre-set the to-sender output's scriptPubkey for when we collaboratively close
-       pub shutdown_scriptpubkey: Option<Script>,
+       pub shutdown_scriptpubkey: Option<ScriptBuf>,
        /// The channel type that this channel will represent.
        ///
        /// If this is `None`, we derive the channel type from the intersection of
@@ -375,7 +375,7 @@ pub struct AcceptChannelV2 {
        pub second_per_commitment_point: PublicKey,
        /// Optionally, a request to pre-set the to-channel-acceptor output's scriptPubkey for when we
        /// collaboratively close
-       pub shutdown_scriptpubkey: Option<Script>,
+       pub shutdown_scriptpubkey: Option<ScriptBuf>,
        /// The channel type that this channel will represent. If none is set, we derive the channel
        /// type from the intersection of our feature bits with our counterparty's feature bits from
        /// the Init message.
@@ -527,7 +527,7 @@ pub struct TxAddOutput {
        /// The satoshi value of the output
        pub sats: u64,
        /// The scriptPubKey for the output
-       pub script: Script,
+       pub script: ScriptBuf,
 }
 
 /// A tx_remove_input message for removing an input during interactive transaction construction.
@@ -627,7 +627,7 @@ pub struct Shutdown {
        /// The destination of this peer's funds on closing.
        ///
        /// Must be in one of these forms: P2PKH, P2SH, P2WPKH, P2WSH, P2TR.
-       pub scriptpubkey: Script,
+       pub scriptpubkey: ScriptBuf,
 }
 
 /// The minimum and maximum fees which the sender is willing to place on the closing transaction.
@@ -1823,7 +1823,7 @@ impl_writeable_msg!(AcceptChannel, {
        htlc_basepoint,
        first_per_commitment_point,
 }, {
-       (0, shutdown_scriptpubkey, (option, encoding: (Script, WithoutLength))), // Don't encode length twice.
+       (0, shutdown_scriptpubkey, (option, encoding: (ScriptBuf, WithoutLength))), // Don't encode length twice.
        (1, channel_type, option),
 });
 
@@ -1844,7 +1844,7 @@ impl_writeable_msg!(AcceptChannel, {
        htlc_basepoint,
        first_per_commitment_point,
 }, {
-       (0, shutdown_scriptpubkey, (option, encoding: (Script, WithoutLength))), // Don't encode length twice.
+       (0, shutdown_scriptpubkey, (option, encoding: (ScriptBuf, WithoutLength))), // Don't encode length twice.
        (1, channel_type, option),
        (4, next_local_nonce, option),
 });
@@ -2090,7 +2090,7 @@ impl_writeable_msg!(OpenChannel, {
        first_per_commitment_point,
        channel_flags,
 }, {
-       (0, shutdown_scriptpubkey, (option, encoding: (Script, WithoutLength))), // Don't encode length twice.
+       (0, shutdown_scriptpubkey, (option, encoding: (ScriptBuf, WithoutLength))), // Don't encode length twice.
        (1, channel_type, option),
 });
 
@@ -2799,8 +2799,8 @@ impl_writeable_msg!(GossipTimestampFilter, {
 #[cfg(test)]
 mod tests {
        use std::convert::TryFrom;
-       use bitcoin::{Transaction, PackedLockTime, TxIn, Script, Sequence, Witness, TxOut};
-       use hex;
+       use bitcoin::{Transaction, TxIn, ScriptBuf, Sequence, Witness, TxOut};
+       use hex::DisplayHex;
        use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
        use crate::ln::ChannelId;
        use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
@@ -2811,12 +2811,13 @@ mod tests {
        use crate::util::test_utils;
 
        use bitcoin::hashes::hex::FromHex;
-       use bitcoin::util::address::Address;
+       use bitcoin::address::Address;
        use bitcoin::network::constants::Network;
        use bitcoin::blockdata::constants::ChainHash;
        use bitcoin::blockdata::script::Builder;
        use bitcoin::blockdata::opcodes;
        use bitcoin::hash_types::Txid;
+       use bitcoin::locktime::absolute::LockTime;
 
        use bitcoin::secp256k1::{PublicKey,SecretKey};
        use bitcoin::secp256k1::{Secp256k1, Message};
@@ -2835,7 +2836,7 @@ mod tests {
        fn encoding_channel_reestablish() {
                let public_key = {
                        let secp_ctx = Secp256k1::new();
-                       PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap())
+                       PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&<Vec<u8>>::from_hex("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap())
                };
 
                let cr = msgs::ChannelReestablish {
@@ -2864,7 +2865,7 @@ mod tests {
        fn encoding_channel_reestablish_with_next_funding_txid() {
                let public_key = {
                        let secp_ctx = Secp256k1::new();
-                       PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap())
+                       PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&<Vec<u8>>::from_hex("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap())
                };
 
                let cr = msgs::ChannelReestablish {
@@ -2873,7 +2874,7 @@ mod tests {
                        next_remote_commitment_number: 4,
                        your_last_per_commitment_secret: [9;32],
                        my_current_per_commitment_point: public_key,
-                       next_funding_txid: Some(Txid::from_hash(bitcoin::hashes::Hash::from_slice(&[
+                       next_funding_txid: Some(Txid::from_raw_hash(bitcoin::hashes::Hash::from_slice(&[
                                48, 167, 250, 69, 152, 48, 103, 172, 164, 99, 59, 19, 23, 11, 92, 84, 15, 80, 4, 12, 98, 82, 75, 31, 201, 11, 91, 23, 98, 23, 53, 124,
                        ]).unwrap())),
                };
@@ -2897,7 +2898,7 @@ mod tests {
        macro_rules! get_keys_from {
                ($slice: expr, $secp_ctx: expr) => {
                        {
-                               let privkey = SecretKey::from_slice(&hex::decode($slice).unwrap()[..]).unwrap();
+                               let privkey = SecretKey::from_slice(&<Vec<u8>>::from_hex($slice).unwrap()[..]).unwrap();
                                let pubkey = PublicKey::from_secret_key(&$secp_ctx, &privkey);
                                (privkey, pubkey)
                        }
@@ -2927,7 +2928,7 @@ mod tests {
                };
 
                let encoded_value = announcement_signatures.encode();
-               assert_eq!(encoded_value, hex::decode("040000000000000005000000000000000600000000000000070000000000000000083a840000034dd977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073acf9953cef4700860f5967838eba2bae89288ad188ebf8b20bf995c3ea53a26df1876d0a3a0e13172ba286a673140190c02ba9da60a2e43a745188c8a83c7f3ef").unwrap());
+               assert_eq!(encoded_value, <Vec<u8>>::from_hex("040000000000000005000000000000000600000000000000070000000000000000083a840000034dd977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073acf9953cef4700860f5967838eba2bae89288ad188ebf8b20bf995c3ea53a26df1876d0a3a0e13172ba286a673140190c02ba9da60a2e43a745188c8a83c7f3ef").unwrap());
        }
 
        fn do_encoding_channel_announcement(unknown_features_bits: bool, excess_data: bool) {
@@ -2962,16 +2963,16 @@ mod tests {
                        contents: unsigned_channel_announcement,
                };
                let encoded_value = channel_announcement.encode();
-               let mut target_value = hex::decode("d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a1735b6a427e80d5fe7cd90a2f4ee08dc9c27cda7c35a4172e5d85b12c49d4232537e98f9b1f3c5e6989a8b9644e90e8918127680dbd0d4043510840fc0f1e11a216c280b5395a2546e7e4b2663e04f811622f15a4f91e83aa2e92ba2a573c139142c54ae63072a1ec1ee7dc0c04bde5c847806172aa05c92c22ae8e308d1d2692b12cc195ce0a2d1bda6a88befa19fa07f51caa75ce83837f28965600b8aacab0855ffb0e741ec5f7c41421e9829a9d48611c8c831f71be5ea73e66594977ffd").unwrap();
+               let mut target_value = <Vec<u8>>::from_hex("d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a1735b6a427e80d5fe7cd90a2f4ee08dc9c27cda7c35a4172e5d85b12c49d4232537e98f9b1f3c5e6989a8b9644e90e8918127680dbd0d4043510840fc0f1e11a216c280b5395a2546e7e4b2663e04f811622f15a4f91e83aa2e92ba2a573c139142c54ae63072a1ec1ee7dc0c04bde5c847806172aa05c92c22ae8e308d1d2692b12cc195ce0a2d1bda6a88befa19fa07f51caa75ce83837f28965600b8aacab0855ffb0e741ec5f7c41421e9829a9d48611c8c831f71be5ea73e66594977ffd").unwrap();
                if unknown_features_bits {
-                       target_value.append(&mut hex::decode("0002ffff").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("0002ffff").unwrap());
                } else {
-                       target_value.append(&mut hex::decode("0000").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("0000").unwrap());
                }
-               target_value.append(&mut hex::decode("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap());
-               target_value.append(&mut hex::decode("00083a840000034d031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d076602531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe33703462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("00083a840000034d031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d076602531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe33703462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b").unwrap());
                if excess_data {
-                       target_value.append(&mut hex::decode("0a00001400001e000028").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("0a00001400001e000028").unwrap());
                }
                assert_eq!(encoded_value, target_value);
        }
@@ -3046,34 +3047,34 @@ mod tests {
                        contents: unsigned_node_announcement,
                };
                let encoded_value = node_announcement.encode();
-               let mut target_value = hex::decode("d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a").unwrap();
+               let mut target_value = <Vec<u8>>::from_hex("d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a").unwrap();
                if unknown_features_bits {
-                       target_value.append(&mut hex::decode("0002ffff").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("0002ffff").unwrap());
                } else {
-                       target_value.append(&mut hex::decode("000122").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("000122").unwrap());
                }
-               target_value.append(&mut hex::decode("013413a7031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f2020201010101010101010101010101010101010101010101010101010101010101010").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("013413a7031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f2020201010101010101010101010101010101010101010101010101010101010101010").unwrap());
                target_value.append(&mut vec![(addr_len >> 8) as u8, addr_len as u8]);
                if ipv4 {
-                       target_value.append(&mut hex::decode("01fffefdfc2607").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("01fffefdfc2607").unwrap());
                }
                if ipv6 {
-                       target_value.append(&mut hex::decode("02fffefdfcfbfaf9f8f7f6f5f4f3f2f1f02607").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("02fffefdfcfbfaf9f8f7f6f5f4f3f2f1f02607").unwrap());
                }
                if onionv2 {
-                       target_value.append(&mut hex::decode("03fffefdfcfbfaf9f8f7f62607").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("03fffefdfcfbfaf9f8f7f62607").unwrap());
                }
                if onionv3 {
-                       target_value.append(&mut hex::decode("04fffefdfcfbfaf9f8f7f6f5f4f3f2f1f0efeeedecebeae9e8e7e6e5e4e3e2e1e00020102607").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("04fffefdfcfbfaf9f8f7f6f5f4f3f2f1f0efeeedecebeae9e8e7e6e5e4e3e2e1e00020102607").unwrap());
                }
                if hostname {
-                       target_value.append(&mut hex::decode("0504686f73742607").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("0504686f73742607").unwrap());
                }
                if excess_address_data {
-                       target_value.append(&mut hex::decode("216c280b5395a2546e7e4b2663e04f811622f15a4f92e83aa2e92ba2a573c139142c54ae63072a1ec1ee7dc0c04bde5c847806172aa05c92c22ae8e308d1d269").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("216c280b5395a2546e7e4b2663e04f811622f15a4f92e83aa2e92ba2a573c139142c54ae63072a1ec1ee7dc0c04bde5c847806172aa05c92c22ae8e308d1d269").unwrap());
                }
                if excess_data {
-                       target_value.append(&mut hex::decode("3b12cc195ce0a2d1bda6a88befa19fa07f51caa75ce83837f28965600b8aacab0855ffb0e741ec5f7c41421e9829a9d48611c8c831f71be5ea73e66594977ffd").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("3b12cc195ce0a2d1bda6a88befa19fa07f51caa75ce83837f28965600b8aacab0855ffb0e741ec5f7c41421e9829a9d48611c8c831f71be5ea73e66594977ffd").unwrap());
                }
                assert_eq!(encoded_value, target_value);
        }
@@ -3113,11 +3114,11 @@ mod tests {
                        contents: unsigned_channel_update
                };
                let encoded_value = channel_update.encode();
-               let mut target_value = hex::decode("d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a").unwrap();
-               target_value.append(&mut hex::decode("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap());
-               target_value.append(&mut hex::decode("00083a840000034d013413a7").unwrap());
-               target_value.append(&mut hex::decode("01").unwrap());
-               target_value.append(&mut hex::decode("00").unwrap());
+               let mut target_value = <Vec<u8>>::from_hex("d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a").unwrap();
+               target_value.append(&mut <Vec<u8>>::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("00083a840000034d013413a7").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("01").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("00").unwrap());
                if direction {
                        let flag = target_value.last_mut().unwrap();
                        *flag = 1;
@@ -3126,10 +3127,10 @@ mod tests {
                        let flag = target_value.last_mut().unwrap();
                        *flag = *flag | 1 << 1;
                }
-               target_value.append(&mut hex::decode("009000000000000f42400000271000000014").unwrap());
-               target_value.append(&mut hex::decode("0000777788889999").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("009000000000000f42400000271000000014").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("0000777788889999").unwrap());
                if excess_data {
-                       target_value.append(&mut hex::decode("000000003b9aca00").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("000000003b9aca00").unwrap());
                }
                assert_eq!(encoded_value, target_value);
        }
@@ -3178,18 +3179,18 @@ mod tests {
                };
                let encoded_value = open_channel.encode();
                let mut target_value = Vec::new();
-               target_value.append(&mut hex::decode("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap());
-               target_value.append(&mut hex::decode("02020202020202020202020202020202020202020202020202020202020202021234567890123456233403289122369832144668701144767633030896203198784335490624111800083a840000034d000c89d4c0bcc0bc031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d076602531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe33703462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b0362c0a046dacce86ddd0343c6d3c7c79c2208ba0d9c9cf24a6d046d21d21f90f703f006a18d5653c4edf5391ff23a61f03ff83d237e880ee61187fa9f379a028e0a").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("02020202020202020202020202020202020202020202020202020202020202021234567890123456233403289122369832144668701144767633030896203198784335490624111800083a840000034d000c89d4c0bcc0bc031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d076602531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe33703462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b0362c0a046dacce86ddd0343c6d3c7c79c2208ba0d9c9cf24a6d046d21d21f90f703f006a18d5653c4edf5391ff23a61f03ff83d237e880ee61187fa9f379a028e0a").unwrap());
                if random_bit {
-                       target_value.append(&mut hex::decode("20").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("20").unwrap());
                } else {
-                       target_value.append(&mut hex::decode("00").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("00").unwrap());
                }
                if shutdown {
-                       target_value.append(&mut hex::decode("001976a91479b000887626b294a914501a4cd226b58b23598388ac").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("001976a91479b000887626b294a914501a4cd226b58b23598388ac").unwrap());
                }
                if incl_chan_type {
-                       target_value.append(&mut hex::decode("0100").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("0100").unwrap());
                }
                assert_eq!(encoded_value, target_value);
        }
@@ -3241,39 +3242,39 @@ mod tests {
                };
                let encoded_value = open_channelv2.encode();
                let mut target_value = Vec::new();
-               target_value.append(&mut hex::decode("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap());
-               target_value.append(&mut hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap());
-               target_value.append(&mut hex::decode("000c89d4").unwrap());
-               target_value.append(&mut hex::decode("000c89d4").unwrap());
-               target_value.append(&mut hex::decode("1234567890123456").unwrap());
-               target_value.append(&mut hex::decode("3214466870114476").unwrap());
-               target_value.append(&mut hex::decode("7633030896203198").unwrap());
-               target_value.append(&mut hex::decode("00083a840000034d").unwrap());
-               target_value.append(&mut hex::decode("c0bc").unwrap());
-               target_value.append(&mut hex::decode("c0bc").unwrap());
-               target_value.append(&mut hex::decode("12345678").unwrap());
-               target_value.append(&mut hex::decode("031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f").unwrap());
-               target_value.append(&mut hex::decode("024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d0766").unwrap());
-               target_value.append(&mut hex::decode("02531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe337").unwrap());
-               target_value.append(&mut hex::decode("03462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b").unwrap());
-               target_value.append(&mut hex::decode("0362c0a046dacce86ddd0343c6d3c7c79c2208ba0d9c9cf24a6d046d21d21f90f7").unwrap());
-               target_value.append(&mut hex::decode("03f006a18d5653c4edf5391ff23a61f03ff83d237e880ee61187fa9f379a028e0a").unwrap());
-               target_value.append(&mut hex::decode("02989c0b76cb563971fdc9bef31ec06c3560f3249d6ee9e5d83c57625596e05f6f").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("0202020202020202020202020202020202020202020202020202020202020202").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("000c89d4").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("000c89d4").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("1234567890123456").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("3214466870114476").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("7633030896203198").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("00083a840000034d").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("c0bc").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("c0bc").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("12345678").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d0766").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("02531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe337").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("03462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("0362c0a046dacce86ddd0343c6d3c7c79c2208ba0d9c9cf24a6d046d21d21f90f7").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("03f006a18d5653c4edf5391ff23a61f03ff83d237e880ee61187fa9f379a028e0a").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("02989c0b76cb563971fdc9bef31ec06c3560f3249d6ee9e5d83c57625596e05f6f").unwrap());
 
                if random_bit {
-                       target_value.append(&mut hex::decode("20").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("20").unwrap());
                } else {
-                       target_value.append(&mut hex::decode("00").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("00").unwrap());
                }
                if shutdown {
-                       target_value.append(&mut hex::decode("001b").unwrap()); // Type 0 + Length 27
-                       target_value.append(&mut hex::decode("001976a91479b000887626b294a914501a4cd226b58b23598388ac").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("001b").unwrap()); // Type 0 + Length 27
+                       target_value.append(&mut <Vec<u8>>::from_hex("001976a91479b000887626b294a914501a4cd226b58b23598388ac").unwrap());
                }
                if incl_chan_type {
-                       target_value.append(&mut hex::decode("0100").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("0100").unwrap());
                }
                if require_confirmed_inputs {
-                       target_value.append(&mut hex::decode("0200").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("0200").unwrap());
                }
                assert_eq!(encoded_value, target_value);
        }
@@ -3327,9 +3328,9 @@ mod tests {
                        next_local_nonce: None,
                };
                let encoded_value = accept_channel.encode();
-               let mut target_value = hex::decode("020202020202020202020202020202020202020202020202020202020202020212345678901234562334032891223698321446687011447600083a840000034d000c89d4c0bcc0bc031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d076602531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe33703462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b0362c0a046dacce86ddd0343c6d3c7c79c2208ba0d9c9cf24a6d046d21d21f90f703f006a18d5653c4edf5391ff23a61f03ff83d237e880ee61187fa9f379a028e0a").unwrap();
+               let mut target_value = <Vec<u8>>::from_hex("020202020202020202020202020202020202020202020202020202020202020212345678901234562334032891223698321446687011447600083a840000034d000c89d4c0bcc0bc031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d076602531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe33703462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b0362c0a046dacce86ddd0343c6d3c7c79c2208ba0d9c9cf24a6d046d21d21f90f703f006a18d5653c4edf5391ff23a61f03ff83d237e880ee61187fa9f379a028e0a").unwrap();
                if shutdown {
-                       target_value.append(&mut hex::decode("001976a91479b000887626b294a914501a4cd226b58b23598388ac").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("001976a91479b000887626b294a914501a4cd226b58b23598388ac").unwrap());
                }
                assert_eq!(encoded_value, target_value);
        }
@@ -3370,24 +3371,24 @@ mod tests {
                        require_confirmed_inputs: None,
                };
                let encoded_value = accept_channelv2.encode();
-               let mut target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap(); // temporary_channel_id
-               target_value.append(&mut hex::decode("1234567890123456").unwrap()); // funding_satoshis
-               target_value.append(&mut hex::decode("1234567890123456").unwrap()); // dust_limit_satoshis
-               target_value.append(&mut hex::decode("2334032891223698").unwrap()); // max_htlc_value_in_flight_msat
-               target_value.append(&mut hex::decode("00083a840000034d").unwrap()); // htlc_minimum_msat
-               target_value.append(&mut hex::decode("000c89d4").unwrap()); //  minimum_depth
-               target_value.append(&mut hex::decode("c0bc").unwrap()); // to_self_delay
-               target_value.append(&mut hex::decode("c0bc").unwrap()); // max_accepted_htlcs
-               target_value.append(&mut hex::decode("031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f").unwrap()); // funding_pubkey
-               target_value.append(&mut hex::decode("024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d0766").unwrap()); // revocation_basepoint
-               target_value.append(&mut hex::decode("02531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe337").unwrap()); // payment_basepoint
-               target_value.append(&mut hex::decode("03462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b").unwrap()); // delayed_payment_basepoint
-               target_value.append(&mut hex::decode("0362c0a046dacce86ddd0343c6d3c7c79c2208ba0d9c9cf24a6d046d21d21f90f7").unwrap()); // htlc_basepoint
-               target_value.append(&mut hex::decode("03f006a18d5653c4edf5391ff23a61f03ff83d237e880ee61187fa9f379a028e0a").unwrap()); // first_per_commitment_point
-               target_value.append(&mut hex::decode("02989c0b76cb563971fdc9bef31ec06c3560f3249d6ee9e5d83c57625596e05f6f").unwrap()); // second_per_commitment_point
+               let mut target_value = <Vec<u8>>::from_hex("0202020202020202020202020202020202020202020202020202020202020202").unwrap(); // temporary_channel_id
+               target_value.append(&mut <Vec<u8>>::from_hex("1234567890123456").unwrap()); // funding_satoshis
+               target_value.append(&mut <Vec<u8>>::from_hex("1234567890123456").unwrap()); // dust_limit_satoshis
+               target_value.append(&mut <Vec<u8>>::from_hex("2334032891223698").unwrap()); // max_htlc_value_in_flight_msat
+               target_value.append(&mut <Vec<u8>>::from_hex("00083a840000034d").unwrap()); // htlc_minimum_msat
+               target_value.append(&mut <Vec<u8>>::from_hex("000c89d4").unwrap()); //  minimum_depth
+               target_value.append(&mut <Vec<u8>>::from_hex("c0bc").unwrap()); // to_self_delay
+               target_value.append(&mut <Vec<u8>>::from_hex("c0bc").unwrap()); // max_accepted_htlcs
+               target_value.append(&mut <Vec<u8>>::from_hex("031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f").unwrap()); // funding_pubkey
+               target_value.append(&mut <Vec<u8>>::from_hex("024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d0766").unwrap()); // revocation_basepoint
+               target_value.append(&mut <Vec<u8>>::from_hex("02531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe337").unwrap()); // payment_basepoint
+               target_value.append(&mut <Vec<u8>>::from_hex("03462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b").unwrap()); // delayed_payment_basepoint
+               target_value.append(&mut <Vec<u8>>::from_hex("0362c0a046dacce86ddd0343c6d3c7c79c2208ba0d9c9cf24a6d046d21d21f90f7").unwrap()); // htlc_basepoint
+               target_value.append(&mut <Vec<u8>>::from_hex("03f006a18d5653c4edf5391ff23a61f03ff83d237e880ee61187fa9f379a028e0a").unwrap()); // first_per_commitment_point
+               target_value.append(&mut <Vec<u8>>::from_hex("02989c0b76cb563971fdc9bef31ec06c3560f3249d6ee9e5d83c57625596e05f6f").unwrap()); // second_per_commitment_point
                if shutdown {
-                       target_value.append(&mut hex::decode("001b").unwrap()); // Type 0 + Length 27
-                       target_value.append(&mut hex::decode("001976a91479b000887626b294a914501a4cd226b58b23598388ac").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("001b").unwrap()); // Type 0 + Length 27
+                       target_value.append(&mut <Vec<u8>>::from_hex("001976a91479b000887626b294a914501a4cd226b58b23598388ac").unwrap());
                }
                assert_eq!(encoded_value, target_value);
        }
@@ -3405,7 +3406,7 @@ mod tests {
                let sig_1 = get_sig_on!(privkey_1, secp_ctx, String::from("01010101010101010101010101010101"));
                let funding_created = msgs::FundingCreated {
                        temporary_channel_id: ChannelId::from_bytes([2; 32]),
-                       funding_txid: Txid::from_hex("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap(),
+                       funding_txid: Txid::from_str("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap(),
                        funding_output_index: 255,
                        signature: sig_1,
                        #[cfg(taproot)]
@@ -3414,7 +3415,7 @@ mod tests {
                        next_local_nonce: None,
                };
                let encoded_value = funding_created.encode();
-               let target_value = hex::decode("02020202020202020202020202020202020202020202020202020202020202026e96fe9f8b0ddcd729ba03cfafa5a27b050b39d354dd980814268dfa9a44d4c200ffd977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a").unwrap();
+               let target_value = <Vec<u8>>::from_hex("02020202020202020202020202020202020202020202020202020202020202026e96fe9f8b0ddcd729ba03cfafa5a27b050b39d354dd980814268dfa9a44d4c200ffd977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a").unwrap();
                assert_eq!(encoded_value, target_value);
        }
 
@@ -3430,7 +3431,7 @@ mod tests {
                        partial_signature_with_nonce: None,
                };
                let encoded_value = funding_signed.encode();
-               let target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a").unwrap();
+               let target_value = <Vec<u8>>::from_hex("0202020202020202020202020202020202020202020202020202020202020202d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a").unwrap();
                assert_eq!(encoded_value, target_value);
        }
 
@@ -3444,7 +3445,7 @@ mod tests {
                        short_channel_id_alias: None,
                };
                let encoded_value = channel_ready.encode();
-               let target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f").unwrap();
+               let target_value = <Vec<u8>>::from_hex("0202020202020202020202020202020202020202020202020202020202020202031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f").unwrap();
                assert_eq!(encoded_value, target_value);
        }
 
@@ -3461,7 +3462,7 @@ mod tests {
                        funding_pubkey: pubkey_1,
                };
                let encoded_value = splice.encode();
-               assert_eq!(hex::encode(encoded_value), "02020202020202020202020202020202020202020202020202020202020202026fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000000000000001e240000007d000000000031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f");
+               assert_eq!(encoded_value.as_hex().to_string(), "02020202020202020202020202020202020202020202020202020202020202026fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000000000000001e240000007d000000000031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f");
        }
 
        #[test]
@@ -3471,7 +3472,7 @@ mod tests {
                        initiator: 1,
                };
                let encoded_value = stfu.encode();
-               assert_eq!(hex::encode(encoded_value), "020202020202020202020202020202020202020202020202020202020202020201");
+               assert_eq!(encoded_value.as_hex().to_string(), "020202020202020202020202020202020202020202020202020202020202020201");
        }
 
        #[test]
@@ -3485,7 +3486,7 @@ mod tests {
                        funding_pubkey: pubkey_1,
                };
                let encoded_value = splice.encode();
-               assert_eq!(hex::encode(encoded_value), "02020202020202020202020202020202020202020202020202020202020202026fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000000000000001e240031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f");
+               assert_eq!(encoded_value.as_hex().to_string(), "02020202020202020202020202020202020202020202020202020202020202026fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000000000000001e240031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f");
        }
 
        #[test]
@@ -3494,7 +3495,7 @@ mod tests {
                        channel_id: ChannelId::from_bytes([2; 32]),
                };
                let encoded_value = splice.encode();
-               assert_eq!(hex::encode(encoded_value), "0202020202020202020202020202020202020202020202020202020202020202");
+               assert_eq!(encoded_value.as_hex().to_string(), "0202020202020202020202020202020202020202020202020202020202020202");
        }
 
        #[test]
@@ -3504,23 +3505,23 @@ mod tests {
                        serial_id: 4886718345,
                        prevtx: TransactionU16LenLimited::new(Transaction {
                                version: 2,
-                               lock_time: PackedLockTime(0),
+                               lock_time: LockTime::ZERO,
                                input: vec![TxIn {
-                                       previous_output: OutPoint { txid: Txid::from_hex("305bab643ee297b8b6b76b320792c8223d55082122cb606bf89382146ced9c77").unwrap(), index: 2 }.into_bitcoin_outpoint(),
-                                       script_sig: Script::new(),
+                                       previous_output: OutPoint { txid: Txid::from_str("305bab643ee297b8b6b76b320792c8223d55082122cb606bf89382146ced9c77").unwrap(), index: 2 }.into_bitcoin_outpoint(),
+                                       script_sig: ScriptBuf::new(),
                                        sequence: Sequence(0xfffffffd),
-                                       witness: Witness::from_vec(vec![
-                                               hex::decode("304402206af85b7dd67450ad12c979302fac49dfacbc6a8620f49c5da2b5721cf9565ca502207002b32fed9ce1bf095f57aeb10c36928ac60b12e723d97d2964a54640ceefa701").unwrap(),
-                                               hex::decode("0301ab7dc16488303549bfcdd80f6ae5ee4c20bf97ab5410bbd6b1bfa85dcd6944").unwrap()]),
+                                       witness: Witness::from_slice(&vec![
+                                               <Vec<u8>>::from_hex("304402206af85b7dd67450ad12c979302fac49dfacbc6a8620f49c5da2b5721cf9565ca502207002b32fed9ce1bf095f57aeb10c36928ac60b12e723d97d2964a54640ceefa701").unwrap(),
+                                               <Vec<u8>>::from_hex("0301ab7dc16488303549bfcdd80f6ae5ee4c20bf97ab5410bbd6b1bfa85dcd6944").unwrap()]),
                                }],
                                output: vec![
                                        TxOut {
                                                value: 12704566,
-                                               script_pubkey: Address::from_str("bc1qzlffunw52jav8vwdu5x3jfk6sr8u22rmq3xzw2").unwrap().script_pubkey(),
+                                               script_pubkey: Address::from_str("bc1qzlffunw52jav8vwdu5x3jfk6sr8u22rmq3xzw2").unwrap().payload.script_pubkey(),
                                        },
                                        TxOut {
                                                value: 245148,
-                                               script_pubkey: Address::from_str("bc1qxmk834g5marzm227dgqvynd23y2nvt2ztwcw2z").unwrap().script_pubkey(),
+                                               script_pubkey: Address::from_str("bc1qxmk834g5marzm227dgqvynd23y2nvt2ztwcw2z").unwrap().payload.script_pubkey(),
                                        },
                                ],
                        }).unwrap(),
@@ -3528,7 +3529,7 @@ mod tests {
                        sequence: 305419896,
                };
                let encoded_value = tx_add_input.encode();
-               let target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202000000012345678900de02000000000101779ced6c148293f86b60cb222108553d22c89207326bb7b6b897e23e64ab5b300200000000fdffffff0236dbc1000000000016001417d29e4dd454bac3b1cde50d1926da80cfc5287b9cbd03000000000016001436ec78d514df462da95e6a00c24daa8915362d420247304402206af85b7dd67450ad12c979302fac49dfacbc6a8620f49c5da2b5721cf9565ca502207002b32fed9ce1bf095f57aeb10c36928ac60b12e723d97d2964a54640ceefa701210301ab7dc16488303549bfcdd80f6ae5ee4c20bf97ab5410bbd6b1bfa85dcd6944000000001234567812345678").unwrap();
+               let target_value = <Vec<u8>>::from_hex("0202020202020202020202020202020202020202020202020202020202020202000000012345678900de02000000000101779ced6c148293f86b60cb222108553d22c89207326bb7b6b897e23e64ab5b300200000000fdffffff0236dbc1000000000016001417d29e4dd454bac3b1cde50d1926da80cfc5287b9cbd03000000000016001436ec78d514df462da95e6a00c24daa8915362d420247304402206af85b7dd67450ad12c979302fac49dfacbc6a8620f49c5da2b5721cf9565ca502207002b32fed9ce1bf095f57aeb10c36928ac60b12e723d97d2964a54640ceefa701210301ab7dc16488303549bfcdd80f6ae5ee4c20bf97ab5410bbd6b1bfa85dcd6944000000001234567812345678").unwrap();
                assert_eq!(encoded_value, target_value);
        }
 
@@ -3538,10 +3539,10 @@ mod tests {
                        channel_id: ChannelId::from_bytes([2; 32]),
                        serial_id: 4886718345,
                        sats: 4886718345,
-                       script: Address::from_str("bc1qxmk834g5marzm227dgqvynd23y2nvt2ztwcw2z").unwrap().script_pubkey(),
+                       script: Address::from_str("bc1qxmk834g5marzm227dgqvynd23y2nvt2ztwcw2z").unwrap().payload.script_pubkey(),
                };
                let encoded_value = tx_add_output.encode();
-               let target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202000000012345678900000001234567890016001436ec78d514df462da95e6a00c24daa8915362d42").unwrap();
+               let target_value = <Vec<u8>>::from_hex("0202020202020202020202020202020202020202020202020202020202020202000000012345678900000001234567890016001436ec78d514df462da95e6a00c24daa8915362d42").unwrap();
                assert_eq!(encoded_value, target_value);
        }
 
@@ -3552,7 +3553,7 @@ mod tests {
                        serial_id: 4886718345,
                };
                let encoded_value = tx_remove_input.encode();
-               let target_value = hex::decode("02020202020202020202020202020202020202020202020202020202020202020000000123456789").unwrap();
+               let target_value = <Vec<u8>>::from_hex("02020202020202020202020202020202020202020202020202020202020202020000000123456789").unwrap();
                assert_eq!(encoded_value, target_value);
        }
 
@@ -3563,7 +3564,7 @@ mod tests {
                        serial_id: 4886718345,
                };
                let encoded_value = tx_remove_output.encode();
-               let target_value = hex::decode("02020202020202020202020202020202020202020202020202020202020202020000000123456789").unwrap();
+               let target_value = <Vec<u8>>::from_hex("02020202020202020202020202020202020202020202020202020202020202020000000123456789").unwrap();
                assert_eq!(encoded_value, target_value);
        }
 
@@ -3573,7 +3574,7 @@ mod tests {
                        channel_id: ChannelId::from_bytes([2; 32]),
                };
                let encoded_value = tx_complete.encode();
-               let target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap();
+               let target_value = <Vec<u8>>::from_hex("0202020202020202020202020202020202020202020202020202020202020202").unwrap();
                assert_eq!(encoded_value, target_value);
        }
 
@@ -3581,34 +3582,34 @@ mod tests {
        fn encoding_tx_signatures() {
                let tx_signatures = msgs::TxSignatures {
                        channel_id: ChannelId::from_bytes([2; 32]),
-                       tx_hash: Txid::from_hex("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap(),
+                       tx_hash: Txid::from_str("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap(),
                        witnesses: vec![
-                               Witness::from_vec(vec![
-                                       hex::decode("304402206af85b7dd67450ad12c979302fac49dfacbc6a8620f49c5da2b5721cf9565ca502207002b32fed9ce1bf095f57aeb10c36928ac60b12e723d97d2964a54640ceefa701").unwrap(),
-                                       hex::decode("0301ab7dc16488303549bfcdd80f6ae5ee4c20bf97ab5410bbd6b1bfa85dcd6944").unwrap()]),
-                               Witness::from_vec(vec![
-                                       hex::decode("3045022100ee00dbf4a862463e837d7c08509de814d620e4d9830fa84818713e0fa358f145022021c3c7060c4d53fe84fd165d60208451108a778c13b92ca4c6bad439236126cc01").unwrap(),
-                                       hex::decode("028fbbf0b16f5ba5bcb5dd37cd4047ce6f726a21c06682f9ec2f52b057de1dbdb5").unwrap()]),
+                               Witness::from_slice(&vec![
+                                       <Vec<u8>>::from_hex("304402206af85b7dd67450ad12c979302fac49dfacbc6a8620f49c5da2b5721cf9565ca502207002b32fed9ce1bf095f57aeb10c36928ac60b12e723d97d2964a54640ceefa701").unwrap(),
+                                       <Vec<u8>>::from_hex("0301ab7dc16488303549bfcdd80f6ae5ee4c20bf97ab5410bbd6b1bfa85dcd6944").unwrap()]),
+                               Witness::from_slice(&vec![
+                                       <Vec<u8>>::from_hex("3045022100ee00dbf4a862463e837d7c08509de814d620e4d9830fa84818713e0fa358f145022021c3c7060c4d53fe84fd165d60208451108a778c13b92ca4c6bad439236126cc01").unwrap(),
+                                       <Vec<u8>>::from_hex("028fbbf0b16f5ba5bcb5dd37cd4047ce6f726a21c06682f9ec2f52b057de1dbdb5").unwrap()]),
                        ],
                };
                let encoded_value = tx_signatures.encode();
-               let mut target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap(); // channel_id
-               target_value.append(&mut hex::decode("6e96fe9f8b0ddcd729ba03cfafa5a27b050b39d354dd980814268dfa9a44d4c2").unwrap()); // tx_hash (sha256) (big endian byte order)
-               target_value.append(&mut hex::decode("0002").unwrap()); // num_witnesses (u16)
+               let mut target_value = <Vec<u8>>::from_hex("0202020202020202020202020202020202020202020202020202020202020202").unwrap(); // channel_id
+               target_value.append(&mut <Vec<u8>>::from_hex("6e96fe9f8b0ddcd729ba03cfafa5a27b050b39d354dd980814268dfa9a44d4c2").unwrap()); // tx_hash (sha256) (big endian byte order)
+               target_value.append(&mut <Vec<u8>>::from_hex("0002").unwrap()); // num_witnesses (u16)
                // Witness 1
-               target_value.append(&mut hex::decode("006b").unwrap()); // len of witness_data
-               target_value.append(&mut hex::decode("02").unwrap()); // num_witness_elements (VarInt)
-               target_value.append(&mut hex::decode("47").unwrap()); // len of witness element data (VarInt)
-               target_value.append(&mut hex::decode("304402206af85b7dd67450ad12c979302fac49dfacbc6a8620f49c5da2b5721cf9565ca502207002b32fed9ce1bf095f57aeb10c36928ac60b12e723d97d2964a54640ceefa701").unwrap());
-               target_value.append(&mut hex::decode("21").unwrap()); // len of witness element data (VarInt)
-               target_value.append(&mut hex::decode("0301ab7dc16488303549bfcdd80f6ae5ee4c20bf97ab5410bbd6b1bfa85dcd6944").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("006b").unwrap()); // len of witness_data
+               target_value.append(&mut <Vec<u8>>::from_hex("02").unwrap()); // num_witness_elements (VarInt)
+               target_value.append(&mut <Vec<u8>>::from_hex("47").unwrap()); // len of witness element data (VarInt)
+               target_value.append(&mut <Vec<u8>>::from_hex("304402206af85b7dd67450ad12c979302fac49dfacbc6a8620f49c5da2b5721cf9565ca502207002b32fed9ce1bf095f57aeb10c36928ac60b12e723d97d2964a54640ceefa701").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("21").unwrap()); // len of witness element data (VarInt)
+               target_value.append(&mut <Vec<u8>>::from_hex("0301ab7dc16488303549bfcdd80f6ae5ee4c20bf97ab5410bbd6b1bfa85dcd6944").unwrap());
                // Witness 2
-               target_value.append(&mut hex::decode("006c").unwrap()); // len of witness_data
-               target_value.append(&mut hex::decode("02").unwrap()); // num_witness_elements (VarInt)
-               target_value.append(&mut hex::decode("48").unwrap()); // len of witness element data (VarInt)
-               target_value.append(&mut hex::decode("3045022100ee00dbf4a862463e837d7c08509de814d620e4d9830fa84818713e0fa358f145022021c3c7060c4d53fe84fd165d60208451108a778c13b92ca4c6bad439236126cc01").unwrap());
-               target_value.append(&mut hex::decode("21").unwrap()); // len of witness element data (VarInt)
-               target_value.append(&mut hex::decode("028fbbf0b16f5ba5bcb5dd37cd4047ce6f726a21c06682f9ec2f52b057de1dbdb5").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("006c").unwrap()); // len of witness_data
+               target_value.append(&mut <Vec<u8>>::from_hex("02").unwrap()); // num_witness_elements (VarInt)
+               target_value.append(&mut <Vec<u8>>::from_hex("48").unwrap()); // len of witness element data (VarInt)
+               target_value.append(&mut <Vec<u8>>::from_hex("3045022100ee00dbf4a862463e837d7c08509de814d620e4d9830fa84818713e0fa358f145022021c3c7060c4d53fe84fd165d60208451108a778c13b92ca4c6bad439236126cc01").unwrap());
+               target_value.append(&mut <Vec<u8>>::from_hex("21").unwrap()); // len of witness element data (VarInt)
+               target_value.append(&mut <Vec<u8>>::from_hex("028fbbf0b16f5ba5bcb5dd37cd4047ce6f726a21c06682f9ec2f52b057de1dbdb5").unwrap());
                assert_eq!(encoded_value, target_value);
        }
 
@@ -3620,13 +3621,13 @@ mod tests {
                        funding_output_contribution: if let Some((value, _)) = funding_value_with_hex_target { Some(value) } else { None },
                };
                let encoded_value = tx_init_rbf.encode();
-               let mut target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap(); // channel_id
-               target_value.append(&mut hex::decode("12345678").unwrap()); // locktime
-               target_value.append(&mut hex::decode("013413a7").unwrap()); // feerate_sat_per_1000_weight
+               let mut target_value = <Vec<u8>>::from_hex("0202020202020202020202020202020202020202020202020202020202020202").unwrap(); // channel_id
+               target_value.append(&mut <Vec<u8>>::from_hex("12345678").unwrap()); // locktime
+               target_value.append(&mut <Vec<u8>>::from_hex("013413a7").unwrap()); // feerate_sat_per_1000_weight
                if let Some((_, target)) = funding_value_with_hex_target {
                        target_value.push(0x00); // Type
                        target_value.push(target.len() as u8 / 2); // Length
-                       target_value.append(&mut hex::decode(target).unwrap()); // Value (i64)
+                       target_value.append(&mut <Vec<u8>>::from_hex(target).unwrap()); // Value (i64)
                }
                assert_eq!(encoded_value, target_value);
        }
@@ -3644,11 +3645,11 @@ mod tests {
                        funding_output_contribution: if let Some((value, _)) = funding_value_with_hex_target { Some(value) } else { None },
                };
                let encoded_value = tx_ack_rbf.encode();
-               let mut target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap();
+               let mut target_value = <Vec<u8>>::from_hex("0202020202020202020202020202020202020202020202020202020202020202").unwrap();
                if let Some((_, target)) = funding_value_with_hex_target {
                        target_value.push(0x00); // Type
                        target_value.push(target.len() as u8 / 2); // Length
-                       target_value.append(&mut hex::decode(target).unwrap()); // Value (i64)
+                       target_value.append(&mut <Vec<u8>>::from_hex(target).unwrap()); // Value (i64)
                }
                assert_eq!(encoded_value, target_value);
        }
@@ -3664,10 +3665,10 @@ mod tests {
        fn encoding_tx_abort() {
                let tx_abort = msgs::TxAbort {
                        channel_id: ChannelId::from_bytes([2; 32]),
-                       data: hex::decode("54686520717569636B2062726F776E20666F78206A756D7073206F76657220746865206C617A7920646F672E").unwrap(),
+                       data: <Vec<u8>>::from_hex("54686520717569636B2062726F776E20666F78206A756D7073206F76657220746865206C617A7920646F672E").unwrap(),
                };
                let encoded_value = tx_abort.encode();
-               let target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202002C54686520717569636B2062726F776E20666F78206A756D7073206F76657220746865206C617A7920646F672E").unwrap();
+               let target_value = <Vec<u8>>::from_hex("0202020202020202020202020202020202020202020202020202020202020202002C54686520717569636B2062726F776E20666F78206A756D7073206F76657220746865206C617A7920646F672E").unwrap();
                assert_eq!(encoded_value, target_value);
        }
 
@@ -3684,15 +3685,15 @@ mod tests {
                                else { Address::p2wsh(&script, Network::Testnet).script_pubkey() },
                };
                let encoded_value = shutdown.encode();
-               let mut target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap();
+               let mut target_value = <Vec<u8>>::from_hex("0202020202020202020202020202020202020202020202020202020202020202").unwrap();
                if script_type == 1 {
-                       target_value.append(&mut hex::decode("001976a91479b000887626b294a914501a4cd226b58b23598388ac").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("001976a91479b000887626b294a914501a4cd226b58b23598388ac").unwrap());
                } else if script_type == 2 {
-                       target_value.append(&mut hex::decode("0017a914da1745e9b549bd0bfa1a569971c77eba30cd5a4b87").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("0017a914da1745e9b549bd0bfa1a569971c77eba30cd5a4b87").unwrap());
                } else if script_type == 3 {
-                       target_value.append(&mut hex::decode("0016001479b000887626b294a914501a4cd226b58b235983").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("0016001479b000887626b294a914501a4cd226b58b235983").unwrap());
                } else if script_type == 4 {
-                       target_value.append(&mut hex::decode("002200204ae81572f06e1b88fd5ced7a1a000945432e83e1551e6f721ee9c00b8cc33260").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("002200204ae81572f06e1b88fd5ced7a1a000945432e83e1551e6f721ee9c00b8cc33260").unwrap());
                }
                assert_eq!(encoded_value, target_value);
        }
@@ -3717,7 +3718,7 @@ mod tests {
                        fee_range: None,
                };
                let encoded_value = closing_signed.encode();
-               let target_value = hex::decode("020202020202020202020202020202020202020202020202020202020202020200083a840000034dd977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a").unwrap();
+               let target_value = <Vec<u8>>::from_hex("020202020202020202020202020202020202020202020202020202020202020200083a840000034dd977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a").unwrap();
                assert_eq!(encoded_value, target_value);
                assert_eq!(msgs::ClosingSigned::read(&mut Cursor::new(&target_value)).unwrap(), closing_signed);
 
@@ -3731,7 +3732,7 @@ mod tests {
                        }),
                };
                let encoded_value_with_range = closing_signed_with_range.encode();
-               let target_value_with_range = hex::decode("020202020202020202020202020202020202020202020202020202020202020200083a840000034dd977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a011000000000deadbeef1badcafe01234567").unwrap();
+               let target_value_with_range = <Vec<u8>>::from_hex("020202020202020202020202020202020202020202020202020202020202020200083a840000034dd977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a011000000000deadbeef1badcafe01234567").unwrap();
                assert_eq!(encoded_value_with_range, target_value_with_range);
                assert_eq!(msgs::ClosingSigned::read(&mut Cursor::new(&target_value_with_range)).unwrap(),
                        closing_signed_with_range);
@@ -3757,7 +3758,7 @@ mod tests {
                        skimmed_fee_msat: None,
                };
                let encoded_value = update_add_htlc.encode();
-               let target_value = hex::decode("020202020202020202020202020202020202020202020202020202020202020200083a840000034d32144668701144760101010101010101010101010101010101010101010101010101010101010101000c89d4ff031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010202020202020202020202020202020202020202020202020202020202020202").unwrap();
+               let target_value = <Vec<u8>>::from_hex("020202020202020202020202020202020202020202020202020202020202020200083a840000034d32144668701144760101010101010101010101010101010101010101010101010101010101010101000c89d4ff031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010202020202020202020202020202020202020202020202020202020202020202").unwrap();
                assert_eq!(encoded_value, target_value);
        }
 
@@ -3769,7 +3770,7 @@ mod tests {
                        payment_preimage: PaymentPreimage([1; 32]),
                };
                let encoded_value = update_fulfill_htlc.encode();
-               let target_value = hex::decode("020202020202020202020202020202020202020202020202020202020202020200083a840000034d0101010101010101010101010101010101010101010101010101010101010101").unwrap();
+               let target_value = <Vec<u8>>::from_hex("020202020202020202020202020202020202020202020202020202020202020200083a840000034d0101010101010101010101010101010101010101010101010101010101010101").unwrap();
                assert_eq!(encoded_value, target_value);
        }
 
@@ -3784,7 +3785,7 @@ mod tests {
                        reason
                };
                let encoded_value = update_fail_htlc.encode();
-               let target_value = hex::decode("020202020202020202020202020202020202020202020202020202020202020200083a840000034d00200101010101010101010101010101010101010101010101010101010101010101").unwrap();
+               let target_value = <Vec<u8>>::from_hex("020202020202020202020202020202020202020202020202020202020202020200083a840000034d00200101010101010101010101010101010101010101010101010101010101010101").unwrap();
                assert_eq!(encoded_value, target_value);
        }
 
@@ -3797,7 +3798,7 @@ mod tests {
                        failure_code: 255
                };
                let encoded_value = update_fail_malformed_htlc.encode();
-               let target_value = hex::decode("020202020202020202020202020202020202020202020202020202020202020200083a840000034d010101010101010101010101010101010101010101010101010101010101010100ff").unwrap();
+               let target_value = <Vec<u8>>::from_hex("020202020202020202020202020202020202020202020202020202020202020200083a840000034d010101010101010101010101010101010101010101010101010101010101010100ff").unwrap();
                assert_eq!(encoded_value, target_value);
        }
 
@@ -3819,11 +3820,11 @@ mod tests {
                        partial_signature_with_nonce: None,
                };
                let encoded_value = commitment_signed.encode();
-               let mut target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a").unwrap();
+               let mut target_value = <Vec<u8>>::from_hex("0202020202020202020202020202020202020202020202020202020202020202d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a").unwrap();
                if htlcs {
-                       target_value.append(&mut hex::decode("00031735b6a427e80d5fe7cd90a2f4ee08dc9c27cda7c35a4172e5d85b12c49d4232537e98f9b1f3c5e6989a8b9644e90e8918127680dbd0d4043510840fc0f1e11a216c280b5395a2546e7e4b2663e04f811622f15a4f91e83aa2e92ba2a573c139142c54ae63072a1ec1ee7dc0c04bde5c847806172aa05c92c22ae8e308d1d2692b12cc195ce0a2d1bda6a88befa19fa07f51caa75ce83837f28965600b8aacab0855ffb0e741ec5f7c41421e9829a9d48611c8c831f71be5ea73e66594977ffd").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("00031735b6a427e80d5fe7cd90a2f4ee08dc9c27cda7c35a4172e5d85b12c49d4232537e98f9b1f3c5e6989a8b9644e90e8918127680dbd0d4043510840fc0f1e11a216c280b5395a2546e7e4b2663e04f811622f15a4f91e83aa2e92ba2a573c139142c54ae63072a1ec1ee7dc0c04bde5c847806172aa05c92c22ae8e308d1d2692b12cc195ce0a2d1bda6a88befa19fa07f51caa75ce83837f28965600b8aacab0855ffb0e741ec5f7c41421e9829a9d48611c8c831f71be5ea73e66594977ffd").unwrap());
                } else {
-                       target_value.append(&mut hex::decode("0000").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("0000").unwrap());
                }
                assert_eq!(encoded_value, target_value);
        }
@@ -3846,7 +3847,7 @@ mod tests {
                        next_local_nonce: None,
                };
                let encoded_value = raa.encode();
-               let target_value = hex::decode("02020202020202020202020202020202020202020202020202020202020202020101010101010101010101010101010101010101010101010101010101010101031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f").unwrap();
+               let target_value = <Vec<u8>>::from_hex("02020202020202020202020202020202020202020202020202020202020202020101010101010101010101010101010101010101010101010101010101010101031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f").unwrap();
                assert_eq!(encoded_value, target_value);
        }
 
@@ -3857,7 +3858,7 @@ mod tests {
                        feerate_per_kw: 20190119,
                };
                let encoded_value = update_fee.encode();
-               let target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202013413a7").unwrap();
+               let target_value = <Vec<u8>>::from_hex("0202020202020202020202020202020202020202020202020202020202020202013413a7").unwrap();
                assert_eq!(encoded_value, target_value);
        }
 
@@ -3868,22 +3869,22 @@ mod tests {
                        features: InitFeatures::from_le_bytes(vec![0xFF, 0xFF, 0xFF]),
                        networks: Some(vec![mainnet_hash]),
                        remote_network_address: None,
-               }.encode(), hex::decode("00023fff0003ffffff01206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap());
+               }.encode(), <Vec<u8>>::from_hex("00023fff0003ffffff01206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap());
                assert_eq!(msgs::Init {
                        features: InitFeatures::from_le_bytes(vec![0xFF]),
                        networks: None,
                        remote_network_address: None,
-               }.encode(), hex::decode("0001ff0001ff").unwrap());
+               }.encode(), <Vec<u8>>::from_hex("0001ff0001ff").unwrap());
                assert_eq!(msgs::Init {
                        features: InitFeatures::from_le_bytes(vec![]),
                        networks: Some(vec![mainnet_hash]),
                        remote_network_address: None,
-               }.encode(), hex::decode("0000000001206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap());
+               }.encode(), <Vec<u8>>::from_hex("0000000001206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap());
                assert_eq!(msgs::Init {
                        features: InitFeatures::from_le_bytes(vec![]),
-                       networks: Some(vec![ChainHash::from(&[1; 32][..]), ChainHash::from(&[2; 32][..])]),
+                       networks: Some(vec![ChainHash::from(&[1; 32]), ChainHash::from(&[2; 32])]),
                        remote_network_address: None,
-               }.encode(), hex::decode("00000000014001010101010101010101010101010101010101010101010101010101010101010202020202020202020202020202020202020202020202020202020202020202").unwrap());
+               }.encode(), <Vec<u8>>::from_hex("00000000014001010101010101010101010101010101010101010101010101010101010101010202020202020202020202020202020202020202020202020202020202020202").unwrap());
                let init_msg = msgs::Init { features: InitFeatures::from_le_bytes(vec![]),
                        networks: Some(vec![mainnet_hash]),
                        remote_network_address: Some(SocketAddress::TcpIpV4 {
@@ -3892,7 +3893,7 @@ mod tests {
                        }),
                };
                let encoded_value = init_msg.encode();
-               let target_value = hex::decode("0000000001206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d61900000000000307017f00000103e8").unwrap();
+               let target_value = <Vec<u8>>::from_hex("0000000001206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d61900000000000307017f00000103e8").unwrap();
                assert_eq!(encoded_value, target_value);
                assert_eq!(msgs::Init::read(&mut Cursor::new(&target_value)).unwrap(), init_msg);
        }
@@ -3904,7 +3905,7 @@ mod tests {
                        data: String::from("rust-lightning"),
                };
                let encoded_value = error.encode();
-               let target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202000e727573742d6c696768746e696e67").unwrap();
+               let target_value = <Vec<u8>>::from_hex("0202020202020202020202020202020202020202020202020202020202020202000e727573742d6c696768746e696e67").unwrap();
                assert_eq!(encoded_value, target_value);
        }
 
@@ -3915,7 +3916,7 @@ mod tests {
                        data: String::from("rust-lightning"),
                };
                let encoded_value = error.encode();
-               let target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202000e727573742d6c696768746e696e67").unwrap();
+               let target_value = <Vec<u8>>::from_hex("0202020202020202020202020202020202020202020202020202020202020202000e727573742d6c696768746e696e67").unwrap();
                assert_eq!(encoded_value, target_value);
        }
 
@@ -3926,7 +3927,7 @@ mod tests {
                        byteslen: 64
                };
                let encoded_value = ping.encode();
-               let target_value = hex::decode("0040004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap();
+               let target_value = <Vec<u8>>::from_hex("0040004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap();
                assert_eq!(encoded_value, target_value);
        }
 
@@ -3936,7 +3937,7 @@ mod tests {
                        byteslen: 64
                };
                let encoded_value = pong.encode();
-               let target_value = hex::decode("004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap();
+               let target_value = <Vec<u8>>::from_hex("004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap();
                assert_eq!(encoded_value, target_value);
        }
 
@@ -3948,7 +3949,7 @@ mod tests {
                        outgoing_cltv_value: 0xffffffff,
                };
                let encoded_value = outbound_msg.encode();
-               let target_value = hex::decode("1a02080badf00d010203040404ffffffff0608deadbeef1bad1dea").unwrap();
+               let target_value = <Vec<u8>>::from_hex("1a02080badf00d010203040404ffffffff0608deadbeef1bad1dea").unwrap();
                assert_eq!(encoded_value, target_value);
 
                let node_signer = test_utils::TestKeysInterface::new(&[42; 32], Network::Testnet);
@@ -3973,7 +3974,7 @@ mod tests {
                        custom_tlvs: vec![],
                };
                let encoded_value = outbound_msg.encode();
-               let target_value = hex::decode("1002080badf00d010203040404ffffffff").unwrap();
+               let target_value = <Vec<u8>>::from_hex("1002080badf00d010203040404ffffffff").unwrap();
                assert_eq!(encoded_value, target_value);
 
                let node_signer = test_utils::TestKeysInterface::new(&[42; 32], Network::Testnet);
@@ -4001,7 +4002,7 @@ mod tests {
                        custom_tlvs: vec![],
                };
                let encoded_value = outbound_msg.encode();
-               let target_value = hex::decode("3602080badf00d010203040404ffffffff082442424242424242424242424242424242424242424242424242424242424242421badca1f").unwrap();
+               let target_value = <Vec<u8>>::from_hex("3602080badf00d010203040404ffffffff082442424242424242424242424242424242424242424242424242424242424242421badca1f").unwrap();
                assert_eq!(encoded_value, target_value);
 
                let node_signer = test_utils::TestKeysInterface::new(&[42; 32], Network::Testnet);
@@ -4072,7 +4073,7 @@ mod tests {
                        outgoing_cltv_value: 0xffffffff,
                };
                let encoded_value = msg.encode();
-               let target_value = hex::decode("2e02080badf00d010203040404ffffffffff0000000146c6616b021234ff0000000146c6616f084242424242424242").unwrap();
+               let target_value = <Vec<u8>>::from_hex("2e02080badf00d010203040404ffffffffff0000000146c6616b021234ff0000000146c6616f084242424242424242").unwrap();
                assert_eq!(encoded_value, target_value);
                let node_signer = test_utils::TestKeysInterface::new(&[42; 32], Network::Testnet);
                let inbound_msg: msgs::InboundOnionPayload = ReadableArgs::read(&mut Cursor::new(&target_value[..]), &&node_signer).unwrap();
@@ -4117,7 +4118,7 @@ mod tests {
                        number_of_blocks: 1500,
                };
                let encoded_value = query_channel_range.encode();
-               let target_value = hex::decode("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f000186a0000005dc").unwrap();
+               let target_value = <Vec<u8>>::from_hex("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f000186a0000005dc").unwrap();
                assert_eq!(encoded_value, target_value);
 
                query_channel_range = Readable::read(&mut Cursor::new(&target_value[..])).unwrap();
@@ -4132,7 +4133,7 @@ mod tests {
        }
 
        fn do_encoding_reply_channel_range(encoding_type: u8) {
-               let mut target_value = hex::decode("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f000b8a06000005dc01").unwrap();
+               let mut target_value = <Vec<u8>>::from_hex("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f000b8a06000005dc01").unwrap();
                let expected_chain_hash = ChainHash::using_genesis_block(Network::Regtest);
                let mut reply_channel_range = msgs::ReplyChannelRange {
                        chain_hash: expected_chain_hash,
@@ -4143,7 +4144,7 @@ mod tests {
                };
 
                if encoding_type == 0 {
-                       target_value.append(&mut hex::decode("001900000000000000008e0000000000003c69000000000045a6c4").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("001900000000000000008e0000000000003c69000000000045a6c4").unwrap());
                        let encoded_value = reply_channel_range.encode();
                        assert_eq!(encoded_value, target_value);
 
@@ -4156,7 +4157,7 @@ mod tests {
                        assert_eq!(reply_channel_range.short_channel_ids[1], 0x0000000000003c69);
                        assert_eq!(reply_channel_range.short_channel_ids[2], 0x000000000045a6c4);
                } else {
-                       target_value.append(&mut hex::decode("001601789c636000833e08659309a65878be010010a9023a").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("001601789c636000833e08659309a65878be010010a9023a").unwrap());
                        let result: Result<msgs::ReplyChannelRange, msgs::DecodeError> = Readable::read(&mut Cursor::new(&target_value[..]));
                        assert!(result.is_err(), "Expected decode failure with unsupported zlib encoding");
                }
@@ -4169,7 +4170,7 @@ mod tests {
        }
 
        fn do_encoding_query_short_channel_ids(encoding_type: u8) {
-               let mut target_value = hex::decode("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f").unwrap();
+               let mut target_value = <Vec<u8>>::from_hex("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f").unwrap();
                let expected_chain_hash = ChainHash::using_genesis_block(Network::Regtest);
                let mut query_short_channel_ids = msgs::QueryShortChannelIds {
                        chain_hash: expected_chain_hash,
@@ -4177,7 +4178,7 @@ mod tests {
                };
 
                if encoding_type == 0 {
-                       target_value.append(&mut hex::decode("001900000000000000008e0000000000003c69000000000045a6c4").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("001900000000000000008e0000000000003c69000000000045a6c4").unwrap());
                        let encoded_value = query_short_channel_ids.encode();
                        assert_eq!(encoded_value, target_value);
 
@@ -4187,7 +4188,7 @@ mod tests {
                        assert_eq!(query_short_channel_ids.short_channel_ids[1], 0x0000000000003c69);
                        assert_eq!(query_short_channel_ids.short_channel_ids[2], 0x000000000045a6c4);
                } else {
-                       target_value.append(&mut hex::decode("001601789c636000833e08659309a65878be010010a9023a").unwrap());
+                       target_value.append(&mut <Vec<u8>>::from_hex("001601789c636000833e08659309a65878be010010a9023a").unwrap());
                        let result: Result<msgs::QueryShortChannelIds, msgs::DecodeError> = Readable::read(&mut Cursor::new(&target_value[..]));
                        assert!(result.is_err(), "Expected decode failure with unsupported zlib encoding");
                }
@@ -4201,7 +4202,7 @@ mod tests {
                        full_information: true,
                };
                let encoded_value = reply_short_channel_ids_end.encode();
-               let target_value = hex::decode("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f01").unwrap();
+               let target_value = <Vec<u8>>::from_hex("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f01").unwrap();
                assert_eq!(encoded_value, target_value);
 
                reply_short_channel_ids_end = Readable::read(&mut Cursor::new(&target_value[..])).unwrap();
@@ -4218,7 +4219,7 @@ mod tests {
                        timestamp_range: 0xffff_ffff,
                };
                let encoded_value = gossip_timestamp_filter.encode();
-               let target_value = hex::decode("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f5ec57980ffffffff").unwrap();
+               let target_value = <Vec<u8>>::from_hex("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f5ec57980ffffffff").unwrap();
                assert_eq!(encoded_value, target_value);
 
                gossip_timestamp_filter = Readable::read(&mut Cursor::new(&target_value[..])).unwrap();
index dce0d232f01613a4c1f3a97ca14c09aa334a35cb..cfdba07a2f2839af321bddfc1e9f0c5ec26abc63 100644 (file)
@@ -639,7 +639,7 @@ fn test_onion_failure() {
                        let um = onion_utils::gen_um_from_shared_secret(&onion_keys[1].shared_secret.as_ref());
                        let mut hmac = HmacEngine::<Sha256>::new(&um);
                        hmac.input(&decoded_err_packet.encode()[32..]);
-                       decoded_err_packet.hmac = Hmac::from_engine(hmac).into_inner();
+                       decoded_err_packet.hmac = Hmac::from_engine(hmac).to_byte_array();
                        msg.reason = onion_utils::encrypt_failure_packet(
                                &onion_keys[1].shared_secret.as_ref(), &decoded_err_packet.encode()[..])
                }, || nodes[2].node.fail_htlc_backwards(&payment_hash), false, None,
@@ -662,7 +662,7 @@ fn test_onion_failure() {
                        let um = onion_utils::gen_um_from_shared_secret(&onion_keys[0].shared_secret.as_ref());
                        let mut hmac = HmacEngine::<Sha256>::new(&um);
                        hmac.input(&decoded_err_packet.encode()[32..]);
-                       decoded_err_packet.hmac = Hmac::from_engine(hmac).into_inner();
+                       decoded_err_packet.hmac = Hmac::from_engine(hmac).to_byte_array();
                        msg.reason = onion_utils::encrypt_failure_packet(
                                &onion_keys[0].shared_secret.as_ref(), &decoded_err_packet.encode()[..])
                }, || {}, true, Some(0x1000|7),
@@ -686,7 +686,7 @@ fn test_onion_failure() {
                        let um = onion_utils::gen_um_from_shared_secret(&onion_keys[1].shared_secret.as_ref());
                        let mut hmac = HmacEngine::<Sha256>::new(&um);
                        hmac.input(&decoded_err_packet.encode()[32..]);
-                       decoded_err_packet.hmac = Hmac::from_engine(hmac).into_inner();
+                       decoded_err_packet.hmac = Hmac::from_engine(hmac).to_byte_array();
                        msg.reason = onion_utils::encrypt_failure_packet(
                                &onion_keys[1].shared_secret.as_ref(), &decoded_err_packet.encode()[..])
                }, || nodes[2].node.fail_htlc_backwards(&payment_hash), true, Some(0x1000|7),
@@ -1119,7 +1119,7 @@ fn test_phantom_onion_hmac_failure() {
                                }, ..
                        }) => {
                                onion_packet.hmac[onion_packet.hmac.len() - 1] ^= 1;
-                               Sha256::hash(&onion_packet.hop_data).into_inner().to_vec()
+                               Sha256::hash(&onion_packet.hop_data).to_byte_array().to_vec()
                        },
                        _ => panic!("Unexpected forward"),
                }
index e952bd8e2e125c5d8c16ef6f8419e1c8a2579ba0..31f2f7827bcb57c42d7b2a625a842abdaa00ab17 100644 (file)
@@ -49,7 +49,7 @@ pub(crate) fn gen_rho_from_shared_secret(shared_secret: &[u8]) -> [u8; 32] {
        assert_eq!(shared_secret.len(), 32);
        let mut hmac = HmacEngine::<Sha256>::new(&[0x72, 0x68, 0x6f]); // rho
        hmac.input(&shared_secret);
-       Hmac::from_engine(hmac).into_inner()
+       Hmac::from_engine(hmac).to_byte_array()
 }
 
 #[inline]
@@ -58,12 +58,12 @@ pub(crate) fn gen_rho_mu_from_shared_secret(shared_secret: &[u8]) -> ([u8; 32],
        ({
                let mut hmac = HmacEngine::<Sha256>::new(&[0x72, 0x68, 0x6f]); // rho
                hmac.input(&shared_secret);
-               Hmac::from_engine(hmac).into_inner()
+               Hmac::from_engine(hmac).to_byte_array()
        },
        {
                let mut hmac = HmacEngine::<Sha256>::new(&[0x6d, 0x75]); // mu
                hmac.input(&shared_secret);
-               Hmac::from_engine(hmac).into_inner()
+               Hmac::from_engine(hmac).to_byte_array()
        })
 }
 
@@ -72,7 +72,7 @@ pub(super) fn gen_um_from_shared_secret(shared_secret: &[u8]) -> [u8; 32] {
        assert_eq!(shared_secret.len(), 32);
        let mut hmac = HmacEngine::<Sha256>::new(&[0x75, 0x6d]); // um
        hmac.input(&shared_secret);
-       Hmac::from_engine(hmac).into_inner()
+       Hmac::from_engine(hmac).to_byte_array()
 }
 
 #[inline]
@@ -80,7 +80,7 @@ pub(super) fn gen_ammag_from_shared_secret(shared_secret: &[u8]) -> [u8; 32] {
        assert_eq!(shared_secret.len(), 32);
        let mut hmac = HmacEngine::<Sha256>::new(&[0x61, 0x6d, 0x6d, 0x61, 0x67]); // ammag
        hmac.input(&shared_secret);
-       Hmac::from_engine(hmac).into_inner()
+       Hmac::from_engine(hmac).to_byte_array()
 }
 
 #[cfg(test)]
@@ -89,7 +89,7 @@ pub(super) fn gen_pad_from_shared_secret(shared_secret: &[u8]) -> [u8; 32] {
        assert_eq!(shared_secret.len(), 32);
        let mut hmac = HmacEngine::<Sha256>::new(&[0x70, 0x61, 0x64]); // pad
        hmac.input(&shared_secret);
-       Hmac::from_engine(hmac).into_inner()
+       Hmac::from_engine(hmac).to_byte_array()
 }
 
 /// Calculates a pubkey for the next hop, such as the next hop's packet pubkey or blinding point.
@@ -100,7 +100,7 @@ pub(crate) fn next_hop_pubkey<T: secp256k1::Verification>(
                let mut sha = Sha256::engine();
                sha.input(&curr_pubkey.serialize()[..]);
                sha.input(shared_secret);
-               Sha256::from_engine(sha).into_inner()
+               Sha256::from_engine(sha).to_byte_array()
        };
 
        curr_pubkey.mul_tweak(secp_ctx, &Scalar::from_be_bytes(blinding_factor).unwrap())
@@ -129,7 +129,7 @@ where
                let mut sha = Sha256::engine();
                sha.input(&blinded_pub.serialize()[..]);
                sha.input(shared_secret.as_ref());
-               let blinding_factor = Sha256::from_engine(sha).into_inner();
+               let blinding_factor = Sha256::from_engine(sha).to_byte_array();
 
                let ephemeral_pubkey = blinded_pub;
 
@@ -366,7 +366,7 @@ fn construct_onion_packet_with_init_noise<HD: Writeable, P: Packet>(
                if let Some(associated_data) = associated_data {
                        hmac.input(&associated_data.0[..]);
                }
-               hmac_res = Hmac::from_engine(hmac).into_inner();
+               hmac_res = Hmac::from_engine(hmac).to_byte_array();
        }
 
        Ok(P::new(onion_keys.first().unwrap().ephemeral_pubkey, packet_data, hmac_res))
@@ -412,7 +412,7 @@ pub(super) fn build_failure_packet(shared_secret: &[u8], failure_type: u16, fail
 
        let mut hmac = HmacEngine::<Sha256>::new(&um);
        hmac.input(&packet.encode()[32..]);
-       packet.hmac = Hmac::from_engine(hmac).into_inner();
+       packet.hmac = Hmac::from_engine(hmac).to_byte_array();
 
        packet
 }
@@ -520,7 +520,7 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
                let mut hmac = HmacEngine::<Sha256>::new(&um);
                hmac.input(&err_packet.encode()[32..]);
 
-               if !fixed_time_eq(&Hmac::from_engine(hmac).into_inner(), &err_packet.hmac) { return }
+               if !fixed_time_eq(&Hmac::from_engine(hmac).to_byte_array(), &err_packet.hmac) { return }
                let error_code_slice = match err_packet.failuremsg.get(0..2) {
                        Some(s) => s,
                        None => {
@@ -967,7 +967,7 @@ fn decode_next_hop<T, R: ReadableArgs<T>, N: NextPacketBytes>(shared_secret: [u8
        if let Some(tag) = payment_hash {
                hmac.input(&tag.0[..]);
        }
-       if !fixed_time_eq(&Hmac::from_engine(hmac).into_inner(), &hmac_bytes) {
+       if !fixed_time_eq(&Hmac::from_engine(hmac).to_byte_array(), &hmac_bytes) {
                return Err(OnionDecodeErr::Malformed {
                        err_msg: "HMAC Check failed",
                        err_code: 0x8000 | 0x4000 | 5,
@@ -1047,15 +1047,14 @@ mod tests {
        use crate::ln::msgs;
        use crate::util::ser::{Writeable, Writer, VecWriter};
 
-       use hex;
-
+       use bitcoin::hashes::hex::FromHex;
        use bitcoin::secp256k1::Secp256k1;
        use bitcoin::secp256k1::{PublicKey,SecretKey};
 
        use super::OnionKeys;
 
        fn get_test_session_key() -> SecretKey {
-               SecretKey::from_slice(&hex::decode("4141414141414141414141414141414141414141414141414141414141414141").unwrap()[..]).unwrap()
+               SecretKey::from_slice(&<Vec<u8>>::from_hex("4141414141414141414141414141414141414141414141414141414141414141").unwrap()[..]).unwrap()
        }
 
        fn build_test_onion_keys() -> Vec<OnionKeys> {
@@ -1065,27 +1064,27 @@ mod tests {
                let route = Route {
                        paths: vec![Path { hops: vec![
                                        RouteHop {
-                                               pubkey: PublicKey::from_slice(&hex::decode("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]).unwrap(),
+                                               pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]).unwrap(),
                                                channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
                                                short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0, maybe_announced_channel: true, // We fill in the payloads manually instead of generating them from RouteHops.
                                        },
                                        RouteHop {
-                                               pubkey: PublicKey::from_slice(&hex::decode("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c").unwrap()[..]).unwrap(),
+                                               pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c").unwrap()[..]).unwrap(),
                                                channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
                                                short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0, maybe_announced_channel: true, // We fill in the payloads manually instead of generating them from RouteHops.
                                        },
                                        RouteHop {
-                                               pubkey: PublicKey::from_slice(&hex::decode("027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007").unwrap()[..]).unwrap(),
+                                               pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007").unwrap()[..]).unwrap(),
                                                channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
                                                short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0, maybe_announced_channel: true, // We fill in the payloads manually instead of generating them from RouteHops.
                                        },
                                        RouteHop {
-                                               pubkey: PublicKey::from_slice(&hex::decode("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991").unwrap()[..]).unwrap(),
+                                               pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991").unwrap()[..]).unwrap(),
                                                channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
                                                short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0, maybe_announced_channel: true, // We fill in the payloads manually instead of generating them from RouteHops.
                                        },
                                        RouteHop {
-                                               pubkey: PublicKey::from_slice(&hex::decode("02edabbd16b41c8371b92ef2f04c1185b4f03b6dcd52ba9b78d9d7c89c8f221145").unwrap()[..]).unwrap(),
+                                               pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("02edabbd16b41c8371b92ef2f04c1185b4f03b6dcd52ba9b78d9d7c89c8f221145").unwrap()[..]).unwrap(),
                                                channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
                                                short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0, maybe_announced_channel: true, // We fill in the payloads manually instead of generating them from RouteHops.
                                        },
@@ -1104,35 +1103,35 @@ mod tests {
 
                // Test generation of ephemeral keys and secrets. These values used to be part of the BOLT4
                // test vectors, but have since been removed. We keep them as they provide test coverage.
-               assert_eq!(onion_keys[0].shared_secret.secret_bytes(), hex::decode("53eb63ea8a3fec3b3cd433b85cd62a4b145e1dda09391b348c4e1cd36a03ea66").unwrap()[..]);
-               assert_eq!(onion_keys[0].blinding_factor[..], hex::decode("2ec2e5da605776054187180343287683aa6a51b4b1c04d6dd49c45d8cffb3c36").unwrap()[..]);
-               assert_eq!(onion_keys[0].ephemeral_pubkey.serialize()[..], hex::decode("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]);
-               assert_eq!(onion_keys[0].rho, hex::decode("ce496ec94def95aadd4bec15cdb41a740c9f2b62347c4917325fcc6fb0453986").unwrap()[..]);
-               assert_eq!(onion_keys[0].mu, hex::decode("b57061dc6d0a2b9f261ac410c8b26d64ac5506cbba30267a649c28c179400eba").unwrap()[..]);
-
-               assert_eq!(onion_keys[1].shared_secret.secret_bytes(), hex::decode("a6519e98832a0b179f62123b3567c106db99ee37bef036e783263602f3488fae").unwrap()[..]);
-               assert_eq!(onion_keys[1].blinding_factor[..], hex::decode("bf66c28bc22e598cfd574a1931a2bafbca09163df2261e6d0056b2610dab938f").unwrap()[..]);
-               assert_eq!(onion_keys[1].ephemeral_pubkey.serialize()[..], hex::decode("028f9438bfbf7feac2e108d677e3a82da596be706cc1cf342b75c7b7e22bf4e6e2").unwrap()[..]);
-               assert_eq!(onion_keys[1].rho, hex::decode("450ffcabc6449094918ebe13d4f03e433d20a3d28a768203337bc40b6e4b2c59").unwrap()[..]);
-               assert_eq!(onion_keys[1].mu, hex::decode("05ed2b4a3fb023c2ff5dd6ed4b9b6ea7383f5cfe9d59c11d121ec2c81ca2eea9").unwrap()[..]);
-
-               assert_eq!(onion_keys[2].shared_secret.secret_bytes(), hex::decode("3a6b412548762f0dbccce5c7ae7bb8147d1caf9b5471c34120b30bc9c04891cc").unwrap()[..]);
-               assert_eq!(onion_keys[2].blinding_factor[..], hex::decode("a1f2dadd184eb1627049673f18c6325814384facdee5bfd935d9cb031a1698a5").unwrap()[..]);
-               assert_eq!(onion_keys[2].ephemeral_pubkey.serialize()[..], hex::decode("03bfd8225241ea71cd0843db7709f4c222f62ff2d4516fd38b39914ab6b83e0da0").unwrap()[..]);
-               assert_eq!(onion_keys[2].rho, hex::decode("11bf5c4f960239cb37833936aa3d02cea82c0f39fd35f566109c41f9eac8deea").unwrap()[..]);
-               assert_eq!(onion_keys[2].mu, hex::decode("caafe2820fa00eb2eeb78695ae452eba38f5a53ed6d53518c5c6edf76f3f5b78").unwrap()[..]);
-
-               assert_eq!(onion_keys[3].shared_secret.secret_bytes(), hex::decode("21e13c2d7cfe7e18836df50872466117a295783ab8aab0e7ecc8c725503ad02d").unwrap()[..]);
-               assert_eq!(onion_keys[3].blinding_factor[..], hex::decode("7cfe0b699f35525029ae0fa437c69d0f20f7ed4e3916133f9cacbb13c82ff262").unwrap()[..]);
-               assert_eq!(onion_keys[3].ephemeral_pubkey.serialize()[..], hex::decode("031dde6926381289671300239ea8e57ffaf9bebd05b9a5b95beaf07af05cd43595").unwrap()[..]);
-               assert_eq!(onion_keys[3].rho, hex::decode("cbe784ab745c13ff5cffc2fbe3e84424aa0fd669b8ead4ee562901a4a4e89e9e").unwrap()[..]);
-               assert_eq!(onion_keys[3].mu, hex::decode("5052aa1b3d9f0655a0932e50d42f0c9ba0705142c25d225515c45f47c0036ee9").unwrap()[..]);
-
-               assert_eq!(onion_keys[4].shared_secret.secret_bytes(), hex::decode("b5756b9b542727dbafc6765a49488b023a725d631af688fc031217e90770c328").unwrap()[..]);
-               assert_eq!(onion_keys[4].blinding_factor[..], hex::decode("c96e00dddaf57e7edcd4fb5954be5b65b09f17cb6d20651b4e90315be5779205").unwrap()[..]);
-               assert_eq!(onion_keys[4].ephemeral_pubkey.serialize()[..], hex::decode("03a214ebd875aab6ddfd77f22c5e7311d7f77f17a169e599f157bbcdae8bf071f4").unwrap()[..]);
-               assert_eq!(onion_keys[4].rho, hex::decode("034e18b8cc718e8af6339106e706c52d8df89e2b1f7e9142d996acf88df8799b").unwrap()[..]);
-               assert_eq!(onion_keys[4].mu, hex::decode("8e45e5c61c2b24cb6382444db6698727afb063adecd72aada233d4bf273d975a").unwrap()[..]);
+               assert_eq!(onion_keys[0].shared_secret.secret_bytes(), <Vec<u8>>::from_hex("53eb63ea8a3fec3b3cd433b85cd62a4b145e1dda09391b348c4e1cd36a03ea66").unwrap()[..]);
+               assert_eq!(onion_keys[0].blinding_factor[..], <Vec<u8>>::from_hex("2ec2e5da605776054187180343287683aa6a51b4b1c04d6dd49c45d8cffb3c36").unwrap()[..]);
+               assert_eq!(onion_keys[0].ephemeral_pubkey.serialize()[..], <Vec<u8>>::from_hex("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]);
+               assert_eq!(onion_keys[0].rho, <Vec<u8>>::from_hex("ce496ec94def95aadd4bec15cdb41a740c9f2b62347c4917325fcc6fb0453986").unwrap()[..]);
+               assert_eq!(onion_keys[0].mu, <Vec<u8>>::from_hex("b57061dc6d0a2b9f261ac410c8b26d64ac5506cbba30267a649c28c179400eba").unwrap()[..]);
+
+               assert_eq!(onion_keys[1].shared_secret.secret_bytes(), <Vec<u8>>::from_hex("a6519e98832a0b179f62123b3567c106db99ee37bef036e783263602f3488fae").unwrap()[..]);
+               assert_eq!(onion_keys[1].blinding_factor[..], <Vec<u8>>::from_hex("bf66c28bc22e598cfd574a1931a2bafbca09163df2261e6d0056b2610dab938f").unwrap()[..]);
+               assert_eq!(onion_keys[1].ephemeral_pubkey.serialize()[..], <Vec<u8>>::from_hex("028f9438bfbf7feac2e108d677e3a82da596be706cc1cf342b75c7b7e22bf4e6e2").unwrap()[..]);
+               assert_eq!(onion_keys[1].rho, <Vec<u8>>::from_hex("450ffcabc6449094918ebe13d4f03e433d20a3d28a768203337bc40b6e4b2c59").unwrap()[..]);
+               assert_eq!(onion_keys[1].mu, <Vec<u8>>::from_hex("05ed2b4a3fb023c2ff5dd6ed4b9b6ea7383f5cfe9d59c11d121ec2c81ca2eea9").unwrap()[..]);
+
+               assert_eq!(onion_keys[2].shared_secret.secret_bytes(), <Vec<u8>>::from_hex("3a6b412548762f0dbccce5c7ae7bb8147d1caf9b5471c34120b30bc9c04891cc").unwrap()[..]);
+               assert_eq!(onion_keys[2].blinding_factor[..], <Vec<u8>>::from_hex("a1f2dadd184eb1627049673f18c6325814384facdee5bfd935d9cb031a1698a5").unwrap()[..]);
+               assert_eq!(onion_keys[2].ephemeral_pubkey.serialize()[..], <Vec<u8>>::from_hex("03bfd8225241ea71cd0843db7709f4c222f62ff2d4516fd38b39914ab6b83e0da0").unwrap()[..]);
+               assert_eq!(onion_keys[2].rho, <Vec<u8>>::from_hex("11bf5c4f960239cb37833936aa3d02cea82c0f39fd35f566109c41f9eac8deea").unwrap()[..]);
+               assert_eq!(onion_keys[2].mu, <Vec<u8>>::from_hex("caafe2820fa00eb2eeb78695ae452eba38f5a53ed6d53518c5c6edf76f3f5b78").unwrap()[..]);
+
+               assert_eq!(onion_keys[3].shared_secret.secret_bytes(), <Vec<u8>>::from_hex("21e13c2d7cfe7e18836df50872466117a295783ab8aab0e7ecc8c725503ad02d").unwrap()[..]);
+               assert_eq!(onion_keys[3].blinding_factor[..], <Vec<u8>>::from_hex("7cfe0b699f35525029ae0fa437c69d0f20f7ed4e3916133f9cacbb13c82ff262").unwrap()[..]);
+               assert_eq!(onion_keys[3].ephemeral_pubkey.serialize()[..], <Vec<u8>>::from_hex("031dde6926381289671300239ea8e57ffaf9bebd05b9a5b95beaf07af05cd43595").unwrap()[..]);
+               assert_eq!(onion_keys[3].rho, <Vec<u8>>::from_hex("cbe784ab745c13ff5cffc2fbe3e84424aa0fd669b8ead4ee562901a4a4e89e9e").unwrap()[..]);
+               assert_eq!(onion_keys[3].mu, <Vec<u8>>::from_hex("5052aa1b3d9f0655a0932e50d42f0c9ba0705142c25d225515c45f47c0036ee9").unwrap()[..]);
+
+               assert_eq!(onion_keys[4].shared_secret.secret_bytes(), <Vec<u8>>::from_hex("b5756b9b542727dbafc6765a49488b023a725d631af688fc031217e90770c328").unwrap()[..]);
+               assert_eq!(onion_keys[4].blinding_factor[..], <Vec<u8>>::from_hex("c96e00dddaf57e7edcd4fb5954be5b65b09f17cb6d20651b4e90315be5779205").unwrap()[..]);
+               assert_eq!(onion_keys[4].ephemeral_pubkey.serialize()[..], <Vec<u8>>::from_hex("03a214ebd875aab6ddfd77f22c5e7311d7f77f17a169e599f157bbcdae8bf071f4").unwrap()[..]);
+               assert_eq!(onion_keys[4].rho, <Vec<u8>>::from_hex("034e18b8cc718e8af6339106e706c52d8df89e2b1f7e9142d996acf88df8799b").unwrap()[..]);
+               assert_eq!(onion_keys[4].mu, <Vec<u8>>::from_hex("8e45e5c61c2b24cb6382444db6698727afb063adecd72aada233d4bf273d975a").unwrap()[..]);
 
                // Packet creation test vectors from BOLT 4 (see
                // https://github.com/lightning/bolts/blob/16973e2b857e853308cafd59e42fa830d75b1642/bolt04/onion-test.json).
@@ -1161,7 +1160,7 @@ mod tests {
                        5. custom_record "fd02013c0102030405060708090a0b0c0d0e0f0102030405060708090a0b0c0d0e0f0102030405060708090a0b0c0d0e0f0102030405060708090a0b0c0d0e0f"
                        */
                        RawOnionHopData {
-                               data: hex::decode("52020236b00402057806080000000000000002fd02013c0102030405060708090a0b0c0d0e0f0102030405060708090a0b0c0d0e0f0102030405060708090a0b0c0d0e0f0102030405060708090a0b0c0d0e0f").unwrap(),
+                               data: <Vec<u8>>::from_hex("52020236b00402057806080000000000000002fd02013c0102030405060708090a0b0c0d0e0f0102030405060708090a0b0c0d0e0f0102030405060708090a0b0c0d0e0f0102030405060708090a0b0c0d0e0f").unwrap(),
                        },
                        RawOnionHopData::new(msgs::OutboundOnionPayload::Forward {
                                short_channel_id: 3,
@@ -1189,7 +1188,7 @@ mod tests {
                        4. custom_record "fd012de02a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a"
                        */
                        RawOnionHopData {
-                               data: hex::decode("fd011002022710040203e8082224a33562c54507a9334e79f0dc4f17d407e6d7c61f0e2f3d0d38599502f617042710fd012de02a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a").unwrap(),
+                               data: <Vec<u8>>::from_hex("fd011002022710040203e8082224a33562c54507a9334e79f0dc4f17d407e6d7c61f0e2f3d0d38599502f617042710fd012de02a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a").unwrap(),
                        },
                );
 
@@ -1197,26 +1196,26 @@ mod tests {
                let mut w = VecWriter(Vec::new());
                payloads[0].write(&mut w).unwrap();
                let hop_1_serialized_payload = w.0;
-               let expected_serialized_hop_1_payload = &hex::decode("1202023a98040205dc06080000000000000001").unwrap()[..];
+               let expected_serialized_hop_1_payload = &<Vec<u8>>::from_hex("1202023a98040205dc06080000000000000001").unwrap()[..];
                assert_eq!(hop_1_serialized_payload, expected_serialized_hop_1_payload);
 
                w = VecWriter(Vec::new());
                payloads[2].write(&mut w).unwrap();
                let hop_3_serialized_payload = w.0;
-               let expected_serialized_hop_3_payload = &hex::decode("12020230d4040204e206080000000000000003").unwrap()[..];
+               let expected_serialized_hop_3_payload = &<Vec<u8>>::from_hex("12020230d4040204e206080000000000000003").unwrap()[..];
                assert_eq!(hop_3_serialized_payload, expected_serialized_hop_3_payload);
 
                w = VecWriter(Vec::new());
                payloads[3].write(&mut w).unwrap();
                let hop_4_serialized_payload = w.0;
-               let expected_serialized_hop_4_payload = &hex::decode("1202022710040203e806080000000000000004").unwrap()[..];
+               let expected_serialized_hop_4_payload = &<Vec<u8>>::from_hex("1202022710040203e806080000000000000004").unwrap()[..];
                assert_eq!(hop_4_serialized_payload, expected_serialized_hop_4_payload);
 
                let pad_keytype_seed = super::gen_pad_from_shared_secret(&get_test_session_key().secret_bytes());
 
                let packet: msgs::OnionPacket = super::construct_onion_packet_with_writable_hopdata::<_>(payloads, onion_keys, pad_keytype_seed, &PaymentHash([0x42; 32])).unwrap();
 
-               assert_eq!(packet.encode(), hex::decode("0002EEC7245D6B7D2CCB30380BFBE2A3648CD7A942653F5AA340EDCEA1F283686619F7F3416A5AA36DC7EEB3EC6D421E9615471AB870A33AC07FA5D5A51DF0A8823AABE3FEA3F90D387529D4F72837F9E687230371CCD8D263072206DBED0234F6505E21E282ABD8C0E4F5B9FF8042800BBAB065036EADD0149B37F27DDE664725A49866E052E809D2B0198AB9610FAA656BBF4EC516763A59F8F42C171B179166BA38958D4F51B39B3E98706E2D14A2DAFD6A5DF808093ABFCA5AEAACA16EDED5DB7D21FB0294DD1A163EDF0FB445D5C8D7D688D6DD9C541762BF5A5123BF9939D957FE648416E88F1B0928BFA034982B22548E1A4D922690EECF546275AFB233ACF4323974680779F1A964CFE687456035CC0FBA8A5428430B390F0057B6D1FE9A8875BFA89693EEB838CE59F09D207A503EE6F6299C92D6361BC335FCBF9B5CD44747AADCE2CE6069CFDC3D671DAEF9F8AE590CF93D957C9E873E9A1BC62D9640DC8FC39C14902D49A1C80239B6C5B7FD91D05878CBF5FFC7DB2569F47C43D6C0D27C438ABFF276E87364DEB8858A37E5A62C446AF95D8B786EAF0B5FCF78D98B41496794F8DCAAC4EEF34B2ACFB94C7E8C32A9E9866A8FA0B6F2A06F00A1CCDE569F97EEC05C803BA7500ACC96691D8898D73D8E6A47B8F43C3D5DE74458D20EDA61474C426359677001FBD75A74D7D5DB6CB4FEB83122F133206203E4E2D293F838BF8C8B3A29ACB321315100B87E80E0EDB272EE80FDA944E3FB6084ED4D7F7C7D21C69D9DA43D31A90B70693F9B0CC3EAC74C11AB8FF655905688916CFA4EF0BD04135F2E50B7C689A21D04E8E981E74C6058188B9B1F9DFC3EEC6838E9FFBCF22CE738D8A177C19318DFFEF090CEE67E12DE1A3E2A39F61247547BA5257489CBC11D7D91ED34617FCC42F7A9DA2E3CF31A94A210A1018143173913C38F60E62B24BF0D7518F38B5BAB3E6A1F8AEB35E31D6442C8ABB5178EFC892D2E787D79C6AD9E2FC271792983FA9955AC4D1D84A36C024071BC6E431B625519D556AF38185601F70E29035EA6A09C8B676C9D88CF7E05E0F17098B584C4168735940263F940033A220F40BE4C85344128B14BEB9E75696DB37014107801A59B13E89CD9D2258C169D523BE6D31552C44C82FF4BB18EC9F099F3BF0E5B1BB2BA9A87D7E26F98D294927B600B5529C47E04D98956677CBCEE8FA2B60F49776D8B8C367465B7C626DA53700684FB6C918EAD0EAB8360E4F60EDD25B4F43816A75ECF70F909301825B512469F8389D79402311D8AECB7B3EF8599E79485A4388D87744D899F7C47EE644361E17040A7958C8911BE6F463AB6A9B2AFACD688EC55EF517B38F1339EFC54487232798BB25522FF4572FF68567FE830F92F7B8113EFCE3E98C3FFFBAEDCE4FD8B50E41DA97C0C08E423A72689CC68E68F752A5E3A9003E64E35C957CA2E1C48BB6F64B05F56B70B575AD2F278D57850A7AD568C24A4D32A3D74B29F03DC125488BC7C637DA582357F40B0A52D16B3B40BB2C2315D03360BC24209E20972C200566BCF3BBE5C5B0AEDD83132A8A4D5B4242BA370B6D67D9B67EB01052D132C7866B9CB502E44796D9D356E4E3CB47CC527322CD24976FE7C9257A2864151A38E568EF7A79F10D6EF27CC04CE382347A2488B1F404FDBF407FE1CA1C9D0D5649E34800E25E18951C98CAE9F43555EEF65FEE1EA8F15828807366C3B612CD5753BF9FB8FCED08855F742CDDD6F765F74254F03186683D646E6F09AC2805586C7CF11998357CAFC5DF3F285329366F475130C928B2DCEBA4AA383758E7A9D20705C4BB9DB619E2992F608A1BA65DB254BB389468741D0502E2588AEB54390AC600C19AF5C8E61383FC1BEBE0029E4474051E4EF908828DB9CCA13277EF65DB3FD47CCC2179126AAEFB627719F421E20").unwrap());
+               assert_eq!(packet.encode(), <Vec<u8>>::from_hex("0002EEC7245D6B7D2CCB30380BFBE2A3648CD7A942653F5AA340EDCEA1F283686619F7F3416A5AA36DC7EEB3EC6D421E9615471AB870A33AC07FA5D5A51DF0A8823AABE3FEA3F90D387529D4F72837F9E687230371CCD8D263072206DBED0234F6505E21E282ABD8C0E4F5B9FF8042800BBAB065036EADD0149B37F27DDE664725A49866E052E809D2B0198AB9610FAA656BBF4EC516763A59F8F42C171B179166BA38958D4F51B39B3E98706E2D14A2DAFD6A5DF808093ABFCA5AEAACA16EDED5DB7D21FB0294DD1A163EDF0FB445D5C8D7D688D6DD9C541762BF5A5123BF9939D957FE648416E88F1B0928BFA034982B22548E1A4D922690EECF546275AFB233ACF4323974680779F1A964CFE687456035CC0FBA8A5428430B390F0057B6D1FE9A8875BFA89693EEB838CE59F09D207A503EE6F6299C92D6361BC335FCBF9B5CD44747AADCE2CE6069CFDC3D671DAEF9F8AE590CF93D957C9E873E9A1BC62D9640DC8FC39C14902D49A1C80239B6C5B7FD91D05878CBF5FFC7DB2569F47C43D6C0D27C438ABFF276E87364DEB8858A37E5A62C446AF95D8B786EAF0B5FCF78D98B41496794F8DCAAC4EEF34B2ACFB94C7E8C32A9E9866A8FA0B6F2A06F00A1CCDE569F97EEC05C803BA7500ACC96691D8898D73D8E6A47B8F43C3D5DE74458D20EDA61474C426359677001FBD75A74D7D5DB6CB4FEB83122F133206203E4E2D293F838BF8C8B3A29ACB321315100B87E80E0EDB272EE80FDA944E3FB6084ED4D7F7C7D21C69D9DA43D31A90B70693F9B0CC3EAC74C11AB8FF655905688916CFA4EF0BD04135F2E50B7C689A21D04E8E981E74C6058188B9B1F9DFC3EEC6838E9FFBCF22CE738D8A177C19318DFFEF090CEE67E12DE1A3E2A39F61247547BA5257489CBC11D7D91ED34617FCC42F7A9DA2E3CF31A94A210A1018143173913C38F60E62B24BF0D7518F38B5BAB3E6A1F8AEB35E31D6442C8ABB5178EFC892D2E787D79C6AD9E2FC271792983FA9955AC4D1D84A36C024071BC6E431B625519D556AF38185601F70E29035EA6A09C8B676C9D88CF7E05E0F17098B584C4168735940263F940033A220F40BE4C85344128B14BEB9E75696DB37014107801A59B13E89CD9D2258C169D523BE6D31552C44C82FF4BB18EC9F099F3BF0E5B1BB2BA9A87D7E26F98D294927B600B5529C47E04D98956677CBCEE8FA2B60F49776D8B8C367465B7C626DA53700684FB6C918EAD0EAB8360E4F60EDD25B4F43816A75ECF70F909301825B512469F8389D79402311D8AECB7B3EF8599E79485A4388D87744D899F7C47EE644361E17040A7958C8911BE6F463AB6A9B2AFACD688EC55EF517B38F1339EFC54487232798BB25522FF4572FF68567FE830F92F7B8113EFCE3E98C3FFFBAEDCE4FD8B50E41DA97C0C08E423A72689CC68E68F752A5E3A9003E64E35C957CA2E1C48BB6F64B05F56B70B575AD2F278D57850A7AD568C24A4D32A3D74B29F03DC125488BC7C637DA582357F40B0A52D16B3B40BB2C2315D03360BC24209E20972C200566BCF3BBE5C5B0AEDD83132A8A4D5B4242BA370B6D67D9B67EB01052D132C7866B9CB502E44796D9D356E4E3CB47CC527322CD24976FE7C9257A2864151A38E568EF7A79F10D6EF27CC04CE382347A2488B1F404FDBF407FE1CA1C9D0D5649E34800E25E18951C98CAE9F43555EEF65FEE1EA8F15828807366C3B612CD5753BF9FB8FCED08855F742CDDD6F765F74254F03186683D646E6F09AC2805586C7CF11998357CAFC5DF3F285329366F475130C928B2DCEBA4AA383758E7A9D20705C4BB9DB619E2992F608A1BA65DB254BB389468741D0502E2588AEB54390AC600C19AF5C8E61383FC1BEBE0029E4474051E4EF908828DB9CCA13277EF65DB3FD47CCC2179126AAEFB627719F421E20").unwrap());
        }
 
        #[test]
@@ -1225,22 +1224,22 @@ mod tests {
 
                let onion_keys = build_test_onion_keys();
                let onion_error = super::build_failure_packet(onion_keys[4].shared_secret.as_ref(), 0x2002, &[0; 0]);
-               assert_eq!(onion_error.encode(), hex::decode("4c2fc8bc08510334b6833ad9c3e79cd1b52ae59dfe5c2a4b23ead50f09f7ee0b0002200200fe0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap());
+               assert_eq!(onion_error.encode(), <Vec<u8>>::from_hex("4c2fc8bc08510334b6833ad9c3e79cd1b52ae59dfe5c2a4b23ead50f09f7ee0b0002200200fe0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap());
 
                let onion_packet_1 = super::encrypt_failure_packet(onion_keys[4].shared_secret.as_ref(), &onion_error.encode()[..]);
-               assert_eq!(onion_packet_1.data, hex::decode("a5e6bd0c74cb347f10cce367f949098f2457d14c046fd8a22cb96efb30b0fdcda8cb9168b50f2fd45edd73c1b0c8b33002df376801ff58aaa94000bf8a86f92620f343baef38a580102395ae3abf9128d1047a0736ff9b83d456740ebbb4aeb3aa9737f18fb4afb4aa074fb26c4d702f42968888550a3bded8c05247e045b866baef0499f079fdaeef6538f31d44deafffdfd3afa2fb4ca9082b8f1c465371a9894dd8c243fb4847e004f5256b3e90e2edde4c9fb3082ddfe4d1e734cacd96ef0706bf63c9984e22dc98851bcccd1c3494351feb458c9c6af41c0044bea3c47552b1d992ae542b17a2d0bba1a096c78d169034ecb55b6e3a7263c26017f033031228833c1daefc0dedb8cf7c3e37c9c37ebfe42f3225c326e8bcfd338804c145b16e34e4").unwrap());
+               assert_eq!(onion_packet_1.data, <Vec<u8>>::from_hex("a5e6bd0c74cb347f10cce367f949098f2457d14c046fd8a22cb96efb30b0fdcda8cb9168b50f2fd45edd73c1b0c8b33002df376801ff58aaa94000bf8a86f92620f343baef38a580102395ae3abf9128d1047a0736ff9b83d456740ebbb4aeb3aa9737f18fb4afb4aa074fb26c4d702f42968888550a3bded8c05247e045b866baef0499f079fdaeef6538f31d44deafffdfd3afa2fb4ca9082b8f1c465371a9894dd8c243fb4847e004f5256b3e90e2edde4c9fb3082ddfe4d1e734cacd96ef0706bf63c9984e22dc98851bcccd1c3494351feb458c9c6af41c0044bea3c47552b1d992ae542b17a2d0bba1a096c78d169034ecb55b6e3a7263c26017f033031228833c1daefc0dedb8cf7c3e37c9c37ebfe42f3225c326e8bcfd338804c145b16e34e4").unwrap());
 
                let onion_packet_2 = super::encrypt_failure_packet(onion_keys[3].shared_secret.as_ref(), &onion_packet_1.data[..]);
-               assert_eq!(onion_packet_2.data, hex::decode("c49a1ce81680f78f5f2000cda36268de34a3f0a0662f55b4e837c83a8773c22aa081bab1616a0011585323930fa5b9fae0c85770a2279ff59ec427ad1bbff9001c0cd1497004bd2a0f68b50704cf6d6a4bf3c8b6a0833399a24b3456961ba00736785112594f65b6b2d44d9f5ea4e49b5e1ec2af978cbe31c67114440ac51a62081df0ed46d4a3df295da0b0fe25c0115019f03f15ec86fabb4c852f83449e812f141a9395b3f70b766ebbd4ec2fae2b6955bd8f32684c15abfe8fd3a6261e52650e8807a92158d9f1463261a925e4bfba44bd20b166d532f0017185c3a6ac7957adefe45559e3072c8dc35abeba835a8cb01a71a15c736911126f27d46a36168ca5ef7dccd4e2886212602b181463e0dd30185c96348f9743a02aca8ec27c0b90dca270").unwrap());
+               assert_eq!(onion_packet_2.data, <Vec<u8>>::from_hex("c49a1ce81680f78f5f2000cda36268de34a3f0a0662f55b4e837c83a8773c22aa081bab1616a0011585323930fa5b9fae0c85770a2279ff59ec427ad1bbff9001c0cd1497004bd2a0f68b50704cf6d6a4bf3c8b6a0833399a24b3456961ba00736785112594f65b6b2d44d9f5ea4e49b5e1ec2af978cbe31c67114440ac51a62081df0ed46d4a3df295da0b0fe25c0115019f03f15ec86fabb4c852f83449e812f141a9395b3f70b766ebbd4ec2fae2b6955bd8f32684c15abfe8fd3a6261e52650e8807a92158d9f1463261a925e4bfba44bd20b166d532f0017185c3a6ac7957adefe45559e3072c8dc35abeba835a8cb01a71a15c736911126f27d46a36168ca5ef7dccd4e2886212602b181463e0dd30185c96348f9743a02aca8ec27c0b90dca270").unwrap());
 
                let onion_packet_3 = super::encrypt_failure_packet(onion_keys[2].shared_secret.as_ref(), &onion_packet_2.data[..]);
-               assert_eq!(onion_packet_3.data, hex::decode("a5d3e8634cfe78b2307d87c6d90be6fe7855b4f2cc9b1dfb19e92e4b79103f61ff9ac25f412ddfb7466e74f81b3e545563cdd8f5524dae873de61d7bdfccd496af2584930d2b566b4f8d3881f8c043df92224f38cf094cfc09d92655989531524593ec6d6caec1863bdfaa79229b5020acc034cd6deeea1021c50586947b9b8e6faa83b81fbfa6133c0af5d6b07c017f7158fa94f0d206baf12dda6b68f785b773b360fd0497e16cc402d779c8d48d0fa6315536ef0660f3f4e1865f5b38ea49c7da4fd959de4e83ff3ab686f059a45c65ba2af4a6a79166aa0f496bf04d06987b6d2ea205bdb0d347718b9aeff5b61dfff344993a275b79717cd815b6ad4c0beb568c4ac9c36ff1c315ec1119a1993c4b61e6eaa0375e0aaf738ac691abd3263bf937e3").unwrap());
+               assert_eq!(onion_packet_3.data, <Vec<u8>>::from_hex("a5d3e8634cfe78b2307d87c6d90be6fe7855b4f2cc9b1dfb19e92e4b79103f61ff9ac25f412ddfb7466e74f81b3e545563cdd8f5524dae873de61d7bdfccd496af2584930d2b566b4f8d3881f8c043df92224f38cf094cfc09d92655989531524593ec6d6caec1863bdfaa79229b5020acc034cd6deeea1021c50586947b9b8e6faa83b81fbfa6133c0af5d6b07c017f7158fa94f0d206baf12dda6b68f785b773b360fd0497e16cc402d779c8d48d0fa6315536ef0660f3f4e1865f5b38ea49c7da4fd959de4e83ff3ab686f059a45c65ba2af4a6a79166aa0f496bf04d06987b6d2ea205bdb0d347718b9aeff5b61dfff344993a275b79717cd815b6ad4c0beb568c4ac9c36ff1c315ec1119a1993c4b61e6eaa0375e0aaf738ac691abd3263bf937e3").unwrap());
 
                let onion_packet_4 = super::encrypt_failure_packet(onion_keys[1].shared_secret.as_ref(), &onion_packet_3.data[..]);
-               assert_eq!(onion_packet_4.data, hex::decode("aac3200c4968f56b21f53e5e374e3a2383ad2b1b6501bbcc45abc31e59b26881b7dfadbb56ec8dae8857add94e6702fb4c3a4de22e2e669e1ed926b04447fc73034bb730f4932acd62727b75348a648a1128744657ca6a4e713b9b646c3ca66cac02cdab44dd3439890ef3aaf61708714f7375349b8da541b2548d452d84de7084bb95b3ac2345201d624d31f4d52078aa0fa05a88b4e20202bd2b86ac5b52919ea305a8949de95e935eed0319cf3cf19ebea61d76ba92532497fcdc9411d06bcd4275094d0a4a3c5d3a945e43305a5a9256e333e1f64dbca5fcd4e03a39b9012d197506e06f29339dfee3331995b21615337ae060233d39befea925cc262873e0530408e6990f1cbd233a150ef7b004ff6166c70c68d9f8c853c1abca640b8660db2921").unwrap());
+               assert_eq!(onion_packet_4.data, <Vec<u8>>::from_hex("aac3200c4968f56b21f53e5e374e3a2383ad2b1b6501bbcc45abc31e59b26881b7dfadbb56ec8dae8857add94e6702fb4c3a4de22e2e669e1ed926b04447fc73034bb730f4932acd62727b75348a648a1128744657ca6a4e713b9b646c3ca66cac02cdab44dd3439890ef3aaf61708714f7375349b8da541b2548d452d84de7084bb95b3ac2345201d624d31f4d52078aa0fa05a88b4e20202bd2b86ac5b52919ea305a8949de95e935eed0319cf3cf19ebea61d76ba92532497fcdc9411d06bcd4275094d0a4a3c5d3a945e43305a5a9256e333e1f64dbca5fcd4e03a39b9012d197506e06f29339dfee3331995b21615337ae060233d39befea925cc262873e0530408e6990f1cbd233a150ef7b004ff6166c70c68d9f8c853c1abca640b8660db2921").unwrap());
 
                let onion_packet_5 = super::encrypt_failure_packet(onion_keys[0].shared_secret.as_ref(), &onion_packet_4.data[..]);
-               assert_eq!(onion_packet_5.data, hex::decode("9c5add3963fc7f6ed7f148623c84134b5647e1306419dbe2174e523fa9e2fbed3a06a19f899145610741c83ad40b7712aefaddec8c6baf7325d92ea4ca4d1df8bce517f7e54554608bf2bd8071a4f52a7a2f7ffbb1413edad81eeea5785aa9d990f2865dc23b4bc3c301a94eec4eabebca66be5cf638f693ec256aec514620cc28ee4a94bd9565bc4d4962b9d3641d4278fb319ed2b84de5b665f307a2db0f7fbb757366067d88c50f7e829138fde4f78d39b5b5802f1b92a8a820865af5cc79f9f30bc3f461c66af95d13e5e1f0381c184572a91dee1c849048a647a1158cf884064deddbf1b0b88dfe2f791428d0ba0f6fb2f04e14081f69165ae66d9297c118f0907705c9c4954a199bae0bb96fad763d690e7daa6cfda59ba7f2c8d11448b604d12d").unwrap());
+               assert_eq!(onion_packet_5.data, <Vec<u8>>::from_hex("9c5add3963fc7f6ed7f148623c84134b5647e1306419dbe2174e523fa9e2fbed3a06a19f899145610741c83ad40b7712aefaddec8c6baf7325d92ea4ca4d1df8bce517f7e54554608bf2bd8071a4f52a7a2f7ffbb1413edad81eeea5785aa9d990f2865dc23b4bc3c301a94eec4eabebca66be5cf638f693ec256aec514620cc28ee4a94bd9565bc4d4962b9d3641d4278fb319ed2b84de5b665f307a2db0f7fbb757366067d88c50f7e829138fde4f78d39b5b5802f1b92a8a820865af5cc79f9f30bc3f461c66af95d13e5e1f0381c184572a91dee1c849048a647a1158cf884064deddbf1b0b88dfe2f791428d0ba0f6fb2f04e14081f69165ae66d9297c118f0907705c9c4954a199bae0bb96fad763d690e7daa6cfda59ba7f2c8d11448b604d12d").unwrap());
        }
 
        struct RawOnionHopData {
index 0fbb0f5eaf4ccdeffd32d2a7c9d2aea20888273c..b449e27983ecd09efdc88a90ff22235d0f7d0f67 100644 (file)
@@ -728,7 +728,7 @@ impl OutboundPayments {
        {
                let preimage = payment_preimage
                        .unwrap_or_else(|| PaymentPreimage(entropy_source.get_secure_random_bytes()));
-               let payment_hash = PaymentHash(Sha256::hash(&preimage.0).into_inner());
+               let payment_hash = PaymentHash(Sha256::hash(&preimage.0).to_byte_array());
                self.send_payment_internal(payment_id, payment_hash, recipient_onion, Some(preimage),
                        retry_strategy, route_params, router, first_hops, inflight_htlcs, entropy_source,
                        node_signer, best_block_height, logger, pending_events, send_payment_along_path)
@@ -747,7 +747,7 @@ impl OutboundPayments {
        {
                let preimage = payment_preimage
                        .unwrap_or_else(|| PaymentPreimage(entropy_source.get_secure_random_bytes()));
-               let payment_hash = PaymentHash(Sha256::hash(&preimage.0).into_inner());
+               let payment_hash = PaymentHash(Sha256::hash(&preimage.0).to_byte_array());
                let onion_session_privs = self.add_new_pending_payment(payment_hash, recipient_onion.clone(),
                        payment_id, Some(preimage), &route, None, None, entropy_source, best_block_height)?;
 
@@ -1463,7 +1463,7 @@ impl OutboundPayments {
                let mut pending_events = pending_events.lock().unwrap();
                if let hash_map::Entry::Occupied(mut payment) = outbounds.entry(payment_id) {
                        if !payment.get().is_fulfilled() {
-                               let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0).into_inner());
+                               let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0).to_byte_array());
                                log_info!(logger, "Payment with id {} and hash {} sent!", payment_id, payment_hash);
                                let fee_paid_msat = payment.get().get_pending_fee_msat();
                                pending_events.push_back((events::Event::PaymentSent {
@@ -1483,7 +1483,7 @@ impl OutboundPayments {
                                // TODO: We should have a second monitor event that informs us of payments
                                // irrevocably fulfilled.
                                if payment.get_mut().remove(&session_priv_bytes, Some(&path)) {
-                                       let payment_hash = Some(PaymentHash(Sha256::hash(&payment_preimage.0).into_inner()));
+                                       let payment_hash = Some(PaymentHash(Sha256::hash(&payment_preimage.0).to_byte_array()));
                                        pending_events.push_back((events::Event::PaymentPathSuccessful {
                                                payment_id,
                                                payment_hash,
@@ -1763,7 +1763,7 @@ fn probing_cookie_from_id(payment_id: &PaymentId, probing_cookie_secret: [u8; 32
        let mut preimage = [0u8; 64];
        preimage[..32].copy_from_slice(&probing_cookie_secret);
        preimage[32..].copy_from_slice(&payment_id.0);
-       PaymentHash(Sha256::hash(&preimage).into_inner())
+       PaymentHash(Sha256::hash(&preimage).to_byte_array())
 }
 
 impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
index 8569fa60ffef46268fd020578dc22cb1e455649d..c9e1ac47886956eb3a6532d6008ca6d6e62992f7 100644 (file)
@@ -22,10 +22,11 @@ use bitcoin::secp256k1::{PublicKey,SecretKey};
 use bitcoin::secp256k1::ecdh::SharedSecret;
 use bitcoin::secp256k1;
 
+use hex::DisplayHex;
+
 use crate::util::chacha20poly1305rfc::ChaCha20Poly1305RFC;
 use crate::util::crypto::hkdf_extract_expand_twice;
 use crate::util::ser::VecWriter;
-use bitcoin::hashes::hex::ToHex;
 
 use core::ops::Deref;
 
@@ -104,7 +105,7 @@ impl PeerChannelEncryptor {
                let mut sha = Sha256::engine();
                sha.input(&NOISE_H);
                sha.input(&their_node_id.serialize()[..]);
-               let h = Sha256::from_engine(sha).into_inner();
+               let h = Sha256::from_engine(sha).to_byte_array();
 
                PeerChannelEncryptor {
                        their_node_id: Some(their_node_id),
@@ -126,7 +127,7 @@ impl PeerChannelEncryptor {
                sha.input(&NOISE_H);
                let our_node_id = node_signer.get_node_id(Recipient::Node).unwrap();
                sha.input(&our_node_id.serialize()[..]);
-               let h = Sha256::from_engine(sha).into_inner();
+               let h = Sha256::from_engine(sha).to_byte_array();
 
                PeerChannelEncryptor {
                        their_node_id: None,
@@ -207,7 +208,7 @@ impl PeerChannelEncryptor {
                let mut sha = Sha256::engine();
                sha.input(&state.h);
                sha.input(&our_pub.serialize()[..]);
-               state.h = Sha256::from_engine(sha).into_inner();
+               state.h = Sha256::from_engine(sha).to_byte_array();
 
                let ss = SharedSecret::new(&their_key, &our_key);
                let temp_k = PeerChannelEncryptor::hkdf(state, ss);
@@ -219,7 +220,7 @@ impl PeerChannelEncryptor {
                let mut sha = Sha256::engine();
                sha.input(&state.h);
                sha.input(&res[34..]);
-               state.h = Sha256::from_engine(sha).into_inner();
+               state.h = Sha256::from_engine(sha).to_byte_array();
 
                (res, temp_k)
        }
@@ -235,14 +236,14 @@ impl PeerChannelEncryptor {
                }
 
                let their_pub = match PublicKey::from_slice(&act[1..34]) {
-                       Err(_) => return Err(LightningError{err: format!("Invalid public key {}", &act[1..34].to_hex()), action: msgs::ErrorAction::DisconnectPeer{ msg: None }}),
+                       Err(_) => return Err(LightningError{err: format!("Invalid public key {}", &act[1..34].as_hex()), action: msgs::ErrorAction::DisconnectPeer{ msg: None }}),
                        Ok(key) => key,
                };
 
                let mut sha = Sha256::engine();
                sha.input(&state.h);
                sha.input(&their_pub.serialize()[..]);
-               state.h = Sha256::from_engine(sha).into_inner();
+               state.h = Sha256::from_engine(sha).to_byte_array();
 
                let ss = match secret_key {
                        NoiseSecretKey::InMemory(secret_key) => SharedSecret::new(&their_pub, secret_key),
@@ -261,7 +262,7 @@ impl PeerChannelEncryptor {
                let mut sha = Sha256::engine();
                sha.input(&state.h);
                sha.input(&act[34..]);
-               state.h = Sha256::from_engine(sha).into_inner();
+               state.h = Sha256::from_engine(sha).to_byte_array();
 
                Ok((their_pub, temp_k))
        }
@@ -343,7 +344,7 @@ impl PeerChannelEncryptor {
                                                let mut sha = Sha256::engine();
                                                sha.input(&bidirectional_state.h);
                                                sha.input(&res[1..50]);
-                                               bidirectional_state.h = Sha256::from_engine(sha).into_inner();
+                                               bidirectional_state.h = Sha256::from_engine(sha).to_byte_array();
 
                                                let ss = node_signer.ecdh(Recipient::Node, &re, None).map_err(|_| LightningError {
                                                        err: "Failed to derive shared secret".to_owned(),
@@ -394,13 +395,13 @@ impl PeerChannelEncryptor {
                                                PeerChannelEncryptor::decrypt_with_ad(&mut their_node_id, 1, &temp_k2.unwrap(), &bidirectional_state.h, &act_three[1..50])?;
                                                self.their_node_id = Some(match PublicKey::from_slice(&their_node_id) {
                                                        Ok(key) => key,
-                                                       Err(_) => return Err(LightningError{err: format!("Bad node_id from peer, {}", &their_node_id.to_hex()), action: msgs::ErrorAction::DisconnectPeer{ msg: None }}),
+                                                       Err(_) => return Err(LightningError{err: format!("Bad node_id from peer, {}", &their_node_id.as_hex()), action: msgs::ErrorAction::DisconnectPeer{ msg: None }}),
                                                });
 
                                                let mut sha = Sha256::engine();
                                                sha.input(&bidirectional_state.h);
                                                sha.input(&act_three[1..50]);
-                                               bidirectional_state.h = Sha256::from_engine(sha).into_inner();
+                                               bidirectional_state.h = Sha256::from_engine(sha).to_byte_array();
 
                                                let ss = SharedSecret::new(&self.their_node_id.unwrap(), &re.unwrap());
                                                let temp_k = PeerChannelEncryptor::hkdf(bidirectional_state, ss);
@@ -569,48 +570,47 @@ impl MessageBuf {
 mod tests {
        use super::{MessageBuf, LN_MAX_MSG_LEN};
 
+       use bitcoin::hashes::hex::FromHex;
        use bitcoin::secp256k1::{PublicKey, SecretKey};
        use bitcoin::secp256k1::Secp256k1;
 
-       use hex;
-
        use crate::ln::peer_channel_encryptor::{PeerChannelEncryptor,NoiseState};
        use crate::util::test_utils::TestNodeSigner;
 
        fn get_outbound_peer_for_initiator_test_vectors() -> PeerChannelEncryptor {
-               let their_node_id = PublicKey::from_slice(&hex::decode("028d7500dd4c12685d1f568b4c2b5048e8534b873319f3a8daa612b469132ec7f7").unwrap()[..]).unwrap();
+               let their_node_id = PublicKey::from_slice(&<Vec<u8>>::from_hex("028d7500dd4c12685d1f568b4c2b5048e8534b873319f3a8daa612b469132ec7f7").unwrap()[..]).unwrap();
                let secp_ctx = Secp256k1::signing_only();
 
-               let mut outbound_peer = PeerChannelEncryptor::new_outbound(their_node_id, SecretKey::from_slice(&hex::decode("1212121212121212121212121212121212121212121212121212121212121212").unwrap()[..]).unwrap());
-               assert_eq!(outbound_peer.get_act_one(&secp_ctx)[..], hex::decode("00036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a").unwrap()[..]);
+               let mut outbound_peer = PeerChannelEncryptor::new_outbound(their_node_id, SecretKey::from_slice(&<Vec<u8>>::from_hex("1212121212121212121212121212121212121212121212121212121212121212").unwrap()[..]).unwrap());
+               assert_eq!(outbound_peer.get_act_one(&secp_ctx)[..], <Vec<u8>>::from_hex("00036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a").unwrap()[..]);
                outbound_peer
        }
 
        fn get_inbound_peer_for_test_vectors() -> PeerChannelEncryptor {
                // transport-responder successful handshake
-               let our_node_id = SecretKey::from_slice(&hex::decode("2121212121212121212121212121212121212121212121212121212121212121").unwrap()[..]).unwrap();
-               let our_ephemeral = SecretKey::from_slice(&hex::decode("2222222222222222222222222222222222222222222222222222222222222222").unwrap()[..]).unwrap();
+               let our_node_id = SecretKey::from_slice(&<Vec<u8>>::from_hex("2121212121212121212121212121212121212121212121212121212121212121").unwrap()[..]).unwrap();
+               let our_ephemeral = SecretKey::from_slice(&<Vec<u8>>::from_hex("2222222222222222222222222222222222222222222222222222222222222222").unwrap()[..]).unwrap();
                let secp_ctx = Secp256k1::new();
                let node_signer = TestNodeSigner::new(our_node_id);
 
                let mut inbound_peer = PeerChannelEncryptor::new_inbound(&&node_signer);
 
-               let act_one = hex::decode("00036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a").unwrap().to_vec();
-               assert_eq!(inbound_peer.process_act_one_with_keys(&act_one[..], &&node_signer, our_ephemeral.clone(), &secp_ctx).unwrap()[..], hex::decode("0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae").unwrap()[..]);
+               let act_one = <Vec<u8>>::from_hex("00036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a").unwrap().to_vec();
+               assert_eq!(inbound_peer.process_act_one_with_keys(&act_one[..], &&node_signer, our_ephemeral.clone(), &secp_ctx).unwrap()[..], <Vec<u8>>::from_hex("0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae").unwrap()[..]);
 
-               let act_three = hex::decode("00b9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139ba").unwrap().to_vec();
+               let act_three = <Vec<u8>>::from_hex("00b9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139ba").unwrap().to_vec();
                // test vector doesn't specify the initiator static key, but it's the same as the one
                // from transport-initiator successful handshake
-               assert_eq!(inbound_peer.process_act_three(&act_three[..]).unwrap().serialize()[..], hex::decode("034f355bdcb7cc0af728ef3cceb9615d90684bb5b2ca5f859ab0f0b704075871aa").unwrap()[..]);
+               assert_eq!(inbound_peer.process_act_three(&act_three[..]).unwrap().serialize()[..], <Vec<u8>>::from_hex("034f355bdcb7cc0af728ef3cceb9615d90684bb5b2ca5f859ab0f0b704075871aa").unwrap()[..]);
 
                match inbound_peer.noise_state {
                        NoiseState::Finished { sk, sn, sck, rk, rn, rck } => {
-                               assert_eq!(sk, hex::decode("bb9020b8965f4df047e07f955f3c4b88418984aadc5cdb35096b9ea8fa5c3442").unwrap()[..]);
+                               assert_eq!(sk, <Vec<u8>>::from_hex("bb9020b8965f4df047e07f955f3c4b88418984aadc5cdb35096b9ea8fa5c3442").unwrap()[..]);
                                assert_eq!(sn, 0);
-                               assert_eq!(sck, hex::decode("919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01").unwrap()[..]);
-                               assert_eq!(rk, hex::decode("969ab31b4d288cedf6218839b27a3e2140827047f2c0f01bf5c04435d43511a9").unwrap()[..]);
+                               assert_eq!(sck, <Vec<u8>>::from_hex("919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01").unwrap()[..]);
+                               assert_eq!(rk, <Vec<u8>>::from_hex("969ab31b4d288cedf6218839b27a3e2140827047f2c0f01bf5c04435d43511a9").unwrap()[..]);
                                assert_eq!(rn, 0);
-                               assert_eq!(rck, hex::decode("919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01").unwrap()[..]);
+                               assert_eq!(rck, <Vec<u8>>::from_hex("919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01").unwrap()[..]);
                        },
                        _ => panic!()
                }
@@ -620,24 +620,24 @@ mod tests {
 
        #[test]
        fn noise_initiator_test_vectors() {
-               let our_node_id = SecretKey::from_slice(&hex::decode("1111111111111111111111111111111111111111111111111111111111111111").unwrap()[..]).unwrap();
+               let our_node_id = SecretKey::from_slice(&<Vec<u8>>::from_hex("1111111111111111111111111111111111111111111111111111111111111111").unwrap()[..]).unwrap();
                let node_signer = TestNodeSigner::new(our_node_id);
 
                {
                        // transport-initiator successful handshake
                        let mut outbound_peer = get_outbound_peer_for_initiator_test_vectors();
 
-                       let act_two = hex::decode("0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae").unwrap().to_vec();
-                       assert_eq!(outbound_peer.process_act_two(&act_two[..], &&node_signer).unwrap().0[..], hex::decode("00b9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139ba").unwrap()[..]);
+                       let act_two = <Vec<u8>>::from_hex("0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae").unwrap().to_vec();
+                       assert_eq!(outbound_peer.process_act_two(&act_two[..], &&node_signer).unwrap().0[..], <Vec<u8>>::from_hex("00b9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139ba").unwrap()[..]);
 
                        match outbound_peer.noise_state {
                                NoiseState::Finished { sk, sn, sck, rk, rn, rck } => {
-                                       assert_eq!(sk, hex::decode("969ab31b4d288cedf6218839b27a3e2140827047f2c0f01bf5c04435d43511a9").unwrap()[..]);
+                                       assert_eq!(sk, <Vec<u8>>::from_hex("969ab31b4d288cedf6218839b27a3e2140827047f2c0f01bf5c04435d43511a9").unwrap()[..]);
                                        assert_eq!(sn, 0);
-                                       assert_eq!(sck, hex::decode("919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01").unwrap()[..]);
-                                       assert_eq!(rk, hex::decode("bb9020b8965f4df047e07f955f3c4b88418984aadc5cdb35096b9ea8fa5c3442").unwrap()[..]);
+                                       assert_eq!(sck, <Vec<u8>>::from_hex("919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01").unwrap()[..]);
+                                       assert_eq!(rk, <Vec<u8>>::from_hex("bb9020b8965f4df047e07f955f3c4b88418984aadc5cdb35096b9ea8fa5c3442").unwrap()[..]);
                                        assert_eq!(rn, 0);
-                                       assert_eq!(rck, hex::decode("919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01").unwrap()[..]);
+                                       assert_eq!(rck, <Vec<u8>>::from_hex("919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01").unwrap()[..]);
                                },
                                _ => panic!()
                        }
@@ -650,7 +650,7 @@ mod tests {
                        // transport-initiator act2 bad version test
                        let mut outbound_peer = get_outbound_peer_for_initiator_test_vectors();
 
-                       let act_two = hex::decode("0102466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae").unwrap().to_vec();
+                       let act_two = <Vec<u8>>::from_hex("0102466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae").unwrap().to_vec();
                        assert!(outbound_peer.process_act_two(&act_two[..], &&node_signer).is_err());
                }
 
@@ -658,7 +658,7 @@ mod tests {
                        // transport-initiator act2 bad key serialization test
                        let mut outbound_peer = get_outbound_peer_for_initiator_test_vectors();
 
-                       let act_two = hex::decode("0004466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae").unwrap().to_vec();
+                       let act_two = <Vec<u8>>::from_hex("0004466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae").unwrap().to_vec();
                        assert!(outbound_peer.process_act_two(&act_two[..], &&node_signer).is_err());
                }
 
@@ -666,15 +666,15 @@ mod tests {
                        // transport-initiator act2 bad MAC test
                        let mut outbound_peer = get_outbound_peer_for_initiator_test_vectors();
 
-                       let act_two = hex::decode("0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730af").unwrap().to_vec();
+                       let act_two = <Vec<u8>>::from_hex("0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730af").unwrap().to_vec();
                        assert!(outbound_peer.process_act_two(&act_two[..], &&node_signer).is_err());
                }
        }
 
        #[test]
        fn noise_responder_test_vectors() {
-               let our_node_id = SecretKey::from_slice(&hex::decode("2121212121212121212121212121212121212121212121212121212121212121").unwrap()[..]).unwrap();
-               let our_ephemeral = SecretKey::from_slice(&hex::decode("2222222222222222222222222222222222222222222222222222222222222222").unwrap()[..]).unwrap();
+               let our_node_id = SecretKey::from_slice(&<Vec<u8>>::from_hex("2121212121212121212121212121212121212121212121212121212121212121").unwrap()[..]).unwrap();
+               let our_ephemeral = SecretKey::from_slice(&<Vec<u8>>::from_hex("2222222222222222222222222222222222222222222222222222222222222222").unwrap()[..]).unwrap();
                let secp_ctx = Secp256k1::new();
                let node_signer = TestNodeSigner::new(our_node_id);
 
@@ -689,31 +689,31 @@ mod tests {
                        // transport-responder act1 bad version test
                        let mut inbound_peer = PeerChannelEncryptor::new_inbound(&&node_signer);
 
-                       let act_one = hex::decode("01036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a").unwrap().to_vec();
+                       let act_one = <Vec<u8>>::from_hex("01036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a").unwrap().to_vec();
                        assert!(inbound_peer.process_act_one_with_keys(&act_one[..], &&node_signer, our_ephemeral.clone(), &secp_ctx).is_err());
                }
                {
                        // transport-responder act1 bad key serialization test
                        let mut inbound_peer = PeerChannelEncryptor::new_inbound(&&node_signer);
 
-                       let act_one =hex::decode("00046360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a").unwrap().to_vec();
+                       let act_one =<Vec<u8>>::from_hex("00046360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a").unwrap().to_vec();
                        assert!(inbound_peer.process_act_one_with_keys(&act_one[..], &&node_signer, our_ephemeral.clone(), &secp_ctx).is_err());
                }
                {
                        // transport-responder act1 bad MAC test
                        let mut inbound_peer = PeerChannelEncryptor::new_inbound(&&node_signer);
 
-                       let act_one = hex::decode("00036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6b").unwrap().to_vec();
+                       let act_one = <Vec<u8>>::from_hex("00036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6b").unwrap().to_vec();
                        assert!(inbound_peer.process_act_one_with_keys(&act_one[..], &&node_signer, our_ephemeral.clone(), &secp_ctx).is_err());
                }
                {
                        // transport-responder act3 bad version test
                        let mut inbound_peer = PeerChannelEncryptor::new_inbound(&&node_signer);
 
-                       let act_one = hex::decode("00036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a").unwrap().to_vec();
-                       assert_eq!(inbound_peer.process_act_one_with_keys(&act_one[..], &&node_signer, our_ephemeral.clone(), &secp_ctx).unwrap()[..], hex::decode("0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae").unwrap()[..]);
+                       let act_one = <Vec<u8>>::from_hex("00036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a").unwrap().to_vec();
+                       assert_eq!(inbound_peer.process_act_one_with_keys(&act_one[..], &&node_signer, our_ephemeral.clone(), &secp_ctx).unwrap()[..], <Vec<u8>>::from_hex("0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae").unwrap()[..]);
 
-                       let act_three = hex::decode("01b9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139ba").unwrap().to_vec();
+                       let act_three = <Vec<u8>>::from_hex("01b9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139ba").unwrap().to_vec();
                        assert!(inbound_peer.process_act_three(&act_three[..]).is_err());
                }
                {
@@ -724,30 +724,30 @@ mod tests {
                        // transport-responder act3 bad MAC for ciphertext test
                        let mut inbound_peer = PeerChannelEncryptor::new_inbound(&&node_signer);
 
-                       let act_one = hex::decode("00036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a").unwrap().to_vec();
-                       assert_eq!(inbound_peer.process_act_one_with_keys(&act_one[..], &&node_signer, our_ephemeral.clone(), &secp_ctx).unwrap()[..], hex::decode("0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae").unwrap()[..]);
+                       let act_one = <Vec<u8>>::from_hex("00036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a").unwrap().to_vec();
+                       assert_eq!(inbound_peer.process_act_one_with_keys(&act_one[..], &&node_signer, our_ephemeral.clone(), &secp_ctx).unwrap()[..], <Vec<u8>>::from_hex("0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae").unwrap()[..]);
 
-                       let act_three = hex::decode("00c9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139ba").unwrap().to_vec();
+                       let act_three = <Vec<u8>>::from_hex("00c9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139ba").unwrap().to_vec();
                        assert!(inbound_peer.process_act_three(&act_three[..]).is_err());
                }
                {
                        // transport-responder act3 bad rs test
                        let mut inbound_peer = PeerChannelEncryptor::new_inbound(&&node_signer);
 
-                       let act_one = hex::decode("00036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a").unwrap().to_vec();
-                       assert_eq!(inbound_peer.process_act_one_with_keys(&act_one[..], &&node_signer, our_ephemeral.clone(), &secp_ctx).unwrap()[..], hex::decode("0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae").unwrap()[..]);
+                       let act_one = <Vec<u8>>::from_hex("00036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a").unwrap().to_vec();
+                       assert_eq!(inbound_peer.process_act_one_with_keys(&act_one[..], &&node_signer, our_ephemeral.clone(), &secp_ctx).unwrap()[..], <Vec<u8>>::from_hex("0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae").unwrap()[..]);
 
-                       let act_three = hex::decode("00bfe3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa2235536ad09a8ee351870c2bb7f78b754a26c6cef79a98d25139c856d7efd252c2ae73c").unwrap().to_vec();
+                       let act_three = <Vec<u8>>::from_hex("00bfe3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa2235536ad09a8ee351870c2bb7f78b754a26c6cef79a98d25139c856d7efd252c2ae73c").unwrap().to_vec();
                        assert!(inbound_peer.process_act_three(&act_three[..]).is_err());
                }
                {
                        // transport-responder act3 bad MAC test
                        let mut inbound_peer = PeerChannelEncryptor::new_inbound(&&node_signer);
 
-                       let act_one = hex::decode("00036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a").unwrap().to_vec();
-                       assert_eq!(inbound_peer.process_act_one_with_keys(&act_one[..], &&node_signer, our_ephemeral.clone(), &secp_ctx).unwrap()[..], hex::decode("0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae").unwrap()[..]);
+                       let act_one = <Vec<u8>>::from_hex("00036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a").unwrap().to_vec();
+                       assert_eq!(inbound_peer.process_act_one_with_keys(&act_one[..], &&node_signer, our_ephemeral.clone(), &secp_ctx).unwrap()[..], <Vec<u8>>::from_hex("0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae").unwrap()[..]);
 
-                       let act_three = hex::decode("00b9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139bb").unwrap().to_vec();
+                       let act_three = <Vec<u8>>::from_hex("00b9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139bb").unwrap().to_vec();
                        assert!(inbound_peer.process_act_three(&act_three[..]).is_err());
                }
        }
@@ -760,20 +760,20 @@ mod tests {
                let mut outbound_peer = get_outbound_peer_for_initiator_test_vectors();
 
                {
-                       let our_node_id = SecretKey::from_slice(&hex::decode("1111111111111111111111111111111111111111111111111111111111111111").unwrap()[..]).unwrap();
+                       let our_node_id = SecretKey::from_slice(&<Vec<u8>>::from_hex("1111111111111111111111111111111111111111111111111111111111111111").unwrap()[..]).unwrap();
                        let node_signer = TestNodeSigner::new(our_node_id);
 
-                       let act_two = hex::decode("0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae").unwrap().to_vec();
-                       assert_eq!(outbound_peer.process_act_two(&act_two[..], &&node_signer).unwrap().0[..], hex::decode("00b9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139ba").unwrap()[..]);
+                       let act_two = <Vec<u8>>::from_hex("0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae").unwrap().to_vec();
+                       assert_eq!(outbound_peer.process_act_two(&act_two[..], &&node_signer).unwrap().0[..], <Vec<u8>>::from_hex("00b9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139ba").unwrap()[..]);
 
                        match outbound_peer.noise_state {
                                NoiseState::Finished { sk, sn, sck, rk, rn, rck } => {
-                                       assert_eq!(sk, hex::decode("969ab31b4d288cedf6218839b27a3e2140827047f2c0f01bf5c04435d43511a9").unwrap()[..]);
+                                       assert_eq!(sk, <Vec<u8>>::from_hex("969ab31b4d288cedf6218839b27a3e2140827047f2c0f01bf5c04435d43511a9").unwrap()[..]);
                                        assert_eq!(sn, 0);
-                                       assert_eq!(sck, hex::decode("919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01").unwrap()[..]);
-                                       assert_eq!(rk, hex::decode("bb9020b8965f4df047e07f955f3c4b88418984aadc5cdb35096b9ea8fa5c3442").unwrap()[..]);
+                                       assert_eq!(sck, <Vec<u8>>::from_hex("919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01").unwrap()[..]);
+                                       assert_eq!(rk, <Vec<u8>>::from_hex("bb9020b8965f4df047e07f955f3c4b88418984aadc5cdb35096b9ea8fa5c3442").unwrap()[..]);
                                        assert_eq!(rn, 0);
-                                       assert_eq!(rck, hex::decode("919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01").unwrap()[..]);
+                                       assert_eq!(rck, <Vec<u8>>::from_hex("919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01").unwrap()[..]);
                                },
                                _ => panic!()
                        }
@@ -790,17 +790,17 @@ mod tests {
                        assert_eq!(inbound_peer.decrypt_length_header(&len_header[..]).unwrap() as usize, msg.len());
 
                        if i == 0 {
-                               assert_eq!(res, hex::decode("cf2b30ddf0cf3f80e7c35a6e6730b59fe802473180f396d88a8fb0db8cbcf25d2f214cf9ea1d95").unwrap());
+                               assert_eq!(res, <Vec<u8>>::from_hex("cf2b30ddf0cf3f80e7c35a6e6730b59fe802473180f396d88a8fb0db8cbcf25d2f214cf9ea1d95").unwrap());
                        } else if i == 1 {
-                               assert_eq!(res, hex::decode("72887022101f0b6753e0c7de21657d35a4cb2a1f5cde2650528bbc8f837d0f0d7ad833b1a256a1").unwrap());
+                               assert_eq!(res, <Vec<u8>>::from_hex("72887022101f0b6753e0c7de21657d35a4cb2a1f5cde2650528bbc8f837d0f0d7ad833b1a256a1").unwrap());
                        } else if i == 500 {
-                               assert_eq!(res, hex::decode("178cb9d7387190fa34db9c2d50027d21793c9bc2d40b1e14dcf30ebeeeb220f48364f7a4c68bf8").unwrap());
+                               assert_eq!(res, <Vec<u8>>::from_hex("178cb9d7387190fa34db9c2d50027d21793c9bc2d40b1e14dcf30ebeeeb220f48364f7a4c68bf8").unwrap());
                        } else if i == 501 {
-                               assert_eq!(res, hex::decode("1b186c57d44eb6de4c057c49940d79bb838a145cb528d6e8fd26dbe50a60ca2c104b56b60e45bd").unwrap());
+                               assert_eq!(res, <Vec<u8>>::from_hex("1b186c57d44eb6de4c057c49940d79bb838a145cb528d6e8fd26dbe50a60ca2c104b56b60e45bd").unwrap());
                        } else if i == 1000 {
-                               assert_eq!(res, hex::decode("4a2f3cc3b5e78ddb83dcb426d9863d9d9a723b0337c89dd0b005d89f8d3c05c52b76b29b740f09").unwrap());
+                               assert_eq!(res, <Vec<u8>>::from_hex("4a2f3cc3b5e78ddb83dcb426d9863d9d9a723b0337c89dd0b005d89f8d3c05c52b76b29b740f09").unwrap());
                        } else if i == 1001 {
-                               assert_eq!(res, hex::decode("2ecd8c8a5629d0d02ab457a0fdd0f7b90a192cd46be5ecb6ca570bfc5e268338b1a16cf4ef2d36").unwrap());
+                               assert_eq!(res, <Vec<u8>>::from_hex("2ecd8c8a5629d0d02ab457a0fdd0f7b90a192cd46be5ecb6ca570bfc5e268338b1a16cf4ef2d36").unwrap());
                        }
 
                        inbound_peer.decrypt_message(&mut res[2+16..]).unwrap();
index 4c2e68d9a43993a021c5a0bc796b548aed1a649e..3949b97e0d03019a5f79ad4f293d0d450a9d970a 100644 (file)
@@ -922,7 +922,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
                ephemeral_key_midstate.input(ephemeral_random_data);
 
                let mut secp_ctx = Secp256k1::signing_only();
-               let ephemeral_hash = Sha256::from_engine(ephemeral_key_midstate.clone()).into_inner();
+               let ephemeral_hash = Sha256::from_engine(ephemeral_key_midstate.clone()).to_byte_array();
                secp_ctx.seeded_randomize(&ephemeral_hash);
 
                PeerManager {
@@ -966,7 +966,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
                let mut ephemeral_hash = self.ephemeral_key_midstate.clone();
                let counter = self.peer_counter.get_increment();
                ephemeral_hash.input(&counter.to_le_bytes());
-               SecretKey::from_slice(&Sha256::from_engine(ephemeral_hash).into_inner()).expect("You broke SHA-256!")
+               SecretKey::from_slice(&Sha256::from_engine(ephemeral_hash).to_byte_array()).expect("You broke SHA-256!")
        }
 
        fn init_features(&self, their_node_id: &PublicKey) -> InitFeatures {
@@ -2676,7 +2676,7 @@ mod tests {
                for i in 0..peer_count {
                        let node_secret = SecretKey::from_slice(&[42 + i as u8; 32]).unwrap();
                        let features = InitFeatures::from_le_bytes(vec![0u8; 33]);
-                       let network = ChainHash::from(&[i as u8; 32][..]);
+                       let network = ChainHash::from(&[i as u8; 32]);
                        cfgs.push(
                                PeerManagerCfg{
                                        chan_handler: test_utils::TestChannelMessageHandler::new(network),
@@ -2789,7 +2789,7 @@ mod tests {
                                                                node_id: peers[1].node_signer.get_node_id(Recipient::Node).unwrap(),
                                                                msg: msgs::Shutdown {
                                                                        channel_id: ChannelId::new_zero(),
-                                                                       scriptpubkey: bitcoin::Script::new(),
+                                                                       scriptpubkey: bitcoin::ScriptBuf::new(),
                                                                },
                                                        });
                                                cfgs[1].chan_handler.pending_events.lock().unwrap()
@@ -2797,7 +2797,7 @@ mod tests {
                                                                node_id: peers[0].node_signer.get_node_id(Recipient::Node).unwrap(),
                                                                msg: msgs::Shutdown {
                                                                        channel_id: ChannelId::new_zero(),
-                                                                       scriptpubkey: bitcoin::Script::new(),
+                                                                       scriptpubkey: bitcoin::ScriptBuf::new(),
                                                                },
                                                        });
 
@@ -2925,7 +2925,7 @@ mod tests {
 
                let their_id = peers[1].node_signer.get_node_id(Recipient::Node).unwrap();
 
-               let msg = msgs::Shutdown { channel_id: ChannelId::from_bytes([42; 32]), scriptpubkey: bitcoin::Script::new() };
+               let msg = msgs::Shutdown { channel_id: ChannelId::from_bytes([42; 32]), scriptpubkey: bitcoin::ScriptBuf::new() };
                a_chan_handler.pending_events.lock().unwrap().push(events::MessageSendEvent::SendShutdown {
                        node_id: their_id, msg: msg.clone()
                });
index 079416eae77d29dcca818256950451a4b835eb7a..dc733dd25a1f0ca154c773f1987d4861e4d30a23 100644 (file)
@@ -1,11 +1,11 @@
 //! Abstractions for scripts used in the Lightning Network.
 
 use bitcoin::blockdata::opcodes::all::OP_PUSHBYTES_0 as SEGWIT_V0;
-use bitcoin::blockdata::script::{Builder, Script};
+use bitcoin::blockdata::script::{Script, ScriptBuf};
 use bitcoin::hashes::Hash;
 use bitcoin::hash_types::{WPubkeyHash, WScriptHash};
 use bitcoin::secp256k1::PublicKey;
-use bitcoin::util::address::WitnessVersion;
+use bitcoin::address::WitnessProgram;
 
 use crate::ln::channelmanager;
 use crate::ln::features::InitFeatures;
@@ -21,13 +21,13 @@ use crate::io;
 #[derive(Clone, PartialEq, Eq)]
 pub struct ShutdownScript(ShutdownScriptImpl);
 
-/// An error occurring when converting from [`Script`] to [`ShutdownScript`].
+/// An error occurring when converting from [`ScriptBuf`] to [`ShutdownScript`].
 #[derive(Clone, Debug)]
 pub struct InvalidShutdownScript {
        /// The script that did not meet the requirements from [BOLT #2].
        ///
        /// [BOLT #2]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md
-       pub script: Script
+       pub script: ScriptBuf
 }
 
 #[derive(Clone, PartialEq, Eq)]
@@ -36,8 +36,8 @@ enum ShutdownScriptImpl {
        /// serialization.
        Legacy(PublicKey),
 
-       /// [`Script`] adhering to a script pubkey format specified in BOLT #2.
-       Bolt2(Script),
+       /// [`ScriptBuf`] adhering to a script pubkey format specified in BOLT #2.
+       Bolt2(ScriptBuf),
 }
 
 impl Writeable for ShutdownScript {
@@ -65,12 +65,12 @@ impl ShutdownScript {
 
        /// Generates a P2WPKH script pubkey from the given [`WPubkeyHash`].
        pub fn new_p2wpkh(pubkey_hash: &WPubkeyHash) -> Self {
-               Self(ShutdownScriptImpl::Bolt2(Script::new_v0_p2wpkh(pubkey_hash)))
+               Self(ShutdownScriptImpl::Bolt2(ScriptBuf::new_v0_p2wpkh(pubkey_hash)))
        }
 
        /// Generates a P2WSH script pubkey from the given [`WScriptHash`].
        pub fn new_p2wsh(script_hash: &WScriptHash) -> Self {
-               Self(ShutdownScriptImpl::Bolt2(Script::new_v0_p2wsh(script_hash)))
+               Self(ShutdownScriptImpl::Bolt2(ScriptBuf::new_v0_p2wsh(script_hash)))
        }
 
        /// Generates a witness script pubkey from the given segwit version and program.
@@ -81,16 +81,12 @@ impl ShutdownScript {
        /// # Errors
        ///
        /// This function may return an error if `program` is invalid for the segwit `version`.
-       pub fn new_witness_program(version: WitnessVersion, program: &[u8]) -> Result<Self, InvalidShutdownScript> {
-               let script = Builder::new()
-                       .push_int(version as i64)
-                       .push_slice(&program)
-                       .into_script();
-               Self::try_from(script)
+       pub fn new_witness_program(witness_program: &WitnessProgram) -> Result<Self, InvalidShutdownScript> {
+               Self::try_from(ScriptBuf::new_witness_program(witness_program))
        }
 
-       /// Converts the shutdown script into the underlying [`Script`].
-       pub fn into_inner(self) -> Script {
+       /// Converts the shutdown script into the underlying [`ScriptBuf`].
+       pub fn into_inner(self) -> ScriptBuf {
                self.into()
        }
 
@@ -127,20 +123,20 @@ pub(crate) fn is_bolt2_compliant(script: &Script, features: &InitFeatures) -> bo
 
 // Note that this is only for our own shutdown scripts. Counterparties are still allowed to send us
 // non-witness shutdown scripts which this rejects.
-impl TryFrom<Script> for ShutdownScript {
+impl TryFrom<ScriptBuf> for ShutdownScript {
        type Error = InvalidShutdownScript;
 
-       fn try_from(script: Script) -> Result<Self, Self::Error> {
+       fn try_from(script: ScriptBuf) -> Result<Self, Self::Error> {
                Self::try_from((script, &channelmanager::provided_init_features(&crate::util::config::UserConfig::default())))
        }
 }
 
 // Note that this is only for our own shutdown scripts. Counterparties are still allowed to send us
 // non-witness shutdown scripts which this rejects.
-impl TryFrom<(Script, &InitFeatures)> for ShutdownScript {
+impl TryFrom<(ScriptBuf, &InitFeatures)> for ShutdownScript {
        type Error = InvalidShutdownScript;
 
-       fn try_from((script, features): (Script, &InitFeatures)) -> Result<Self, Self::Error> {
+       fn try_from((script, features): (ScriptBuf, &InitFeatures)) -> Result<Self, Self::Error> {
                if is_bolt2_compliant(&script, features) && script.is_witness_program() {
                        Ok(Self(ShutdownScriptImpl::Bolt2(script)))
                } else {
@@ -149,11 +145,11 @@ impl TryFrom<(Script, &InitFeatures)> for ShutdownScript {
        }
 }
 
-impl Into<Script> for ShutdownScript {
-       fn into(self) -> Script {
+impl Into<ScriptBuf> for ShutdownScript {
+       fn into(self) -> ScriptBuf {
                match self.0 {
                        ShutdownScriptImpl::Legacy(pubkey) =>
-                               Script::new_v0_p2wpkh(&WPubkeyHash::hash(&pubkey.serialize())),
+                               ScriptBuf::new_v0_p2wpkh(&WPubkeyHash::hash(&pubkey.serialize())),
                        ShutdownScriptImpl::Bolt2(script_pubkey) => script_pubkey,
                }
        }
@@ -172,20 +168,20 @@ impl core::fmt::Display for ShutdownScript{
 mod shutdown_script_tests {
        use super::ShutdownScript;
        use bitcoin::blockdata::opcodes;
-       use bitcoin::blockdata::script::{Builder, Script};
+       use bitcoin::blockdata::script::{Builder, ScriptBuf};
        use bitcoin::secp256k1::Secp256k1;
        use bitcoin::secp256k1::{PublicKey, SecretKey};
        use crate::ln::features::InitFeatures;
        use core::convert::TryFrom;
-       use bitcoin::util::address::WitnessVersion;
+       use bitcoin::address::{WitnessProgram, WitnessVersion};
 
-       fn pubkey() -> bitcoin::util::key::PublicKey {
+       fn pubkey() -> bitcoin::key::PublicKey {
                let secp_ctx = Secp256k1::signing_only();
                let secret_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, 0, 1]).unwrap();
-               bitcoin::util::key::PublicKey::new(PublicKey::from_secret_key(&secp_ctx, &secret_key))
+               bitcoin::key::PublicKey::new(PublicKey::from_secret_key(&secp_ctx, &secret_key))
        }
 
-       fn redeem_script() -> Script {
+       fn redeem_script() -> ScriptBuf {
                let pubkey = pubkey();
                Builder::new()
                        .push_opcode(opcodes::all::OP_PUSHNUM_2)
@@ -206,7 +202,7 @@ mod shutdown_script_tests {
        fn generates_p2wpkh_from_pubkey() {
                let pubkey = pubkey();
                let pubkey_hash = pubkey.wpubkey_hash().unwrap();
-               let p2wpkh_script = Script::new_v0_p2wpkh(&pubkey_hash);
+               let p2wpkh_script = ScriptBuf::new_v0_p2wpkh(&pubkey_hash);
 
                let shutdown_script = ShutdownScript::new_p2wpkh_from_pubkey(pubkey.inner);
                assert!(shutdown_script.is_compatible(&any_segwit_features()));
@@ -217,7 +213,7 @@ mod shutdown_script_tests {
        #[test]
        fn generates_p2wpkh_from_pubkey_hash() {
                let pubkey_hash = pubkey().wpubkey_hash().unwrap();
-               let p2wpkh_script = Script::new_v0_p2wpkh(&pubkey_hash);
+               let p2wpkh_script = ScriptBuf::new_v0_p2wpkh(&pubkey_hash);
 
                let shutdown_script = ShutdownScript::new_p2wpkh(&pubkey_hash);
                assert!(shutdown_script.is_compatible(&any_segwit_features()));
@@ -229,7 +225,7 @@ mod shutdown_script_tests {
        #[test]
        fn generates_p2wsh_from_script_hash() {
                let script_hash = redeem_script().wscript_hash();
-               let p2wsh_script = Script::new_v0_p2wsh(&script_hash);
+               let p2wsh_script = ScriptBuf::new_v0_p2wsh(&script_hash);
 
                let shutdown_script = ShutdownScript::new_p2wsh(&script_hash);
                assert!(shutdown_script.is_compatible(&any_segwit_features()));
@@ -240,30 +236,17 @@ mod shutdown_script_tests {
 
        #[test]
        fn generates_segwit_from_non_v0_witness_program() {
-               let witness_program = Script::new_witness_program(WitnessVersion::V16, &[0; 40]);
-               let shutdown_script = ShutdownScript::new_witness_program(WitnessVersion::V16, &[0; 40]).unwrap();
+               let witness_program = WitnessProgram::new(WitnessVersion::V16, &[0; 40]).unwrap();
+               let script = ScriptBuf::new_witness_program(&witness_program);
+               let shutdown_script = ShutdownScript::new_witness_program(&witness_program).unwrap();
                assert!(shutdown_script.is_compatible(&any_segwit_features()));
                assert!(!shutdown_script.is_compatible(&InitFeatures::empty()));
-               assert_eq!(shutdown_script.into_inner(), witness_program);
+               assert_eq!(shutdown_script.into_inner(), script);
        }
 
        #[test]
        fn fails_from_unsupported_script() {
-               let op_return = Script::new_op_return(&[0; 42]);
+               let op_return = ScriptBuf::new_op_return(&[0; 42]);
                assert!(ShutdownScript::try_from(op_return).is_err());
        }
-
-       #[test]
-       fn fails_from_invalid_segwit_v0_witness_program() {
-               let witness_program = Script::new_witness_program(WitnessVersion::V0, &[0; 2]);
-               assert!(ShutdownScript::try_from(witness_program).is_err());
-       }
-
-       #[test]
-       fn fails_from_invalid_segwit_non_v0_witness_program() {
-               let witness_program = Script::new_witness_program(WitnessVersion::V16, &[0; 42]);
-               assert!(ShutdownScript::try_from(witness_program).is_err());
-
-               assert!(ShutdownScript::new_witness_program(WitnessVersion::V16, &[0; 42]).is_err());
-       }
 }
index 664af77d412e646890abd529ca30e6d17ec5e06a..bc7c013771fb0e049d23283d6fce6f533d1d4ae1 100644 (file)
@@ -27,7 +27,7 @@ use crate::util::string::UntrustedString;
 use bitcoin::blockdata::script::Builder;
 use bitcoin::blockdata::opcodes;
 use bitcoin::network::constants::Network;
-use bitcoin::util::address::WitnessVersion;
+use bitcoin::address::{WitnessProgram, WitnessVersion};
 
 use regex;
 
@@ -781,7 +781,7 @@ fn test_unsupported_anysegwit_upfront_shutdown_script() {
        match events[0] {
                MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => {
                        assert_eq!(node_id, nodes[0].node.get_our_node_id());
-                       assert_eq!(msg.data, "Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: Script(OP_PUSHNUM_16 OP_PUSHBYTES_2 0028)");
+                       assert_eq!(msg.data, "Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: OP_PUSHNUM_16 OP_PUSHBYTES_2 0028");
                },
                _ => panic!("Unexpected event"),
        }
@@ -806,11 +806,11 @@ fn test_unsupported_anysegwit_upfront_shutdown_script() {
        match events[0] {
                MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => {
                        assert_eq!(node_id, nodes[1].node.get_our_node_id());
-                       assert_eq!(msg.data, "Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: Script(OP_PUSHNUM_16 OP_PUSHBYTES_2 0028)");
+                       assert_eq!(msg.data, "Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: OP_PUSHNUM_16 OP_PUSHBYTES_2 0028");
                },
                _ => panic!("Unexpected event"),
        }
-       check_closed_event!(nodes[0], 1, ClosureReason::ProcessingError { err: "Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: Script(OP_PUSHNUM_16 OP_PUSHBYTES_2 0028)".to_string() }
+       check_closed_event!(nodes[0], 1, ClosureReason::ProcessingError { err: "Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: OP_PUSHNUM_16 OP_PUSHBYTES_2 0028".to_string() }
                , [nodes[1].node.get_our_node_id()], 100000);
 }
 
@@ -835,7 +835,7 @@ fn test_invalid_upfront_shutdown_script() {
        match events[0] {
                MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => {
                        assert_eq!(node_id, nodes[0].node.get_our_node_id());
-                       assert_eq!(msg.data, "Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: Script(OP_0 OP_PUSHBYTES_2 0000)");
+                       assert_eq!(msg.data, "Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: OP_0 OP_PUSHBYTES_2 0000");
                },
                _ => panic!("Unexpected event"),
        }
@@ -927,8 +927,9 @@ fn test_unsupported_anysegwit_shutdown_script() {
 
        // Check that using an unsupported shutdown script fails and a supported one succeeds.
        let supported_shutdown_script = chanmon_cfgs[1].keys_manager.get_shutdown_scriptpubkey().unwrap();
+       let unsupported_witness_program = WitnessProgram::new(WitnessVersion::V16, &[0, 40]).unwrap();
        let unsupported_shutdown_script =
-               ShutdownScript::new_witness_program(WitnessVersion::V16, &[0, 40]).unwrap();
+               ShutdownScript::new_witness_program(&unsupported_witness_program).unwrap();
        chanmon_cfgs[1].keys_manager
                .expect(OnGetShutdownScriptpubkey { returns: unsupported_shutdown_script.clone() })
                .expect(OnGetShutdownScriptpubkey { returns: supported_shutdown_script });
index 5bd5a95d8e627a3e69964db540fbffa554bbddf4..d0e866b2f2ba9e2acbfa56f8912d8ffe2fbe62fb 100644 (file)
@@ -40,7 +40,7 @@
 //! let secp_ctx = Secp256k1::new();
 //! let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32])?);
 //! let pubkey = PublicKey::from(keys);
-//! let wpubkey_hash = bitcoin::util::key::PublicKey::new(pubkey).wpubkey_hash().unwrap();
+//! let wpubkey_hash = bitcoin::key::PublicKey::new(pubkey).wpubkey_hash().unwrap();
 //! let mut buffer = Vec::new();
 //!
 //! // Invoice for the "offer to be paid" flow.
@@ -70,7 +70,7 @@
 //! # let secp_ctx = Secp256k1::new();
 //! # let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32])?);
 //! # let pubkey = PublicKey::from(keys);
-//! # let wpubkey_hash = bitcoin::util::key::PublicKey::new(pubkey).wpubkey_hash().unwrap();
+//! # let wpubkey_hash = bitcoin::key::PublicKey::new(pubkey).wpubkey_hash().unwrap();
 //! # let mut buffer = Vec::new();
 //!
 //! // Invoice for the "offer for money" flow.
@@ -103,8 +103,8 @@ use bitcoin::hashes::Hash;
 use bitcoin::network::constants::Network;
 use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, self};
 use bitcoin::secp256k1::schnorr::Signature;
-use bitcoin::util::address::{Address, Payload, WitnessVersion};
-use bitcoin::util::schnorr::TweakedPublicKey;
+use bitcoin::address::{Address, Payload, WitnessProgram, WitnessVersion};
+use bitcoin::key::TweakedPublicKey;
 use core::convert::{AsRef, Infallible, TryFrom};
 use core::time::Duration;
 use crate::io;
@@ -291,7 +291,7 @@ impl<'a, S: SigningPubkeyStrategy> InvoiceBuilder<'a, S> {
        pub fn fallback_v0_p2wsh(mut self, script_hash: &WScriptHash) -> Self {
                let address = FallbackAddress {
                        version: WitnessVersion::V0.to_num(),
-                       program: Vec::from(&script_hash.into_inner()[..]),
+                       program: Vec::from(script_hash.to_byte_array()),
                };
                self.invoice.fields_mut().fallbacks.get_or_insert_with(Vec::new).push(address);
                self
@@ -304,7 +304,7 @@ impl<'a, S: SigningPubkeyStrategy> InvoiceBuilder<'a, S> {
        pub fn fallback_v0_p2wpkh(mut self, pubkey_hash: &WPubkeyHash) -> Self {
                let address = FallbackAddress {
                        version: WitnessVersion::V0.to_num(),
-                       program: Vec::from(&pubkey_hash.into_inner()[..]),
+                       program: Vec::from(pubkey_hash.to_byte_array()),
                };
                self.invoice.fields_mut().fallbacks.get_or_insert_with(Vec::new).push(address);
                self
@@ -930,15 +930,12 @@ impl InvoiceContents {
                                return None;
                        }
 
-                       let address = Address {
-                               payload: Payload::WitnessProgram {
-                                       version,
-                                       program: program.clone(),
-                               },
-                               network,
+                       let witness_program = match WitnessProgram::new(version, program.clone()) {
+                               Ok(witness_program) => witness_program,
+                               Err(_) => return None,
                        };
-
-                       if !address.is_standard() && version == WitnessVersion::V0 {
+                       let address = Address::new(network, Payload::WitnessProgram(witness_program));
+                       if !address.is_spend_standard() && version == WitnessVersion::V0 {
                                return None;
                        }
 
@@ -1305,12 +1302,12 @@ mod tests {
        use super::{Bolt12Invoice, DEFAULT_RELATIVE_EXPIRY, FallbackAddress, FullInvoiceTlvStreamRef, InvoiceTlvStreamRef, SIGNATURE_TAG, UnsignedBolt12Invoice};
 
        use bitcoin::blockdata::constants::ChainHash;
-       use bitcoin::blockdata::script::Script;
+       use bitcoin::blockdata::script::ScriptBuf;
        use bitcoin::hashes::Hash;
        use bitcoin::network::constants::Network;
        use bitcoin::secp256k1::{Message, Secp256k1, XOnlyPublicKey, self};
-       use bitcoin::util::address::{Address, Payload, WitnessVersion};
-       use bitcoin::util::schnorr::TweakedPublicKey;
+       use bitcoin::address::{Address, Payload, WitnessProgram, WitnessVersion};
+       use bitcoin::key::TweakedPublicKey;
        use core::convert::TryFrom;
        use core::time::Duration;
        use crate::blinded_path::{BlindedHop, BlindedPath};
@@ -1806,8 +1803,8 @@ mod tests {
 
        #[test]
        fn builds_invoice_with_fallback_address() {
-               let script = Script::new();
-               let pubkey = bitcoin::util::key::PublicKey::new(recipient_pubkey());
+               let script = ScriptBuf::new();
+               let pubkey = bitcoin::key::PublicKey::new(recipient_pubkey());
                let x_only_pubkey = XOnlyPublicKey::from_keypair(&recipient_keys()).0;
                let tweaked_pubkey = TweakedPublicKey::dangerous_assume_tweaked(x_only_pubkey);
 
@@ -1837,11 +1834,11 @@ mod tests {
                        Some(&vec![
                                FallbackAddress {
                                        version: WitnessVersion::V0.to_num(),
-                                       program: Vec::from(&script.wscript_hash().into_inner()[..]),
+                                       program: Vec::from(script.wscript_hash().to_byte_array()),
                                },
                                FallbackAddress {
                                        version: WitnessVersion::V0.to_num(),
-                                       program: Vec::from(&pubkey.wpubkey_hash().unwrap().into_inner()[..]),
+                                       program: Vec::from(pubkey.wpubkey_hash().unwrap().to_byte_array()),
                                },
                                FallbackAddress {
                                        version: WitnessVersion::V1.to_num(),
@@ -2095,8 +2092,8 @@ mod tests {
 
        #[test]
        fn parses_invoice_with_fallback_address() {
-               let script = Script::new();
-               let pubkey = bitcoin::util::key::PublicKey::new(recipient_pubkey());
+               let script = ScriptBuf::new();
+               let pubkey = bitcoin::key::PublicKey::new(recipient_pubkey());
                let x_only_pubkey = XOnlyPublicKey::from_keypair(&recipient_keys()).0;
                let tweaked_pubkey = TweakedPublicKey::dangerous_assume_tweaked(x_only_pubkey);
 
@@ -2129,26 +2126,16 @@ mod tests {
 
                match Bolt12Invoice::try_from(buffer) {
                        Ok(invoice) => {
+                               let v1_witness_program = WitnessProgram::new(WitnessVersion::V1, vec![0u8; 33]).unwrap();
+                               let v2_witness_program = WitnessProgram::new(WitnessVersion::V2, vec![0u8; 40]).unwrap();
                                assert_eq!(
                                        invoice.fallbacks(),
                                        vec![
                                                Address::p2wsh(&script, Network::Bitcoin),
                                                Address::p2wpkh(&pubkey, Network::Bitcoin).unwrap(),
                                                Address::p2tr_tweaked(tweaked_pubkey, Network::Bitcoin),
-                                               Address {
-                                                       payload: Payload::WitnessProgram {
-                                                               version: WitnessVersion::V1,
-                                                               program: vec![0u8; 33],
-                                                       },
-                                                       network: Network::Bitcoin,
-                                               },
-                                               Address {
-                                                       payload: Payload::WitnessProgram {
-                                                               version: WitnessVersion::V2,
-                                                               program: vec![0u8; 40],
-                                                       },
-                                                       network: Network::Bitcoin,
-                                               },
+                                               Address::new(Network::Bitcoin, Payload::WitnessProgram(v1_witness_program)),
+                                               Address::new(Network::Bitcoin, Payload::WitnessProgram(v2_witness_program)),
                                        ],
                                );
                        },
index 7330541220f625240dee1db5e13539a73aaea824..ced3b08b7c2f3a33becd7b2e4f2a444f909a66c9 100644 (file)
@@ -44,7 +44,7 @@ impl TaggedHash {
        pub(super) fn new(tag: &'static str, tlv_stream: &[u8]) -> Self {
                let tag_hash = sha256::Hash::hash(tag.as_bytes());
                let merkle_root = root_hash(tlv_stream);
-               let digest = Message::from_slice(&tagged_hash(tag_hash, merkle_root)).unwrap();
+               let digest = Message::from_slice(tagged_hash(tag_hash, merkle_root).as_byte_array()).unwrap();
                Self {
                        tag,
                        merkle_root,
@@ -273,6 +273,7 @@ mod tests {
        use super::{SIGNATURE_TYPES, TlvStream, WithoutSignatures};
 
        use bitcoin::hashes::{Hash, sha256};
+       use bitcoin::hashes::hex::FromHex;
        use bitcoin::secp256k1::{KeyPair, Message, Secp256k1, SecretKey};
        use bitcoin::secp256k1::schnorr::Signature;
        use core::convert::Infallible;
@@ -289,16 +290,16 @@ mod tests {
                macro_rules! tlv2 { () => { "02080000010000020003" } }
                macro_rules! tlv3 { () => { "03310266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c0351800000000000000010000000000000002" } }
                assert_eq!(
-                       super::root_hash(&hex::decode(tlv1!()).unwrap()),
-                       sha256::Hash::from_slice(&hex::decode("b013756c8fee86503a0b4abdab4cddeb1af5d344ca6fc2fa8b6c08938caa6f93").unwrap()).unwrap(),
+                       super::root_hash(&<Vec<u8>>::from_hex(tlv1!()).unwrap()),
+                       sha256::Hash::from_slice(&<Vec<u8>>::from_hex("b013756c8fee86503a0b4abdab4cddeb1af5d344ca6fc2fa8b6c08938caa6f93").unwrap()).unwrap(),
                );
                assert_eq!(
-                       super::root_hash(&hex::decode(concat!(tlv1!(), tlv2!())).unwrap()),
-                       sha256::Hash::from_slice(&hex::decode("c3774abbf4815aa54ccaa026bff6581f01f3be5fe814c620a252534f434bc0d1").unwrap()).unwrap(),
+                       super::root_hash(&<Vec<u8>>::from_hex(concat!(tlv1!(), tlv2!())).unwrap()),
+                       sha256::Hash::from_slice(&<Vec<u8>>::from_hex("c3774abbf4815aa54ccaa026bff6581f01f3be5fe814c620a252534f434bc0d1").unwrap()).unwrap(),
                );
                assert_eq!(
-                       super::root_hash(&hex::decode(concat!(tlv1!(), tlv2!(), tlv3!())).unwrap()),
-                       sha256::Hash::from_slice(&hex::decode("ab2e79b1283b0b31e0b035258de23782df6b89a38cfa7237bde69aed1a658c5d").unwrap()).unwrap(),
+                       super::root_hash(&<Vec<u8>>::from_hex(concat!(tlv1!(), tlv2!(), tlv3!())).unwrap()),
+                       sha256::Hash::from_slice(&<Vec<u8>>::from_hex("ab2e79b1283b0b31e0b035258de23782df6b89a38cfa7237bde69aed1a658c5d").unwrap()).unwrap(),
                );
        }
 
@@ -306,11 +307,11 @@ mod tests {
        fn calculates_merkle_root_hash_from_invoice_request() {
                let secp_ctx = Secp256k1::new();
                let recipient_pubkey = {
-                       let secret_key = SecretKey::from_slice(&hex::decode("4141414141414141414141414141414141414141414141414141414141414141").unwrap()).unwrap();
+                       let secret_key = SecretKey::from_slice(&<Vec<u8>>::from_hex("4141414141414141414141414141414141414141414141414141414141414141").unwrap()).unwrap();
                        KeyPair::from_secret_key(&secp_ctx, &secret_key).public_key()
                };
                let payer_keys = {
-                       let secret_key = SecretKey::from_slice(&hex::decode("4242424242424242424242424242424242424242424242424242424242424242").unwrap()).unwrap();
+                       let secret_key = SecretKey::from_slice(&<Vec<u8>>::from_hex("4242424242424242424242424242424242424242424242424242424242424242").unwrap()).unwrap();
                        KeyPair::from_secret_key(&secp_ctx, &secret_key)
                };
 
@@ -330,11 +331,11 @@ mod tests {
                );
                assert_eq!(
                        super::root_hash(&invoice_request.bytes[..]),
-                       sha256::Hash::from_slice(&hex::decode("608407c18ad9a94d9ea2bcdbe170b6c20c462a7833a197621c916f78cf18e624").unwrap()).unwrap(),
+                       sha256::Hash::from_slice(&<Vec<u8>>::from_hex("608407c18ad9a94d9ea2bcdbe170b6c20c462a7833a197621c916f78cf18e624").unwrap()).unwrap(),
                );
                assert_eq!(
                        invoice_request.signature(),
-                       Signature::from_slice(&hex::decode("b8f83ea3288cfd6ea510cdb481472575141e8d8744157f98562d162cc1c472526fdb24befefbdebab4dbb726bbd1b7d8aec057f8fa805187e5950d2bbe0e5642").unwrap()).unwrap(),
+                       Signature::from_slice(&<Vec<u8>>::from_hex("b8f83ea3288cfd6ea510cdb481472575141e8d8744157f98562d162cc1c472526fdb24befefbdebab4dbb726bbd1b7d8aec057f8fa805187e5950d2bbe0e5642").unwrap()).unwrap(),
                );
        }
 
@@ -352,7 +353,7 @@ mod tests {
                 let tagged_hash = unsigned_invoice_request.as_ref();
                 let expected_digest = unsigned_invoice_request.as_ref().as_digest();
                 let tag = sha256::Hash::hash(tagged_hash.tag().as_bytes());
-                let actual_digest = Message::from_slice(&super::tagged_hash(tag, tagged_hash.merkle_root()))
+                let actual_digest = Message::from_slice(super::tagged_hash(tag, tagged_hash.merkle_root()).as_byte_array())
                         .unwrap();
                 assert_eq!(*expected_digest, actual_digest);
         }
index 4d5d4662bd62b806cb78543e41653c266a02146a..e0abd82767f6c9fd51dc0a7e425f7236631a0f67 100644 (file)
@@ -183,7 +183,7 @@ impl MetadataMaterial {
 
                let mut bytes = self.encrypted_payment_id.map(|id| id.to_vec()).unwrap_or(vec![]);
                bytes.extend_from_slice(self.nonce.as_slice());
-               bytes.extend_from_slice(&Hmac::from_engine(self.hmac).into_inner());
+               bytes.extend_from_slice(Hmac::from_engine(self.hmac).as_byte_array());
                bytes
        }
 
@@ -197,7 +197,7 @@ impl MetadataMaterial {
                bytes.extend_from_slice(self.nonce.as_slice());
 
                let hmac = Hmac::from_engine(self.hmac);
-               let privkey = SecretKey::from_slice(hmac.as_inner()).unwrap();
+               let privkey = SecretKey::from_slice(hmac.as_byte_array()).unwrap();
                let keys = KeyPair::from_secret_key(secp_ctx, &privkey);
 
                (bytes, keys)
@@ -218,7 +218,7 @@ pub(super) fn derive_keys(nonce: Nonce, expanded_key: &ExpandedKey) -> KeyPair {
        const IV_BYTES: &[u8; IV_LEN] = b"LDK Invoice ~~~~";
        let secp_ctx = Secp256k1::new();
        let hmac = Hmac::from_engine(expanded_key.hmac_for_offer(nonce, IV_BYTES));
-       let privkey = SecretKey::from_slice(hmac.as_inner()).unwrap();
+       let privkey = SecretKey::from_slice(hmac.as_byte_array()).unwrap();
        KeyPair::from_secret_key(&secp_ctx, &privkey)
 }
 
@@ -283,7 +283,7 @@ fn verify_metadata<T: secp256k1::Signing>(
 ) -> Result<Option<KeyPair>, ()> {
        if metadata.len() == Nonce::LENGTH {
                let derived_keys = KeyPair::from_secret_key(
-                       secp_ctx, &SecretKey::from_slice(hmac.as_inner()).unwrap()
+                       secp_ctx, &SecretKey::from_slice(hmac.as_byte_array()).unwrap()
                );
                if fixed_time_eq(&signing_pubkey.serialize(), &derived_keys.public_key().serialize()) {
                        Ok(Some(derived_keys))
@@ -291,7 +291,7 @@ fn verify_metadata<T: secp256k1::Signing>(
                        Err(())
                }
        } else if metadata[Nonce::LENGTH..].len() == Sha256::LEN {
-               if fixed_time_eq(&metadata[Nonce::LENGTH..], &hmac.into_inner()) {
+               if fixed_time_eq(&metadata[Nonce::LENGTH..], &hmac.to_byte_array()) {
                        Ok(None)
                } else {
                        Err(())
index 0193001b30c0d5ca4fc0421b27470a9fab81d0de..32a0fa3eb26fa3bdf5cff00509a81af819f3be23 100644 (file)
@@ -18,6 +18,7 @@ use crate::util::test_utils;
 use super::{CustomOnionMessageHandler, Destination, MessageRouter, OffersMessage, OffersMessageHandler, OnionMessageContents, OnionMessagePath, OnionMessenger, PendingOnionMessage, SendError};
 
 use bitcoin::network::constants::Network;
+use bitcoin::hashes::hex::FromHex;
 use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
 
 use crate::io;
@@ -442,13 +443,13 @@ fn many_hops() {
 fn spec_test_vector() {
        let keys_mgrs = vec![
                (Arc::new(test_utils::TestKeysInterface::new(&[0; 32], Network::Testnet)), // Alice
-                Arc::new(test_utils::TestNodeSigner::new(SecretKey::from_slice(&hex::decode("4141414141414141414141414141414141414141414141414141414141414141").unwrap()).unwrap()))),
+                Arc::new(test_utils::TestNodeSigner::new(SecretKey::from_slice(&<Vec<u8>>::from_hex("4141414141414141414141414141414141414141414141414141414141414141").unwrap()).unwrap()))),
                (Arc::new(test_utils::TestKeysInterface::new(&[1; 32], Network::Testnet)), // Bob
-                Arc::new(test_utils::TestNodeSigner::new(SecretKey::from_slice(&hex::decode("4242424242424242424242424242424242424242424242424242424242424242").unwrap()).unwrap()))),
+                Arc::new(test_utils::TestNodeSigner::new(SecretKey::from_slice(&<Vec<u8>>::from_hex("4242424242424242424242424242424242424242424242424242424242424242").unwrap()).unwrap()))),
                (Arc::new(test_utils::TestKeysInterface::new(&[2; 32], Network::Testnet)), // Carol
-                Arc::new(test_utils::TestNodeSigner::new(SecretKey::from_slice(&hex::decode("4343434343434343434343434343434343434343434343434343434343434343").unwrap()).unwrap()))),
+                Arc::new(test_utils::TestNodeSigner::new(SecretKey::from_slice(&<Vec<u8>>::from_hex("4343434343434343434343434343434343434343434343434343434343434343").unwrap()).unwrap()))),
                (Arc::new(test_utils::TestKeysInterface::new(&[3; 32], Network::Testnet)), // Dave
-                Arc::new(test_utils::TestNodeSigner::new(SecretKey::from_slice(&hex::decode("4444444444444444444444444444444444444444444444444444444444444444").unwrap()).unwrap()))),
+                Arc::new(test_utils::TestNodeSigner::new(SecretKey::from_slice(&<Vec<u8>>::from_hex("4444444444444444444444444444444444444444444444444444444444444444").unwrap()).unwrap()))),
        ];
        let message_router = Arc::new(TestMessageRouter {});
        let offers_message_handler = Arc::new(TestOffersMessageHandler {});
@@ -474,7 +475,7 @@ fn spec_test_vector() {
 
        // Hardcode the sender->Alice onion message, because it includes an unknown TLV of type 1, which
        // LDK doesn't support constructing.
-       let sender_to_alice_packet_bytes = hex::decode("0002531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe33793b828776d70aabbd8cef1a5b52d5a397ae1a20f20435ff6057cd8be339d5aee226660ef73b64afa45dbf2e6e8e26eb96a259b2db5aeecda1ce2e768bbc35d389d7f320ca3d2bd14e2689bef2f5ac0307eaaabc1924eb972c1563d4646ae131accd39da766257ed35ea36e4222527d1db4fa7b2000aab9eafcceed45e28b5560312d4e2299bd8d1e7fe27d10925966c28d497aec400b4630485e82efbabc00550996bdad5d6a9a8c75952f126d14ad2cff91e16198691a7ef2937de83209285f1fb90944b4e46bca7c856a9ce3da10cdf2a7d00dc2bf4f114bc4d3ed67b91cbde558ce9af86dc81fbdc37f8e301b29e23c1466659c62bdbf8cff5d4c20f0fb0851ec72f5e9385dd40fdd2e3ed67ca4517117825665e50a3e26f73c66998daf18e418e8aef9ce2d20da33c3629db2933640e03e7b44c2edf49e9b482db7b475cfd4c617ae1d46d5c24d697846f9f08561eac2b065f9b382501f6eabf07343ed6c602f61eab99cdb52adf63fd44a8db2d3016387ea708fc1c08591e19b4d9984ebe31edbd684c2ea86526dd8c7732b1d8d9117511dc1b643976d356258fce8313b1cb92682f41ab72dedd766f06de375f9edacbcd0ca8c99b865ea2b7952318ea1fd20775a28028b5cf59dece5de14f615b8df254eee63493a5111ea987224bea006d8f1b60d565eef06ac0da194dba2a6d02e79b2f2f34e9ca6e1984a507319d86e9d4fcaeea41b4b9144e0b1826304d4cc1da61cfc5f8b9850697df8adc5e9d6f3acb3219b02764b4909f2b2b22e799fd66c383414a84a7d791b899d4aa663770009eb122f90282c8cb9cda16aba6897edcf9b32951d0080c0f52be3ca011fbec3fb16423deb47744645c3b05fdbd932edf54ba6efd26e65340a8e9b1d1216582e1b30d64524f8ca2d6c5ba63a38f7120a3ed71bed8960bcac2feee2dd41c90be48e3c11ec518eb3d872779e4765a6cc28c6b0fa71ab57ced73ae963cc630edae4258cba2bf25821a6ae049fec2fca28b5dd1bb004d92924b65701b06dcf37f0ccd147a13a03f9bc0f98b7d78fe9058089756931e2cd0e0ed92ec6759d07b248069526c67e9e6ce095118fd3501ba0f858ef030b76c6f6beb11a09317b5ad25343f4b31aef02bc555951bc7791c2c289ecf94d5544dcd6ad3021ed8e8e3db34b2a73e1eedb57b578b068a5401836d6e382110b73690a94328c404af25e85a8d6b808893d1b71af6a31fadd8a8cc6e31ecc0d9ff7e6b91fd03c274a5c1f1ccd25b61150220a3fddb04c91012f5f7a83a5c90deb2470089d6e38cd5914b9c946eca6e9d31bbf8667d36cf87effc3f3ff283c21dd4137bd569fe7cf758feac94053e4baf7338bb592c8b7c291667fadf4a9bf9a2a154a18f612cbc7f851b3f8f2070e0a9d180622ee4f8e81b0ab250d504cef24116a3ff188cc829fcd8610b56343569e8dc997629410d1967ca9dd1d27eec5e01e4375aad16c46faba268524b154850d0d6fe3a76af2c6aa3e97647c51036049ac565370028d6a439a2672b6face56e1b171496c0722cfa22d9da631be359661617c5d5a2d286c5e19db9452c1e21a0107b6400debda2decb0c838f342dd017cdb2dccdf1fe97e3df3f881856b546997a3fed9e279c720145101567dd56be21688fed66bf9759e432a9aa89cbbd225d13cdea4ca05f7a45cfb6a682a3d5b1e18f7e6cf934fae5098108bae9058d05c3387a01d8d02a656d2bfff67e9f46b2d8a6aac28129e52efddf6e552214c3f8a45bc7a912cca9a7fec1d7d06412c6972cb9e3dc518983f56530b8bffe7f92c4b6eb47d4aef59fb513c4653a42de61bc17ad7728e7fc7590ff05a9e991de03f023d0aaf8688ed6170def5091c66576a424ac1cb").unwrap();
+       let sender_to_alice_packet_bytes = <Vec<u8>>::from_hex("0002531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe33793b828776d70aabbd8cef1a5b52d5a397ae1a20f20435ff6057cd8be339d5aee226660ef73b64afa45dbf2e6e8e26eb96a259b2db5aeecda1ce2e768bbc35d389d7f320ca3d2bd14e2689bef2f5ac0307eaaabc1924eb972c1563d4646ae131accd39da766257ed35ea36e4222527d1db4fa7b2000aab9eafcceed45e28b5560312d4e2299bd8d1e7fe27d10925966c28d497aec400b4630485e82efbabc00550996bdad5d6a9a8c75952f126d14ad2cff91e16198691a7ef2937de83209285f1fb90944b4e46bca7c856a9ce3da10cdf2a7d00dc2bf4f114bc4d3ed67b91cbde558ce9af86dc81fbdc37f8e301b29e23c1466659c62bdbf8cff5d4c20f0fb0851ec72f5e9385dd40fdd2e3ed67ca4517117825665e50a3e26f73c66998daf18e418e8aef9ce2d20da33c3629db2933640e03e7b44c2edf49e9b482db7b475cfd4c617ae1d46d5c24d697846f9f08561eac2b065f9b382501f6eabf07343ed6c602f61eab99cdb52adf63fd44a8db2d3016387ea708fc1c08591e19b4d9984ebe31edbd684c2ea86526dd8c7732b1d8d9117511dc1b643976d356258fce8313b1cb92682f41ab72dedd766f06de375f9edacbcd0ca8c99b865ea2b7952318ea1fd20775a28028b5cf59dece5de14f615b8df254eee63493a5111ea987224bea006d8f1b60d565eef06ac0da194dba2a6d02e79b2f2f34e9ca6e1984a507319d86e9d4fcaeea41b4b9144e0b1826304d4cc1da61cfc5f8b9850697df8adc5e9d6f3acb3219b02764b4909f2b2b22e799fd66c383414a84a7d791b899d4aa663770009eb122f90282c8cb9cda16aba6897edcf9b32951d0080c0f52be3ca011fbec3fb16423deb47744645c3b05fdbd932edf54ba6efd26e65340a8e9b1d1216582e1b30d64524f8ca2d6c5ba63a38f7120a3ed71bed8960bcac2feee2dd41c90be48e3c11ec518eb3d872779e4765a6cc28c6b0fa71ab57ced73ae963cc630edae4258cba2bf25821a6ae049fec2fca28b5dd1bb004d92924b65701b06dcf37f0ccd147a13a03f9bc0f98b7d78fe9058089756931e2cd0e0ed92ec6759d07b248069526c67e9e6ce095118fd3501ba0f858ef030b76c6f6beb11a09317b5ad25343f4b31aef02bc555951bc7791c2c289ecf94d5544dcd6ad3021ed8e8e3db34b2a73e1eedb57b578b068a5401836d6e382110b73690a94328c404af25e85a8d6b808893d1b71af6a31fadd8a8cc6e31ecc0d9ff7e6b91fd03c274a5c1f1ccd25b61150220a3fddb04c91012f5f7a83a5c90deb2470089d6e38cd5914b9c946eca6e9d31bbf8667d36cf87effc3f3ff283c21dd4137bd569fe7cf758feac94053e4baf7338bb592c8b7c291667fadf4a9bf9a2a154a18f612cbc7f851b3f8f2070e0a9d180622ee4f8e81b0ab250d504cef24116a3ff188cc829fcd8610b56343569e8dc997629410d1967ca9dd1d27eec5e01e4375aad16c46faba268524b154850d0d6fe3a76af2c6aa3e97647c51036049ac565370028d6a439a2672b6face56e1b171496c0722cfa22d9da631be359661617c5d5a2d286c5e19db9452c1e21a0107b6400debda2decb0c838f342dd017cdb2dccdf1fe97e3df3f881856b546997a3fed9e279c720145101567dd56be21688fed66bf9759e432a9aa89cbbd225d13cdea4ca05f7a45cfb6a682a3d5b1e18f7e6cf934fae5098108bae9058d05c3387a01d8d02a656d2bfff67e9f46b2d8a6aac28129e52efddf6e552214c3f8a45bc7a912cca9a7fec1d7d06412c6972cb9e3dc518983f56530b8bffe7f92c4b6eb47d4aef59fb513c4653a42de61bc17ad7728e7fc7590ff05a9e991de03f023d0aaf8688ed6170def5091c66576a424ac1cb").unwrap();
        let sender_to_alice_packet_bytes_len = sender_to_alice_packet_bytes.len() as u64;
        let mut reader = io::Cursor::new(sender_to_alice_packet_bytes);
        let mut packet_reader = FixedLengthReader::new(&mut reader, sender_to_alice_packet_bytes_len);
@@ -482,27 +483,27 @@ fn spec_test_vector() {
                <super::Packet as LengthReadable>::read(&mut packet_reader).unwrap();
        let secp_ctx = Secp256k1::new();
        let sender_to_alice_om = msgs::OnionMessage {
-               blinding_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("6363636363636363636363636363636363636363636363636363636363636363").unwrap()).unwrap()),
+               blinding_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&<Vec<u8>>::from_hex("6363636363636363636363636363636363636363636363636363636363636363").unwrap()).unwrap()),
                onion_routing_packet: sender_to_alice_packet,
        };
        // The spec test vectors prepend the OM message type (513) to the encoded onion message strings,
        // which is why the asserted strings differ slightly from the spec.
-       assert_eq!(sender_to_alice_om.encode(), hex::decode("031195a8046dcbb8e17034bca630065e7a0982e4e36f6f7e5a8d4554e4846fcd9905560002531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe33793b828776d70aabbd8cef1a5b52d5a397ae1a20f20435ff6057cd8be339d5aee226660ef73b64afa45dbf2e6e8e26eb96a259b2db5aeecda1ce2e768bbc35d389d7f320ca3d2bd14e2689bef2f5ac0307eaaabc1924eb972c1563d4646ae131accd39da766257ed35ea36e4222527d1db4fa7b2000aab9eafcceed45e28b5560312d4e2299bd8d1e7fe27d10925966c28d497aec400b4630485e82efbabc00550996bdad5d6a9a8c75952f126d14ad2cff91e16198691a7ef2937de83209285f1fb90944b4e46bca7c856a9ce3da10cdf2a7d00dc2bf4f114bc4d3ed67b91cbde558ce9af86dc81fbdc37f8e301b29e23c1466659c62bdbf8cff5d4c20f0fb0851ec72f5e9385dd40fdd2e3ed67ca4517117825665e50a3e26f73c66998daf18e418e8aef9ce2d20da33c3629db2933640e03e7b44c2edf49e9b482db7b475cfd4c617ae1d46d5c24d697846f9f08561eac2b065f9b382501f6eabf07343ed6c602f61eab99cdb52adf63fd44a8db2d3016387ea708fc1c08591e19b4d9984ebe31edbd684c2ea86526dd8c7732b1d8d9117511dc1b643976d356258fce8313b1cb92682f41ab72dedd766f06de375f9edacbcd0ca8c99b865ea2b7952318ea1fd20775a28028b5cf59dece5de14f615b8df254eee63493a5111ea987224bea006d8f1b60d565eef06ac0da194dba2a6d02e79b2f2f34e9ca6e1984a507319d86e9d4fcaeea41b4b9144e0b1826304d4cc1da61cfc5f8b9850697df8adc5e9d6f3acb3219b02764b4909f2b2b22e799fd66c383414a84a7d791b899d4aa663770009eb122f90282c8cb9cda16aba6897edcf9b32951d0080c0f52be3ca011fbec3fb16423deb47744645c3b05fdbd932edf54ba6efd26e65340a8e9b1d1216582e1b30d64524f8ca2d6c5ba63a38f7120a3ed71bed8960bcac2feee2dd41c90be48e3c11ec518eb3d872779e4765a6cc28c6b0fa71ab57ced73ae963cc630edae4258cba2bf25821a6ae049fec2fca28b5dd1bb004d92924b65701b06dcf37f0ccd147a13a03f9bc0f98b7d78fe9058089756931e2cd0e0ed92ec6759d07b248069526c67e9e6ce095118fd3501ba0f858ef030b76c6f6beb11a09317b5ad25343f4b31aef02bc555951bc7791c2c289ecf94d5544dcd6ad3021ed8e8e3db34b2a73e1eedb57b578b068a5401836d6e382110b73690a94328c404af25e85a8d6b808893d1b71af6a31fadd8a8cc6e31ecc0d9ff7e6b91fd03c274a5c1f1ccd25b61150220a3fddb04c91012f5f7a83a5c90deb2470089d6e38cd5914b9c946eca6e9d31bbf8667d36cf87effc3f3ff283c21dd4137bd569fe7cf758feac94053e4baf7338bb592c8b7c291667fadf4a9bf9a2a154a18f612cbc7f851b3f8f2070e0a9d180622ee4f8e81b0ab250d504cef24116a3ff188cc829fcd8610b56343569e8dc997629410d1967ca9dd1d27eec5e01e4375aad16c46faba268524b154850d0d6fe3a76af2c6aa3e97647c51036049ac565370028d6a439a2672b6face56e1b171496c0722cfa22d9da631be359661617c5d5a2d286c5e19db9452c1e21a0107b6400debda2decb0c838f342dd017cdb2dccdf1fe97e3df3f881856b546997a3fed9e279c720145101567dd56be21688fed66bf9759e432a9aa89cbbd225d13cdea4ca05f7a45cfb6a682a3d5b1e18f7e6cf934fae5098108bae9058d05c3387a01d8d02a656d2bfff67e9f46b2d8a6aac28129e52efddf6e552214c3f8a45bc7a912cca9a7fec1d7d06412c6972cb9e3dc518983f56530b8bffe7f92c4b6eb47d4aef59fb513c4653a42de61bc17ad7728e7fc7590ff05a9e991de03f023d0aaf8688ed6170def5091c66576a424ac1cb").unwrap());
+       assert_eq!(sender_to_alice_om.encode(), <Vec<u8>>::from_hex("031195a8046dcbb8e17034bca630065e7a0982e4e36f6f7e5a8d4554e4846fcd9905560002531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe33793b828776d70aabbd8cef1a5b52d5a397ae1a20f20435ff6057cd8be339d5aee226660ef73b64afa45dbf2e6e8e26eb96a259b2db5aeecda1ce2e768bbc35d389d7f320ca3d2bd14e2689bef2f5ac0307eaaabc1924eb972c1563d4646ae131accd39da766257ed35ea36e4222527d1db4fa7b2000aab9eafcceed45e28b5560312d4e2299bd8d1e7fe27d10925966c28d497aec400b4630485e82efbabc00550996bdad5d6a9a8c75952f126d14ad2cff91e16198691a7ef2937de83209285f1fb90944b4e46bca7c856a9ce3da10cdf2a7d00dc2bf4f114bc4d3ed67b91cbde558ce9af86dc81fbdc37f8e301b29e23c1466659c62bdbf8cff5d4c20f0fb0851ec72f5e9385dd40fdd2e3ed67ca4517117825665e50a3e26f73c66998daf18e418e8aef9ce2d20da33c3629db2933640e03e7b44c2edf49e9b482db7b475cfd4c617ae1d46d5c24d697846f9f08561eac2b065f9b382501f6eabf07343ed6c602f61eab99cdb52adf63fd44a8db2d3016387ea708fc1c08591e19b4d9984ebe31edbd684c2ea86526dd8c7732b1d8d9117511dc1b643976d356258fce8313b1cb92682f41ab72dedd766f06de375f9edacbcd0ca8c99b865ea2b7952318ea1fd20775a28028b5cf59dece5de14f615b8df254eee63493a5111ea987224bea006d8f1b60d565eef06ac0da194dba2a6d02e79b2f2f34e9ca6e1984a507319d86e9d4fcaeea41b4b9144e0b1826304d4cc1da61cfc5f8b9850697df8adc5e9d6f3acb3219b02764b4909f2b2b22e799fd66c383414a84a7d791b899d4aa663770009eb122f90282c8cb9cda16aba6897edcf9b32951d0080c0f52be3ca011fbec3fb16423deb47744645c3b05fdbd932edf54ba6efd26e65340a8e9b1d1216582e1b30d64524f8ca2d6c5ba63a38f7120a3ed71bed8960bcac2feee2dd41c90be48e3c11ec518eb3d872779e4765a6cc28c6b0fa71ab57ced73ae963cc630edae4258cba2bf25821a6ae049fec2fca28b5dd1bb004d92924b65701b06dcf37f0ccd147a13a03f9bc0f98b7d78fe9058089756931e2cd0e0ed92ec6759d07b248069526c67e9e6ce095118fd3501ba0f858ef030b76c6f6beb11a09317b5ad25343f4b31aef02bc555951bc7791c2c289ecf94d5544dcd6ad3021ed8e8e3db34b2a73e1eedb57b578b068a5401836d6e382110b73690a94328c404af25e85a8d6b808893d1b71af6a31fadd8a8cc6e31ecc0d9ff7e6b91fd03c274a5c1f1ccd25b61150220a3fddb04c91012f5f7a83a5c90deb2470089d6e38cd5914b9c946eca6e9d31bbf8667d36cf87effc3f3ff283c21dd4137bd569fe7cf758feac94053e4baf7338bb592c8b7c291667fadf4a9bf9a2a154a18f612cbc7f851b3f8f2070e0a9d180622ee4f8e81b0ab250d504cef24116a3ff188cc829fcd8610b56343569e8dc997629410d1967ca9dd1d27eec5e01e4375aad16c46faba268524b154850d0d6fe3a76af2c6aa3e97647c51036049ac565370028d6a439a2672b6face56e1b171496c0722cfa22d9da631be359661617c5d5a2d286c5e19db9452c1e21a0107b6400debda2decb0c838f342dd017cdb2dccdf1fe97e3df3f881856b546997a3fed9e279c720145101567dd56be21688fed66bf9759e432a9aa89cbbd225d13cdea4ca05f7a45cfb6a682a3d5b1e18f7e6cf934fae5098108bae9058d05c3387a01d8d02a656d2bfff67e9f46b2d8a6aac28129e52efddf6e552214c3f8a45bc7a912cca9a7fec1d7d06412c6972cb9e3dc518983f56530b8bffe7f92c4b6eb47d4aef59fb513c4653a42de61bc17ad7728e7fc7590ff05a9e991de03f023d0aaf8688ed6170def5091c66576a424ac1cb").unwrap());
        let sender_dummy_node_id = PublicKey::from_slice(&[2; 33]).unwrap();
        nodes[0].handle_onion_message(&sender_dummy_node_id, &sender_to_alice_om);
        let alice_to_bob_om = nodes[0].next_onion_message_for_peer(
                keys_mgrs[1].1.get_node_id(Recipient::Node).unwrap()).unwrap();
-       assert_eq!(alice_to_bob_om.encode(), hex::decode("031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f05560002536d53f93796cad550b6c68662dca41f7e8c221c31022c64dd1a627b2df3982b25eac261e88369cfc66e1e3b6d9829cb3dcd707046e68a7796065202a7904811bf2608c5611cf74c9eb5371c7eb1a4428bb39a041493e2a568ddb0b2482a6cc6711bc6116cef144ebf988073cb18d9dd4ce2d3aa9de91a7dc6d7c6f11a852024626e66b41ba1158055505dff9cb15aa51099f315564d9ee3ed6349665dc3e209eedf9b5805ee4f69d315df44c80e63d0e2efbdab60ec96f44a3447c6a6ddb1efb6aa4e072bde1dab974081646bfddf3b02daa2b83847d74dd336465e76e9b8fecc2b0414045eeedfc39939088a76820177dd1103c99939e659beb07197bab9f714b30ba8dc83738e9a6553a57888aaeda156c68933a2f4ff35e3f81135076b944ed9856acbfee9c61299a5d1763eadd14bf5eaf71304c8e165e590d7ecbcd25f1650bf5b6c2ad1823b2dc9145e168974ecf6a2273c94decff76d94bc6708007a17f22262d63033c184d0166c14f41b225a956271947aae6ce65890ed8f0d09c6ffe05ec02ee8b9de69d7077a0c5adeb813aabcc1ba8975b73ab06ddea5f4db3c23a1de831602de2b83f990d4133871a1a81e53f86393e6a7c3a7b73f0c099fa72afe26c3027bb9412338a19303bd6e6591c04fb4cde9b832b5f41ae199301ea8c303b5cef3aca599454273565de40e1148156d1f97c1aa9e58459ab318304075e034f5b7899c12587b86776a18a1da96b7bcdc22864fccc4c41538ebce92a6f054d53bf46770273a70e75fe0155cd6d2f2e937465b0825ce3123b8c206fac4c30478fa0f08a97ade7216dce11626401374993213636e93545a31f500562130f2feb04089661ad8c34d5a4cbd2e4e426f37cb094c786198a220a2646ecadc38c04c29ee67b19d662c209a7b30bfecc7fe8bf7d274de0605ee5df4db490f6d32234f6af639d3fce38a2801bcf8d51e9c090a6c6932355a83848129a378095b34e71cb8f51152dc035a4fe8e802fec8de221a02ba5afd6765ce570bef912f87357936ea0b90cb2990f56035e89539ec66e8dbd6ed50835158614096990e019c3eba3d7dd6a77147641c6145e8b17552cd5cf7cd163dd40b9eaeba8c78e03a2cd8c0b7997d6f56d35f38983a202b4eb8a54e14945c4de1a6dde46167e11708b7a5ff5cb9c0f7fc12fae49a012aa90bb1995c038130b749c48e6f1ffb732e92086def42af10fbc460d94abeb7b2fa744a5e9a491d62a08452be8cf2fdef573deedc1fe97098bce889f98200b26f9bb99da9aceddda6d793d8e0e44a2601ef4590cfbb5c3d0197aac691e3d31c20fd8e38764962ca34dabeb85df28feabaf6255d4d0df3d814455186a84423182caa87f9673df770432ad8fdfe78d4888632d460d36d2719e8fa8e4b4ca10d817c5d6bc44a8b2affab8c2ba53b8bf4994d63286c2fad6be04c28661162fa1a67065ecda8ba8c13aee4a8039f4f0110e0c0da2366f178d8903e19136dad6df9d8693ce71f3a270f9941de2a93d9b67bc516207ac1687bf6e00b29723c42c7d9c90df9d5e599dbeb7b73add0a6a2b7aba82f98ac93cb6e60494040445229f983a81c34f7f686d166dfc98ec23a6318d4a02a311ac28d655ea4e0f9c3014984f31e621ef003e98c373561d9040893feece2e0fa6cd2dd565e6fbb2773a2407cb2c3273c306cf71f427f2e551c4092e067cf9869f31ac7c6c80dd52d4f85be57a891a41e34be0d564e39b4af6f46b85339254a58b205fb7e10e7d0470ee73622493f28c08962118c23a1198467e72c4ae1cd482144b419247a5895975ea90d135e2a46ef7e5794a1551a447ff0a0d299b66a7f565cd86531f5e7af5408d85d877ce95b1df12b88b7d5954903a5296325ba478ba1e1a9d1f30a2d5052b2e2889bbd64f72c72bc71d8817288a2").unwrap());
+       assert_eq!(alice_to_bob_om.encode(), <Vec<u8>>::from_hex("031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f05560002536d53f93796cad550b6c68662dca41f7e8c221c31022c64dd1a627b2df3982b25eac261e88369cfc66e1e3b6d9829cb3dcd707046e68a7796065202a7904811bf2608c5611cf74c9eb5371c7eb1a4428bb39a041493e2a568ddb0b2482a6cc6711bc6116cef144ebf988073cb18d9dd4ce2d3aa9de91a7dc6d7c6f11a852024626e66b41ba1158055505dff9cb15aa51099f315564d9ee3ed6349665dc3e209eedf9b5805ee4f69d315df44c80e63d0e2efbdab60ec96f44a3447c6a6ddb1efb6aa4e072bde1dab974081646bfddf3b02daa2b83847d74dd336465e76e9b8fecc2b0414045eeedfc39939088a76820177dd1103c99939e659beb07197bab9f714b30ba8dc83738e9a6553a57888aaeda156c68933a2f4ff35e3f81135076b944ed9856acbfee9c61299a5d1763eadd14bf5eaf71304c8e165e590d7ecbcd25f1650bf5b6c2ad1823b2dc9145e168974ecf6a2273c94decff76d94bc6708007a17f22262d63033c184d0166c14f41b225a956271947aae6ce65890ed8f0d09c6ffe05ec02ee8b9de69d7077a0c5adeb813aabcc1ba8975b73ab06ddea5f4db3c23a1de831602de2b83f990d4133871a1a81e53f86393e6a7c3a7b73f0c099fa72afe26c3027bb9412338a19303bd6e6591c04fb4cde9b832b5f41ae199301ea8c303b5cef3aca599454273565de40e1148156d1f97c1aa9e58459ab318304075e034f5b7899c12587b86776a18a1da96b7bcdc22864fccc4c41538ebce92a6f054d53bf46770273a70e75fe0155cd6d2f2e937465b0825ce3123b8c206fac4c30478fa0f08a97ade7216dce11626401374993213636e93545a31f500562130f2feb04089661ad8c34d5a4cbd2e4e426f37cb094c786198a220a2646ecadc38c04c29ee67b19d662c209a7b30bfecc7fe8bf7d274de0605ee5df4db490f6d32234f6af639d3fce38a2801bcf8d51e9c090a6c6932355a83848129a378095b34e71cb8f51152dc035a4fe8e802fec8de221a02ba5afd6765ce570bef912f87357936ea0b90cb2990f56035e89539ec66e8dbd6ed50835158614096990e019c3eba3d7dd6a77147641c6145e8b17552cd5cf7cd163dd40b9eaeba8c78e03a2cd8c0b7997d6f56d35f38983a202b4eb8a54e14945c4de1a6dde46167e11708b7a5ff5cb9c0f7fc12fae49a012aa90bb1995c038130b749c48e6f1ffb732e92086def42af10fbc460d94abeb7b2fa744a5e9a491d62a08452be8cf2fdef573deedc1fe97098bce889f98200b26f9bb99da9aceddda6d793d8e0e44a2601ef4590cfbb5c3d0197aac691e3d31c20fd8e38764962ca34dabeb85df28feabaf6255d4d0df3d814455186a84423182caa87f9673df770432ad8fdfe78d4888632d460d36d2719e8fa8e4b4ca10d817c5d6bc44a8b2affab8c2ba53b8bf4994d63286c2fad6be04c28661162fa1a67065ecda8ba8c13aee4a8039f4f0110e0c0da2366f178d8903e19136dad6df9d8693ce71f3a270f9941de2a93d9b67bc516207ac1687bf6e00b29723c42c7d9c90df9d5e599dbeb7b73add0a6a2b7aba82f98ac93cb6e60494040445229f983a81c34f7f686d166dfc98ec23a6318d4a02a311ac28d655ea4e0f9c3014984f31e621ef003e98c373561d9040893feece2e0fa6cd2dd565e6fbb2773a2407cb2c3273c306cf71f427f2e551c4092e067cf9869f31ac7c6c80dd52d4f85be57a891a41e34be0d564e39b4af6f46b85339254a58b205fb7e10e7d0470ee73622493f28c08962118c23a1198467e72c4ae1cd482144b419247a5895975ea90d135e2a46ef7e5794a1551a447ff0a0d299b66a7f565cd86531f5e7af5408d85d877ce95b1df12b88b7d5954903a5296325ba478ba1e1a9d1f30a2d5052b2e2889bbd64f72c72bc71d8817288a2").unwrap());
        nodes[1].handle_onion_message(
                &keys_mgrs[0].1.get_node_id(Recipient::Node).unwrap(), &alice_to_bob_om);
        let bob_to_carol_om = nodes[1].next_onion_message_for_peer(
                keys_mgrs[2].1.get_node_id(Recipient::Node).unwrap()).unwrap();
-       assert_eq!(bob_to_carol_om.encode(), hex::decode("02b684babfd400c8dd48b367e9754b8021a3594a34dc94d7101776c7f6a86d0582055600029a77e8523162efa1f4208f4f2050cd5c386ddb6ce6d36235ea569d217ec52209fb85fdf7dbc4786c373eebdba0ddc184cfbe6da624f610e93f62c70f2c56be1090b926359969f040f932c03f53974db5656233bd60af375517d4323002937d784c2c88a564bcefe5c33d3fc21c26d94dfacab85e2e19685fd2ff4c543650958524439b6da68779459aee5ffc9dc543339acec73ff43be4c44ddcbe1c11d50e2411a67056ba9db7939d780f5a86123fdd3abd6f075f7a1d78ab7daf3a82798b7ec1e9f1345bc0d1e935098497067e2ae5a51ece396fcb3bb30871ad73aee51b2418b39f00c8e8e22be4a24f4b624e09cb0414dd46239de31c7be035f71e8da4f5a94d15b44061f46414d3f355069b5c5b874ba56704eb126148a22ec873407fe118972127e63ff80e682e410f297f23841777cec0517e933eaf49d7e34bd203266b42081b3a5193b51ccd34b41342bc67cf73523b741f5c012ba2572e9dda15fbe131a6ac2ff24dc2a7622d58b9f3553092cfae7fae3c8864d95f97aa49ec8edeff5d9f5782471160ee412d82ff6767030fc63eec6a93219a108cd41433834b26676a39846a944998796c79cd1cc460531b8ded659cedfd8aecefd91944f00476f1496daafb4ea6af3feacac1390ea510709783c2aa81a29de27f8959f6284f4684102b17815667cbb0645396ac7d542b878d90c42a1f7f00c4c4eedb2a22a219f38afadb4f1f562b6e000a94e75cc38f535b43a3c0384ccef127fde254a9033a317701c710b2b881065723486e3f4d3eea5e12f374a41565fe43fa137c1a252c2153dde055bb343344c65ad0529010ece29bbd405effbebfe3ba21382b94a60ac1a5ffa03f521792a67b30773cb42e862a8a02a8bbd41b842e115969c87d1ff1f8c7b5726b9f20772dd57fe6e4ea41f959a2a673ffad8e2f2a472c4c8564f3a5a47568dd75294b1c7180c500f7392a7da231b1fe9e525ea2d7251afe9ca52a17fe54a116cb57baca4f55b9b6de915924d644cba9dade4ccc01939d7935749c008bafc6d3ad01cd72341ce5ddf7a5d7d21cf0465ab7a3233433aef21f9acf2bfcdc5a8cc003adc4d82ac9d72b36eb74e05c9aa6ccf439ac92e6b84a3191f0764dd2a2e0b4cc3baa08782b232ad6ecd3ca6029bc08cc094aef3aebddcaddc30070cb6023a689641de86cfc6341c8817215a4650f844cd2ca60f2f10c6e44cfc5f23912684d4457bf4f599879d30b79bf12ef1ab8d34dddc15672b82e56169d4c770f0a2a7a960b1e8790773f5ff7fce92219808f16d061cc85e053971213676d28fb48925e9232b66533dbd938458eb2cc8358159df7a2a2e4cf87500ede2afb8ce963a845b98978edf26a6948d4932a6b95d022004556d25515fe158092ce9a913b4b4a493281393ca731e8d8e5a3449b9d888fc4e73ffcbb9c6d6d66e88e03cf6e81a0496ede6e4e4172b08c000601993af38f80c7f68c9d5fff9e0e215cff088285bf039ca731744efcb7825a272ca724517736b4890f47e306b200aa2543c363e2c9090bcf3cf56b5b86868a62471c7123a41740392fc1d5ab28da18dca66618e9af7b42b62b23aba907779e73ca03ec60e6ab9e0484b9cae6578e0fddb6386cb3468506bf6420298bf4a690947ab582255551d82487f271101c72e19e54872ab47eae144db66bc2f8194a666a5daec08d12822cb83a61946234f2dfdbd6ca7d8763e6818adee7b401fcdb1ac42f9df1ac5cc5ac131f2869013c8d6cd29d4c4e3d05bccd34ca83366d616296acf854fa05149bfd763a25b9938e96826a037fdcb85545439c76df6beed3bdbd01458f9cf984997cc4f0a7ac3cc3f5e1eeb59c09cadcf5a537f16e444149c8f17d4bdaef16c9fbabc5ef06eb0f0bf3a07a1beddfeacdaf1df5582d6dbd6bb808d6ab31bc22e5d7").unwrap());
+       assert_eq!(bob_to_carol_om.encode(), <Vec<u8>>::from_hex("02b684babfd400c8dd48b367e9754b8021a3594a34dc94d7101776c7f6a86d0582055600029a77e8523162efa1f4208f4f2050cd5c386ddb6ce6d36235ea569d217ec52209fb85fdf7dbc4786c373eebdba0ddc184cfbe6da624f610e93f62c70f2c56be1090b926359969f040f932c03f53974db5656233bd60af375517d4323002937d784c2c88a564bcefe5c33d3fc21c26d94dfacab85e2e19685fd2ff4c543650958524439b6da68779459aee5ffc9dc543339acec73ff43be4c44ddcbe1c11d50e2411a67056ba9db7939d780f5a86123fdd3abd6f075f7a1d78ab7daf3a82798b7ec1e9f1345bc0d1e935098497067e2ae5a51ece396fcb3bb30871ad73aee51b2418b39f00c8e8e22be4a24f4b624e09cb0414dd46239de31c7be035f71e8da4f5a94d15b44061f46414d3f355069b5c5b874ba56704eb126148a22ec873407fe118972127e63ff80e682e410f297f23841777cec0517e933eaf49d7e34bd203266b42081b3a5193b51ccd34b41342bc67cf73523b741f5c012ba2572e9dda15fbe131a6ac2ff24dc2a7622d58b9f3553092cfae7fae3c8864d95f97aa49ec8edeff5d9f5782471160ee412d82ff6767030fc63eec6a93219a108cd41433834b26676a39846a944998796c79cd1cc460531b8ded659cedfd8aecefd91944f00476f1496daafb4ea6af3feacac1390ea510709783c2aa81a29de27f8959f6284f4684102b17815667cbb0645396ac7d542b878d90c42a1f7f00c4c4eedb2a22a219f38afadb4f1f562b6e000a94e75cc38f535b43a3c0384ccef127fde254a9033a317701c710b2b881065723486e3f4d3eea5e12f374a41565fe43fa137c1a252c2153dde055bb343344c65ad0529010ece29bbd405effbebfe3ba21382b94a60ac1a5ffa03f521792a67b30773cb42e862a8a02a8bbd41b842e115969c87d1ff1f8c7b5726b9f20772dd57fe6e4ea41f959a2a673ffad8e2f2a472c4c8564f3a5a47568dd75294b1c7180c500f7392a7da231b1fe9e525ea2d7251afe9ca52a17fe54a116cb57baca4f55b9b6de915924d644cba9dade4ccc01939d7935749c008bafc6d3ad01cd72341ce5ddf7a5d7d21cf0465ab7a3233433aef21f9acf2bfcdc5a8cc003adc4d82ac9d72b36eb74e05c9aa6ccf439ac92e6b84a3191f0764dd2a2e0b4cc3baa08782b232ad6ecd3ca6029bc08cc094aef3aebddcaddc30070cb6023a689641de86cfc6341c8817215a4650f844cd2ca60f2f10c6e44cfc5f23912684d4457bf4f599879d30b79bf12ef1ab8d34dddc15672b82e56169d4c770f0a2a7a960b1e8790773f5ff7fce92219808f16d061cc85e053971213676d28fb48925e9232b66533dbd938458eb2cc8358159df7a2a2e4cf87500ede2afb8ce963a845b98978edf26a6948d4932a6b95d022004556d25515fe158092ce9a913b4b4a493281393ca731e8d8e5a3449b9d888fc4e73ffcbb9c6d6d66e88e03cf6e81a0496ede6e4e4172b08c000601993af38f80c7f68c9d5fff9e0e215cff088285bf039ca731744efcb7825a272ca724517736b4890f47e306b200aa2543c363e2c9090bcf3cf56b5b86868a62471c7123a41740392fc1d5ab28da18dca66618e9af7b42b62b23aba907779e73ca03ec60e6ab9e0484b9cae6578e0fddb6386cb3468506bf6420298bf4a690947ab582255551d82487f271101c72e19e54872ab47eae144db66bc2f8194a666a5daec08d12822cb83a61946234f2dfdbd6ca7d8763e6818adee7b401fcdb1ac42f9df1ac5cc5ac131f2869013c8d6cd29d4c4e3d05bccd34ca83366d616296acf854fa05149bfd763a25b9938e96826a037fdcb85545439c76df6beed3bdbd01458f9cf984997cc4f0a7ac3cc3f5e1eeb59c09cadcf5a537f16e444149c8f17d4bdaef16c9fbabc5ef06eb0f0bf3a07a1beddfeacdaf1df5582d6dbd6bb808d6ab31bc22e5d7").unwrap());
        nodes[2].handle_onion_message(
                &keys_mgrs[1].1.get_node_id(Recipient::Node).unwrap(), &bob_to_carol_om);
        let carol_to_dave_om = nodes[2].next_onion_message_for_peer(
                keys_mgrs[3].1.get_node_id(Recipient::Node).unwrap()).unwrap();
-       assert_eq!(carol_to_dave_om.encode(), hex::decode("025aaca62db7ce6b46386206ef9930daa32e979a35cb185a41cb951aa7d254b03c055600025550b2910294fa73bda99b9de9c851be9cbb481e23194a1743033630efba546b86e7d838d0f6e9cc0ed088dbf6889f0dceca3bfc745bd77d013a31311fa932a8bf1d28387d9ff521eabc651dee8f861fed609a68551145a451f017ec44978addeee97a423c08445531da488fd1ddc998e9cdbfcea59517b53fbf1833f0bbe6188dba6ca773a247220ec934010daca9cc185e1ceb136803469baac799e27a0d82abe53dc48a06a55d1f643885cc7894677dd20a4e4152577d1ba74b870b9279f065f9b340cedb3ca13b7df218e853e10ccd1b59c42a2acf93f489e170ee4373d30ab158b60fc20d3ba73a1f8c750951d69fb5b9321b968ddc8114936412346aff802df65516e1c09c51ef19849ff36c0199fd88c8bec301a30fef0c7cb497901c038611303f64e4174b5daf42832aa5586b84d2c9b95f382f4269a5d1bd4be898618dc78dfd451170f72ca16decac5b03e60702112e439cadd104fb3bbb3d5023c9b80823fdcd0a212a7e1aaa6eeb027adc7f8b3723031d135a09a979a4802788bb7861c6cc85501fb91137768b70aeab309b27b885686604ffc387004ac4f8c44b101c39bc0597ef7fd957f53fc5051f534b10eb3852100962b5e58254e5558689913c26ad6072ea41f5c5db10077cfc91101d4ae393be274c74297da5cc381cd88d54753aaa7df74b2f9da8d88a72bc9218fcd1f19e4ff4aace182312b9509c5175b6988f044c5756d232af02a451a02ca752f3c52747773acff6fd07d2032e6ce562a2c42105d106eba02d0b1904182cdc8c74875b082d4989d3a7e9f0e73de7c75d357f4af976c28c0b206c5e8123fc2391d078592d0d5ff686fd245c0a2de2e535b7cca99c0a37d432a8657393a9e3ca53eec1692159046ba52cb9bc97107349d8673f74cbc97e231f1108005c8d03e24ca813cea2294b39a7a493bcc062708f1f6cf0074e387e7d50e0666ce784ef4d31cb860f6cad767438d9ea5156ff0ae86e029e0247bf94df75ee0cda4f2006061455cb2eaff513d558863ae334cef7a3d45f55e7cc13153c6719e9901c1d4db6c03f643b69ea4860690305651794284d9e61eb848ccdf5a77794d376f0af62e46d4835acce6fd9eef5df73ebb8ea3bb48629766967f446e744ecc57ff3642c4aa1ccee9a2f72d5caa75fa05787d08b79408fce792485fdecdc25df34820fb061275d70b84ece540b0fc47b2453612be34f2b78133a64e812598fbe225fd85415f8ffe5340ce955b5fd9d67dd88c1c531dde298ed25f96df271558c812c26fa386966c76f03a6ebccbca49ac955916929bd42e134f982dde03f924c464be5fd1ba44f8dc4c3cbc8162755fd1d8f7dc044b15b1a796c53df7d8769bb167b2045b49cc71e08908796c92c16a235717cabc4bb9f60f8f66ff4fff1f9836388a99583acebdff4a7fb20f48eedcd1f4bdcc06ec8b48e35307df51d9bc81d38a94992dd135b30079e1f592da6e98dff496cb1a7776460a26b06395b176f585636ebdf7eab692b227a31d6979f5a6141292698e91346b6c806b90c7c6971e481559cae92ee8f4136f2226861f5c39ddd29bbdb118a35dece03f49a96804caea79a3dacfbf09d65f2611b5622de51d98e18151acb3bb84c09caaa0cc80edfa743a4679f37d6167618ce99e73362fa6f213409931762618a61f1738c071bba5afc1db24fe94afb70c40d731908ab9a505f76f57a7d40e708fd3df0efc5b7cbb2a7b75cd23449e09684a2f0e2bfa0d6176c35f96fe94d92fc9fa4103972781f81cb6e8df7dbeb0fc529c600d768bed3f08828b773d284f69e9a203459d88c12d6df7a75be2455fec128f07a497a2b2bf626cc6272d0419ca663e9dc66b8224227eb796f0246dcae9c5b0b6cfdbbd40c3245a610481c92047c968c9fc92c04b89cc41a0c15355a8f").unwrap());
+       assert_eq!(carol_to_dave_om.encode(), <Vec<u8>>::from_hex("025aaca62db7ce6b46386206ef9930daa32e979a35cb185a41cb951aa7d254b03c055600025550b2910294fa73bda99b9de9c851be9cbb481e23194a1743033630efba546b86e7d838d0f6e9cc0ed088dbf6889f0dceca3bfc745bd77d013a31311fa932a8bf1d28387d9ff521eabc651dee8f861fed609a68551145a451f017ec44978addeee97a423c08445531da488fd1ddc998e9cdbfcea59517b53fbf1833f0bbe6188dba6ca773a247220ec934010daca9cc185e1ceb136803469baac799e27a0d82abe53dc48a06a55d1f643885cc7894677dd20a4e4152577d1ba74b870b9279f065f9b340cedb3ca13b7df218e853e10ccd1b59c42a2acf93f489e170ee4373d30ab158b60fc20d3ba73a1f8c750951d69fb5b9321b968ddc8114936412346aff802df65516e1c09c51ef19849ff36c0199fd88c8bec301a30fef0c7cb497901c038611303f64e4174b5daf42832aa5586b84d2c9b95f382f4269a5d1bd4be898618dc78dfd451170f72ca16decac5b03e60702112e439cadd104fb3bbb3d5023c9b80823fdcd0a212a7e1aaa6eeb027adc7f8b3723031d135a09a979a4802788bb7861c6cc85501fb91137768b70aeab309b27b885686604ffc387004ac4f8c44b101c39bc0597ef7fd957f53fc5051f534b10eb3852100962b5e58254e5558689913c26ad6072ea41f5c5db10077cfc91101d4ae393be274c74297da5cc381cd88d54753aaa7df74b2f9da8d88a72bc9218fcd1f19e4ff4aace182312b9509c5175b6988f044c5756d232af02a451a02ca752f3c52747773acff6fd07d2032e6ce562a2c42105d106eba02d0b1904182cdc8c74875b082d4989d3a7e9f0e73de7c75d357f4af976c28c0b206c5e8123fc2391d078592d0d5ff686fd245c0a2de2e535b7cca99c0a37d432a8657393a9e3ca53eec1692159046ba52cb9bc97107349d8673f74cbc97e231f1108005c8d03e24ca813cea2294b39a7a493bcc062708f1f6cf0074e387e7d50e0666ce784ef4d31cb860f6cad767438d9ea5156ff0ae86e029e0247bf94df75ee0cda4f2006061455cb2eaff513d558863ae334cef7a3d45f55e7cc13153c6719e9901c1d4db6c03f643b69ea4860690305651794284d9e61eb848ccdf5a77794d376f0af62e46d4835acce6fd9eef5df73ebb8ea3bb48629766967f446e744ecc57ff3642c4aa1ccee9a2f72d5caa75fa05787d08b79408fce792485fdecdc25df34820fb061275d70b84ece540b0fc47b2453612be34f2b78133a64e812598fbe225fd85415f8ffe5340ce955b5fd9d67dd88c1c531dde298ed25f96df271558c812c26fa386966c76f03a6ebccbca49ac955916929bd42e134f982dde03f924c464be5fd1ba44f8dc4c3cbc8162755fd1d8f7dc044b15b1a796c53df7d8769bb167b2045b49cc71e08908796c92c16a235717cabc4bb9f60f8f66ff4fff1f9836388a99583acebdff4a7fb20f48eedcd1f4bdcc06ec8b48e35307df51d9bc81d38a94992dd135b30079e1f592da6e98dff496cb1a7776460a26b06395b176f585636ebdf7eab692b227a31d6979f5a6141292698e91346b6c806b90c7c6971e481559cae92ee8f4136f2226861f5c39ddd29bbdb118a35dece03f49a96804caea79a3dacfbf09d65f2611b5622de51d98e18151acb3bb84c09caaa0cc80edfa743a4679f37d6167618ce99e73362fa6f213409931762618a61f1738c071bba5afc1db24fe94afb70c40d731908ab9a505f76f57a7d40e708fd3df0efc5b7cbb2a7b75cd23449e09684a2f0e2bfa0d6176c35f96fe94d92fc9fa4103972781f81cb6e8df7dbeb0fc529c600d768bed3f08828b773d284f69e9a203459d88c12d6df7a75be2455fec128f07a497a2b2bf626cc6272d0419ca663e9dc66b8224227eb796f0246dcae9c5b0b6cfdbbd40c3245a610481c92047c968c9fc92c04b89cc41a0c15355a8f").unwrap());
        // Dave handles the onion message but he'll log that he errored while decoding the hop data
        // because he sees it as an empty onion message (the only contents of the sender's OM is "hello"
        // with TLV type 1, which Dave ignores because (1) it's odd and he can't understand it and (2) LDK
index cf0f9e086b5c41a12c2e9b1b5e27f3a03949fae7..0e68d09143c00d251c69ee251162960b05ec3bed 100644 (file)
@@ -59,6 +59,7 @@ use crate::prelude::*;
 /// ```
 /// # extern crate bitcoin;
 /// # use bitcoin::hashes::_export::_core::time::Duration;
+/// # use bitcoin::hashes::hex::FromHex;
 /// # use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
 /// # use lightning::blinded_path::BlindedPath;
 /// # use lightning::sign::KeysManager;
@@ -82,7 +83,7 @@ use crate::prelude::*;
 /// # let time = Duration::from_secs(123456);
 /// # let keys_manager = KeysManager::new(&seed, time.as_secs(), time.subsec_nanos());
 /// # let logger = Arc::new(FakeLogger {});
-/// # let node_secret = SecretKey::from_slice(&hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap();
+/// # let node_secret = SecretKey::from_slice(&<Vec<u8>>::from_hex("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap();
 /// # let secp_ctx = Secp256k1::new();
 /// # let hop_node_id1 = PublicKey::from_secret_key(&secp_ctx, &node_secret);
 /// # let (hop_node_id2, hop_node_id3, hop_node_id4) = (hop_node_id1, hop_node_id1, hop_node_id1);
@@ -406,7 +407,7 @@ where
                let blinding_factor = {
                        let mut hmac = HmacEngine::<Sha256>::new(b"blinded_node_id");
                        hmac.input(control_tlvs_ss.as_ref());
-                       Hmac::from_engine(hmac).into_inner()
+                       Hmac::from_engine(hmac).to_byte_array()
                };
                match node_signer.ecdh(Recipient::Node, &msg.onion_routing_packet.public_key,
                        Some(&Scalar::from_be_bytes(blinding_factor).unwrap()))
index 7791737d9e2f70513fb7a70049f6bca8857b373b..f556fabad0cbcdc9f3d94924bd236080c692c865 100644 (file)
@@ -18,8 +18,6 @@ use bitcoin::secp256k1;
 
 use bitcoin::hashes::sha256d::Hash as Sha256dHash;
 use bitcoin::hashes::Hash;
-use bitcoin::hashes::hex::FromHex;
-
 use bitcoin::network::constants::Network;
 
 use crate::events::{MessageSendEvent, MessageSendEventsProvider};
@@ -81,6 +79,11 @@ impl NodeId {
                &self.0
        }
 
+       /// Get the public key as an array from this NodeId
+       pub fn as_array(&self) -> &[u8; PUBLIC_KEY_SIZE] {
+               &self.0
+       }
+
        /// Get the public key from this NodeId
        pub fn as_pubkey(&self) -> Result<PublicKey, secp256k1::Error> {
                PublicKey::from_slice(&self.0)
@@ -154,10 +157,10 @@ impl TryFrom<NodeId> for PublicKey {
 }
 
 impl FromStr for NodeId {
-       type Err = bitcoin::hashes::hex::Error;
+       type Err = hex::parse::HexToArrayError;
 
        fn from_str(s: &str) -> Result<Self, Self::Err> {
-               let data: [u8; PUBLIC_KEY_SIZE] = FromHex::from_hex(s)?;
+               let data: [u8; PUBLIC_KEY_SIZE] = hex::FromHex::from_hex(s)?;
                Ok(NodeId(data))
        }
 }
@@ -2094,13 +2097,11 @@ pub(crate) mod tests {
 
        use bitcoin::hashes::sha256d::Hash as Sha256dHash;
        use bitcoin::hashes::Hash;
+       use bitcoin::hashes::hex::FromHex;
        use bitcoin::network::constants::Network;
        use bitcoin::blockdata::constants::ChainHash;
-       use bitcoin::blockdata::script::Script;
+       use bitcoin::blockdata::script::ScriptBuf;
        use bitcoin::blockdata::transaction::TxOut;
-
-       use hex;
-
        use bitcoin::secp256k1::{PublicKey, SecretKey};
        use bitcoin::secp256k1::{All, Secp256k1};
 
@@ -2129,7 +2130,7 @@ pub(crate) mod tests {
        fn request_full_sync_finite_times() {
                let network_graph = create_network_graph();
                let (secp_ctx, gossip_sync) = create_gossip_sync(&network_graph);
-               let node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap()[..]).unwrap());
+               let node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&<Vec<u8>>::from_hex("0202020202020202020202020202020202020202020202020202020202020202").unwrap()[..]).unwrap());
 
                assert!(gossip_sync.should_request_full_sync(&node_id));
                assert!(gossip_sync.should_request_full_sync(&node_id));
@@ -2186,7 +2187,7 @@ pub(crate) mod tests {
                }
        }
 
-       pub(crate) fn get_channel_script(secp_ctx: &Secp256k1<secp256k1::All>) -> Script {
+       pub(crate) fn get_channel_script(secp_ctx: &Secp256k1<secp256k1::All>) -> ScriptBuf {
                let node_1_btckey = SecretKey::from_slice(&[40; 32]).unwrap();
                let node_2_btckey = SecretKey::from_slice(&[39; 32]).unwrap();
                make_funding_redeemscript(&PublicKey::from_secret_key(secp_ctx, &node_1_btckey),
@@ -2243,7 +2244,7 @@ pub(crate) mod tests {
                        Err(_) => panic!()
                };
 
-               let fake_msghash = hash_to_message!(&zero_hash);
+               let fake_msghash = hash_to_message!(zero_hash.as_byte_array());
                match gossip_sync.handle_node_announcement(
                        &NodeAnnouncement {
                                signature: secp_ctx.sign_ecdsa(&fake_msghash, node_1_privkey),
@@ -2505,7 +2506,7 @@ pub(crate) mod tests {
                        unsigned_channel_update.timestamp += 500;
                }, node_1_privkey, &secp_ctx);
                let zero_hash = Sha256dHash::hash(&[0; 32]);
-               let fake_msghash = hash_to_message!(&zero_hash);
+               let fake_msghash = hash_to_message!(zero_hash.as_byte_array());
                invalid_sig_channel_update.signature = secp_ctx.sign_ecdsa(&fake_msghash, node_1_privkey);
                match gossip_sync.handle_channel_update(&invalid_sig_channel_update) {
                        Ok(_) => panic!(),
@@ -3344,16 +3345,16 @@ pub(crate) mod tests {
                assert_eq!(chan_update_info, read_chan_update_info);
 
                // Check the serialization hasn't changed.
-               let legacy_chan_update_info_with_some: Vec<u8> = hex::decode("340004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c0100").unwrap();
+               let legacy_chan_update_info_with_some: Vec<u8> = <Vec<u8>>::from_hex("340004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c0100").unwrap();
                assert_eq!(encoded_chan_update_info, legacy_chan_update_info_with_some);
 
                // Check we fail if htlc_maximum_msat is not present in either the ChannelUpdateInfo itself
                // or the ChannelUpdate enclosed with `last_update_message`.
-               let legacy_chan_update_info_with_some_and_fail_update: Vec<u8> = hex::decode("b40004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c8181d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f00083a840000034d013413a70000009000000000000f42400000271000000014").unwrap();
+               let legacy_chan_update_info_with_some_and_fail_update: Vec<u8> = <Vec<u8>>::from_hex("b40004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c8181d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f00083a840000034d013413a70000009000000000000f42400000271000000014").unwrap();
                let read_chan_update_info_res: Result<ChannelUpdateInfo, crate::ln::msgs::DecodeError> = crate::util::ser::Readable::read(&mut legacy_chan_update_info_with_some_and_fail_update.as_slice());
                assert!(read_chan_update_info_res.is_err());
 
-               let legacy_chan_update_info_with_none: Vec<u8> = hex::decode("2c0004000000170201010402002a060800000000000004d20801000a0d0c00040000000902040000000a0c0100").unwrap();
+               let legacy_chan_update_info_with_none: Vec<u8> = <Vec<u8>>::from_hex("2c0004000000170201010402002a060800000000000004d20801000a0d0c00040000000902040000000a0c0100").unwrap();
                let read_chan_update_info_res: Result<ChannelUpdateInfo, crate::ln::msgs::DecodeError> = crate::util::ser::Readable::read(&mut legacy_chan_update_info_with_none.as_slice());
                assert!(read_chan_update_info_res.is_err());
 
@@ -3395,18 +3396,18 @@ pub(crate) mod tests {
                assert_eq!(chan_info_some_updates, read_chan_info);
 
                // Check the serialization hasn't changed.
-               let legacy_chan_info_with_some: Vec<u8> = hex::decode("ca00020000010800000000000156660221027f921585f2ac0c7c70e36110adecfd8fd14b8a99bfb3d000a283fcac358fce88043636340004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c010006210355f8d2238a322d16b602bd0ceaad5b01019fb055971eaadcc9b29226a4da6c23083636340004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c01000a01000c0100").unwrap();
+               let legacy_chan_info_with_some: Vec<u8> = <Vec<u8>>::from_hex("ca00020000010800000000000156660221027f921585f2ac0c7c70e36110adecfd8fd14b8a99bfb3d000a283fcac358fce88043636340004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c010006210355f8d2238a322d16b602bd0ceaad5b01019fb055971eaadcc9b29226a4da6c23083636340004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c01000a01000c0100").unwrap();
                assert_eq!(encoded_chan_info, legacy_chan_info_with_some);
 
                // Check we can decode legacy ChannelInfo, even if the `two_to_one` / `one_to_two` /
                // `last_update_message` fields fail to decode due to missing htlc_maximum_msat.
-               let legacy_chan_info_with_some_and_fail_update = hex::decode("fd01ca00020000010800000000000156660221027f921585f2ac0c7c70e36110adecfd8fd14b8a99bfb3d000a283fcac358fce8804b6b6b40004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c8181d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f00083a840000034d013413a70000009000000000000f4240000027100000001406210355f8d2238a322d16b602bd0ceaad5b01019fb055971eaadcc9b29226a4da6c2308b6b6b40004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c8181d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f00083a840000034d013413a70000009000000000000f424000002710000000140a01000c0100").unwrap();
+               let legacy_chan_info_with_some_and_fail_update = <Vec<u8>>::from_hex("fd01ca00020000010800000000000156660221027f921585f2ac0c7c70e36110adecfd8fd14b8a99bfb3d000a283fcac358fce8804b6b6b40004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c8181d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f00083a840000034d013413a70000009000000000000f4240000027100000001406210355f8d2238a322d16b602bd0ceaad5b01019fb055971eaadcc9b29226a4da6c2308b6b6b40004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c8181d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f00083a840000034d013413a70000009000000000000f424000002710000000140a01000c0100").unwrap();
                let read_chan_info: ChannelInfo = crate::util::ser::Readable::read(&mut legacy_chan_info_with_some_and_fail_update.as_slice()).unwrap();
                assert_eq!(read_chan_info.announcement_received_time, 87654);
                assert_eq!(read_chan_info.one_to_two, None);
                assert_eq!(read_chan_info.two_to_one, None);
 
-               let legacy_chan_info_with_none: Vec<u8> = hex::decode("ba00020000010800000000000156660221027f921585f2ac0c7c70e36110adecfd8fd14b8a99bfb3d000a283fcac358fce88042e2e2c0004000000170201010402002a060800000000000004d20801000a0d0c00040000000902040000000a0c010006210355f8d2238a322d16b602bd0ceaad5b01019fb055971eaadcc9b29226a4da6c23082e2e2c0004000000170201010402002a060800000000000004d20801000a0d0c00040000000902040000000a0c01000a01000c0100").unwrap();
+               let legacy_chan_info_with_none: Vec<u8> = <Vec<u8>>::from_hex("ba00020000010800000000000156660221027f921585f2ac0c7c70e36110adecfd8fd14b8a99bfb3d000a283fcac358fce88042e2e2c0004000000170201010402002a060800000000000004d20801000a0d0c00040000000902040000000a0c010006210355f8d2238a322d16b602bd0ceaad5b01019fb055971eaadcc9b29226a4da6c23082e2e2c0004000000170201010402002a060800000000000004d20801000a0d0c00040000000902040000000a0c01000a01000c0100").unwrap();
                let read_chan_info: ChannelInfo = crate::util::ser::Readable::read(&mut legacy_chan_info_with_none.as_slice()).unwrap();
                assert_eq!(read_chan_info.announcement_received_time, 87654);
                assert_eq!(read_chan_info.one_to_two, None);
@@ -3416,7 +3417,7 @@ pub(crate) mod tests {
        #[test]
        fn node_info_is_readable() {
                // 1. Check we can read a valid NodeAnnouncementInfo and fail on an invalid one
-               let announcement_message = hex::decode("d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a000122013413a7031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f2020201010101010101010101010101010101010101010101010101010101010101010000701fffefdfc2607").unwrap();
+               let announcement_message = <Vec<u8>>::from_hex("d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a000122013413a7031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f2020201010101010101010101010101010101010101010101010101010101010101010000701fffefdfc2607").unwrap();
                let announcement_message = NodeAnnouncement::read(&mut announcement_message.as_slice()).unwrap();
                let valid_node_ann_info = NodeAnnouncementInfo {
                        features: channelmanager::provided_node_features(&UserConfig::default()),
@@ -3432,7 +3433,7 @@ pub(crate) mod tests {
                assert_eq!(read_valid_node_ann_info, valid_node_ann_info);
                assert_eq!(read_valid_node_ann_info.addresses().len(), 1);
 
-               let encoded_invalid_node_ann_info = hex::decode("3f0009000788a000080a51a20204000000000403000000062000000000000000000000000000000000000000000000000000000000000000000a0505014004d2").unwrap();
+               let encoded_invalid_node_ann_info = <Vec<u8>>::from_hex("3f0009000788a000080a51a20204000000000403000000062000000000000000000000000000000000000000000000000000000000000000000a0505014004d2").unwrap();
                let read_invalid_node_ann_info_res = NodeAnnouncementInfo::read(&mut encoded_invalid_node_ann_info.as_slice());
                assert!(read_invalid_node_ann_info_res.is_err());
 
@@ -3447,14 +3448,14 @@ pub(crate) mod tests {
                let read_valid_node_info = NodeInfo::read(&mut encoded_valid_node_info.as_slice()).unwrap();
                assert_eq!(read_valid_node_info, valid_node_info);
 
-               let encoded_invalid_node_info_hex = hex::decode("4402403f0009000788a000080a51a20204000000000403000000062000000000000000000000000000000000000000000000000000000000000000000a0505014004d20400").unwrap();
+               let encoded_invalid_node_info_hex = <Vec<u8>>::from_hex("4402403f0009000788a000080a51a20204000000000403000000062000000000000000000000000000000000000000000000000000000000000000000a0505014004d20400").unwrap();
                let read_invalid_node_info = NodeInfo::read(&mut encoded_invalid_node_info_hex.as_slice()).unwrap();
                assert_eq!(read_invalid_node_info.announcement_info, None);
        }
 
        #[test]
        fn test_node_info_keeps_compatibility() {
-               let old_ann_info_with_addresses = hex::decode("3f0009000708a000080a51220204000000000403000000062000000000000000000000000000000000000000000000000000000000000000000a0505014104d2").unwrap();
+               let old_ann_info_with_addresses = <Vec<u8>>::from_hex("3f0009000708a000080a51220204000000000403000000062000000000000000000000000000000000000000000000000000000000000000000a0505014104d2").unwrap();
                let ann_info_with_addresses = NodeAnnouncementInfo::read(&mut old_ann_info_with_addresses.as_slice())
                                .expect("to be able to read an old NodeAnnouncementInfo with addresses");
                // This serialized info has an address field but no announcement_message, therefore the addresses returned by our function will still be empty
index 8e45a8779620c2fc8247c8bce2b13a3620c18404..a2d9f51a38e6a4edc2a8e64c35798c5184e1c5ca 100644 (file)
@@ -68,7 +68,7 @@ impl< G: Deref<Target = NetworkGraph<L>>, L: Deref, S: Deref, SP: Sized, Sc: Sco
        ) -> Result<Route, LightningError> {
                let random_seed_bytes = {
                        let mut locked_random_seed_bytes = self.random_seed_bytes.lock().unwrap();
-                       *locked_random_seed_bytes = Sha256::hash(&*locked_random_seed_bytes).into_inner();
+                       *locked_random_seed_bytes = Sha256::hash(&*locked_random_seed_bytes).to_byte_array();
                        *locked_random_seed_bytes
                };
                find_route(
@@ -2835,9 +2835,7 @@ mod tests {
        use bitcoin::blockdata::script::Builder;
        use bitcoin::blockdata::opcodes;
        use bitcoin::blockdata::transaction::TxOut;
-
-       use hex;
-
+       use bitcoin::hashes::hex::FromHex;
        use bitcoin::secp256k1::{PublicKey,SecretKey};
        use bitcoin::secp256k1::Secp256k1;
 
@@ -3808,7 +3806,7 @@ mod tests {
                let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph();
                let (_, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
 
-               let non_announced_privkey = SecretKey::from_slice(&hex::decode(format!("{:02x}", 0xf0).repeat(32)).unwrap()[..]).unwrap();
+               let non_announced_privkey = SecretKey::from_slice(&<Vec<u8>>::from_hex(&format!("{:02x}", 0xf0).repeat(32)).unwrap()[..]).unwrap();
                let non_announced_pubkey = PublicKey::from_secret_key(&secp_ctx, &non_announced_privkey);
 
                let last_hops = multi_hop_last_hops_hint([nodes[2], non_announced_pubkey]);
@@ -4089,9 +4087,9 @@ mod tests {
        }
 
        fn do_unannounced_path_test(last_hop_htlc_max: Option<u64>, last_hop_fee_prop: u32, outbound_capacity_msat: u64, route_val: u64) -> Result<Route, LightningError> {
-               let source_node_id = PublicKey::from_secret_key(&Secp256k1::new(), &SecretKey::from_slice(&hex::decode(format!("{:02}", 41).repeat(32)).unwrap()[..]).unwrap());
-               let middle_node_id = PublicKey::from_secret_key(&Secp256k1::new(), &SecretKey::from_slice(&hex::decode(format!("{:02}", 42).repeat(32)).unwrap()[..]).unwrap());
-               let target_node_id = PublicKey::from_secret_key(&Secp256k1::new(), &SecretKey::from_slice(&hex::decode(format!("{:02}", 43).repeat(32)).unwrap()[..]).unwrap());
+               let source_node_id = PublicKey::from_secret_key(&Secp256k1::new(), &SecretKey::from_slice(&<Vec<u8>>::from_hex(&format!("{:02}", 41).repeat(32)).unwrap()[..]).unwrap());
+               let middle_node_id = PublicKey::from_secret_key(&Secp256k1::new(), &SecretKey::from_slice(&<Vec<u8>>::from_hex(&format!("{:02}", 42).repeat(32)).unwrap()[..]).unwrap());
+               let target_node_id = PublicKey::from_secret_key(&Secp256k1::new(), &SecretKey::from_slice(&<Vec<u8>>::from_hex(&format!("{:02}", 43).repeat(32)).unwrap()[..]).unwrap());
 
                // If we specify a channel to a middle hop, that overrides our local channel view and that gets used
                let last_hops = RouteHint(vec![RouteHintHop {
@@ -4126,8 +4124,8 @@ mod tests {
                // hints.
                let route = do_unannounced_path_test(None, 1, 2000000, 1000000).unwrap();
 
-               let middle_node_id = PublicKey::from_secret_key(&Secp256k1::new(), &SecretKey::from_slice(&hex::decode(format!("{:02}", 42).repeat(32)).unwrap()[..]).unwrap());
-               let target_node_id = PublicKey::from_secret_key(&Secp256k1::new(), &SecretKey::from_slice(&hex::decode(format!("{:02}", 43).repeat(32)).unwrap()[..]).unwrap());
+               let middle_node_id = PublicKey::from_secret_key(&Secp256k1::new(), &SecretKey::from_slice(&<Vec<u8>>::from_hex(&format!("{:02}", 42).repeat(32)).unwrap()[..]).unwrap());
+               let target_node_id = PublicKey::from_secret_key(&Secp256k1::new(), &SecretKey::from_slice(&<Vec<u8>>::from_hex(&format!("{:02}", 43).repeat(32)).unwrap()[..]).unwrap());
                assert_eq!(route.paths[0].hops.len(), 2);
 
                assert_eq!(route.paths[0].hops[0].pubkey, middle_node_id);
@@ -6187,17 +6185,17 @@ mod tests {
                let route = Route {
                        paths: vec![Path { hops: vec![
                                RouteHop {
-                                       pubkey: PublicKey::from_slice(&hex::decode("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]).unwrap(),
+                                       pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]).unwrap(),
                                        channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
                                        short_channel_id: 0, fee_msat: 100, cltv_expiry_delta: 0, maybe_announced_channel: true,
                                },
                                RouteHop {
-                                       pubkey: PublicKey::from_slice(&hex::decode("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c").unwrap()[..]).unwrap(),
+                                       pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c").unwrap()[..]).unwrap(),
                                        channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
                                        short_channel_id: 0, fee_msat: 150, cltv_expiry_delta: 0, maybe_announced_channel: true,
                                },
                                RouteHop {
-                                       pubkey: PublicKey::from_slice(&hex::decode("027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007").unwrap()[..]).unwrap(),
+                                       pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007").unwrap()[..]).unwrap(),
                                        channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
                                        short_channel_id: 0, fee_msat: 225, cltv_expiry_delta: 0, maybe_announced_channel: true,
                                },
@@ -6214,23 +6212,23 @@ mod tests {
                let route = Route {
                        paths: vec![Path { hops: vec![
                                RouteHop {
-                                       pubkey: PublicKey::from_slice(&hex::decode("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]).unwrap(),
+                                       pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]).unwrap(),
                                        channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
                                        short_channel_id: 0, fee_msat: 100, cltv_expiry_delta: 0, maybe_announced_channel: true,
                                },
                                RouteHop {
-                                       pubkey: PublicKey::from_slice(&hex::decode("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c").unwrap()[..]).unwrap(),
+                                       pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c").unwrap()[..]).unwrap(),
                                        channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
                                        short_channel_id: 0, fee_msat: 150, cltv_expiry_delta: 0, maybe_announced_channel: true,
                                },
                        ], blinded_tail: None }, Path { hops: vec![
                                RouteHop {
-                                       pubkey: PublicKey::from_slice(&hex::decode("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]).unwrap(),
+                                       pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]).unwrap(),
                                        channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
                                        short_channel_id: 0, fee_msat: 100, cltv_expiry_delta: 0, maybe_announced_channel: true,
                                },
                                RouteHop {
-                                       pubkey: PublicKey::from_slice(&hex::decode("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c").unwrap()[..]).unwrap(),
+                                       pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c").unwrap()[..]).unwrap(),
                                        channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
                                        short_channel_id: 0, fee_msat: 150, cltv_expiry_delta: 0, maybe_announced_channel: true,
                                },
index f4048f58d4dc9ef5478b43b9922c8082754938c4..3c0ef85fd7e3815696a669bc34203d411535f337 100644 (file)
@@ -17,10 +17,8 @@ use crate::util::ser::Writeable;
 use bitcoin::blockdata::constants::ChainHash;
 use bitcoin::hashes::sha256d::Hash as Sha256dHash;
 use bitcoin::hashes::Hash;
+use bitcoin::hashes::hex::FromHex;
 use bitcoin::network::constants::Network;
-
-use hex;
-
 use bitcoin::secp256k1::{PublicKey,SecretKey};
 use bitcoin::secp256k1::{Secp256k1, All};
 
@@ -107,12 +105,12 @@ pub(super) fn update_channel(
 
 pub(super) fn get_nodes(secp_ctx: &Secp256k1<All>) -> (SecretKey, PublicKey, Vec<SecretKey>, Vec<PublicKey>) {
        let privkeys: Vec<SecretKey> = (2..22).map(|i| {
-               SecretKey::from_slice(&hex::decode(format!("{:02x}", i).repeat(32)).unwrap()[..]).unwrap()
+               SecretKey::from_slice(&<Vec<u8>>::from_hex(&format!("{:02x}", i).repeat(32)).unwrap()[..]).unwrap()
        }).collect();
 
        let pubkeys = privkeys.iter().map(|secret| PublicKey::from_secret_key(&secp_ctx, secret)).collect();
 
-       let our_privkey = SecretKey::from_slice(&hex::decode("01".repeat(32)).unwrap()[..]).unwrap();
+       let our_privkey = SecretKey::from_slice(&<Vec<u8>>::from_hex(&"01".repeat(32)).unwrap()[..]).unwrap();
        let our_id = PublicKey::from_secret_key(&secp_ctx, &our_privkey);
 
        (our_privkey, our_id, privkeys, pubkeys)
index 164974672380b1272ffe23cc0bbb2d6ea26347c9..e190d4258ae4c6b862ad13135eaf1d656fab32f9 100644 (file)
 
 use bitcoin::TxOut;
 use bitcoin::blockdata::constants::ChainHash;
-use bitcoin::hashes::hex::ToHex;
+
+use hex::DisplayHex;
 
 use crate::events::MessageSendEvent;
 use crate::ln::chan_utils::make_funding_redeemscript_from_slices;
 use crate::ln::msgs::{self, LightningError, ErrorAction};
 use crate::routing::gossip::{NetworkGraph, NodeId, P2PGossipSync};
 use crate::util::logger::{Level, Logger};
-use crate::util::ser::Writeable;
 
 use crate::prelude::*;
 
@@ -460,11 +460,11 @@ impl PendingChecks {
                        match res {
                                Ok(TxOut { value, script_pubkey }) => {
                                        let expected_script =
-                                               make_funding_redeemscript_from_slices(msg.bitcoin_key_1.as_slice(), msg.bitcoin_key_2.as_slice()).to_v0_p2wsh();
+                                               make_funding_redeemscript_from_slices(msg.bitcoin_key_1.as_array(), msg.bitcoin_key_2.as_array()).to_v0_p2wsh();
                                        if script_pubkey != expected_script {
                                                return Err(LightningError{
                                                        err: format!("Channel announcement key ({}) didn't match on-chain script ({})",
-                                                               expected_script.to_hex(), script_pubkey.to_hex()),
+                                                               expected_script.to_hex_string(), script_pubkey.to_hex_string()),
                                                        action: ErrorAction::IgnoreError
                                                });
                                        }
@@ -473,7 +473,7 @@ impl PendingChecks {
                                Err(UtxoLookupError::UnknownChain) => {
                                        Err(LightningError {
                                                err: format!("Channel announced on an unknown chain ({})",
-                                                       msg.chain_hash.encode().to_hex()),
+                                                       msg.chain_hash.to_bytes().as_hex()),
                                                action: ErrorAction::IgnoreError
                                        })
                                },
@@ -578,7 +578,7 @@ mod tests {
        }
 
        fn get_test_objects() -> (msgs::ChannelAnnouncement, TestChainSource,
-               NetworkGraph<Box<TestLogger>>, bitcoin::Script, msgs::NodeAnnouncement,
+               NetworkGraph<Box<TestLogger>>, bitcoin::ScriptBuf, msgs::NodeAnnouncement,
                msgs::NodeAnnouncement, msgs::ChannelUpdate, msgs::ChannelUpdate, msgs::ChannelUpdate)
        {
                let secp_ctx = Secp256k1::new();
@@ -661,7 +661,7 @@ mod tests {
                assert!(network_graph.read_only().channels().get(&valid_announcement.contents.short_channel_id).is_none());
 
                future.resolve_without_forwarding(&network_graph,
-                       Ok(TxOut { value: 1_000_000, script_pubkey: bitcoin::Script::new() }));
+                       Ok(TxOut { value: 1_000_000, script_pubkey: bitcoin::ScriptBuf::new() }));
                assert!(network_graph.read_only().channels().get(&valid_announcement.contents.short_channel_id).is_none());
        }
 
index 5912b7b84e16e393daffb3a144c6b12ee2e4331b..bc15a3a7662c0dd12b06aab8b1927ee2f6e2eab3 100644 (file)
 //! The provided output descriptors follow a custom LDK data format and are currently not fully
 //! compatible with Bitcoin Core output descriptors.
 
-use bitcoin::blockdata::transaction::{Transaction, TxOut, TxIn, EcdsaSighashType};
-use bitcoin::blockdata::script::{Script, Builder};
+use bitcoin::blockdata::locktime::absolute::LockTime;
+use bitcoin::blockdata::transaction::{Transaction, TxOut, TxIn};
+use bitcoin::blockdata::script::{Script, ScriptBuf, Builder};
 use bitcoin::blockdata::opcodes;
+use bitcoin::ecdsa::Signature as EcdsaSignature;
 use bitcoin::network::constants::Network;
 use bitcoin::psbt::PartiallySignedTransaction;
-use bitcoin::util::bip32::{ExtendedPrivKey, ExtendedPubKey, ChildNumber};
-use bitcoin::util::sighash;
+use bitcoin::bip32::{ExtendedPrivKey, ExtendedPubKey, ChildNumber};
+use bitcoin::sighash;
+use bitcoin::sighash::EcdsaSighashType;
 
 use bitcoin::bech32::u5;
 use bitcoin::hashes::{Hash, HashEngine};
@@ -30,7 +33,7 @@ use bitcoin::secp256k1::{KeyPair, PublicKey, Scalar, Secp256k1, SecretKey, Signi
 use bitcoin::secp256k1::ecdh::SharedSecret;
 use bitcoin::secp256k1::ecdsa::{RecoverableSignature, Signature};
 use bitcoin::secp256k1::schnorr;
-use bitcoin::{PackedLockTime, secp256k1, Sequence, Witness, Txid};
+use bitcoin::{secp256k1, Sequence, Witness, Txid};
 
 use crate::util::transaction_utils;
 use crate::util::crypto::{hkdf_extract_expand_twice, sign, sign_with_aux_rand};
@@ -93,7 +96,7 @@ impl DelayedPaymentOutputDescriptor {
        /// shorter.
        // Calculated as 1 byte length + 73 byte signature, 1 byte empty vec push, 1 byte length plus
        // redeemscript push length.
-       pub const MAX_WITNESS_LENGTH: usize = 1 + 73 + 1 + chan_utils::REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH + 1;
+       pub const MAX_WITNESS_LENGTH: u64 = 1 + 73 + 1 + chan_utils::REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH as u64 + 1;
 }
 
 impl_writeable_tlv_based!(DelayedPaymentOutputDescriptor, {
@@ -137,7 +140,7 @@ impl StaticPaymentOutputDescriptor {
        ///
        /// Note that this will only return `Some` for [`StaticPaymentOutputDescriptor`]s that
        /// originated from an anchor outputs channel, as they take the form of a P2WSH script.
-       pub fn witness_script(&self) -> Option<Script> {
+       pub fn witness_script(&self) -> Option<ScriptBuf> {
                self.channel_transaction_parameters.as_ref()
                        .and_then(|channel_params|
                                 if channel_params.channel_type_features.supports_anchors_zero_fee_htlc_tx() {
@@ -152,7 +155,7 @@ impl StaticPaymentOutputDescriptor {
        /// The maximum length a well-formed witness spending one of these should have.
        /// Note: If you have the grind_signatures feature enabled, this will be at least 1 byte
        /// shorter.
-       pub fn max_witness_length(&self) -> usize {
+       pub fn max_witness_length(&self) -> u64 {
                if self.channel_transaction_parameters.as_ref()
                        .map(|channel_params| channel_params.channel_type_features.supports_anchors_zero_fee_htlc_tx())
                        .unwrap_or(false)
@@ -162,7 +165,7 @@ impl StaticPaymentOutputDescriptor {
                        1 /* num witness items */ + 1 /* sig push */ + 73 /* sig including sighash flag */ +
                                1 /* witness script push */ + witness_script_weight
                } else {
-                       P2WPKH_WITNESS_WEIGHT as usize
+                       P2WPKH_WITNESS_WEIGHT
                }
        }
 }
@@ -319,7 +322,7 @@ impl SpendableOutputDescriptor {
        /// does not match the one we can spend.
        ///
        /// We do not enforce that outputs meet the dust limit or that any output scripts are standard.
-       pub fn create_spendable_outputs_psbt(descriptors: &[&SpendableOutputDescriptor], outputs: Vec<TxOut>, change_destination_script: Script, feerate_sat_per_1000_weight: u32, locktime: Option<PackedLockTime>) -> Result<(PartiallySignedTransaction, usize), ()> {
+       pub fn create_spendable_outputs_psbt(descriptors: &[&SpendableOutputDescriptor], outputs: Vec<TxOut>, change_destination_script: ScriptBuf, feerate_sat_per_1000_weight: u32, locktime: Option<LockTime>) -> Result<(PartiallySignedTransaction, u64), ()> {
                let mut input = Vec::with_capacity(descriptors.len());
                let mut input_value = 0;
                let mut witness_weight = 0;
@@ -339,7 +342,7 @@ impl SpendableOutputDescriptor {
                                                };
                                        input.push(TxIn {
                                                previous_output: descriptor.outpoint.into_bitcoin_outpoint(),
-                                               script_sig: Script::new(),
+                                               script_sig: ScriptBuf::new(),
                                                sequence,
                                                witness: Witness::new(),
                                        });
@@ -352,7 +355,7 @@ impl SpendableOutputDescriptor {
                                        if !output_set.insert(descriptor.outpoint) { return Err(()); }
                                        input.push(TxIn {
                                                previous_output: descriptor.outpoint.into_bitcoin_outpoint(),
-                                               script_sig: Script::new(),
+                                               script_sig: ScriptBuf::new(),
                                                sequence: Sequence(descriptor.to_self_delay as u32),
                                                witness: Witness::new(),
                                        });
@@ -365,7 +368,7 @@ impl SpendableOutputDescriptor {
                                        if !output_set.insert(*outpoint) { return Err(()); }
                                        input.push(TxIn {
                                                previous_output: outpoint.into_bitcoin_outpoint(),
-                                               script_sig: Script::new(),
+                                               script_sig: ScriptBuf::new(),
                                                sequence: Sequence::ZERO,
                                                witness: Witness::new(),
                                        });
@@ -379,7 +382,7 @@ impl SpendableOutputDescriptor {
                }
                let mut tx = Transaction {
                        version: 2,
-                       lock_time: locktime.unwrap_or(PackedLockTime::ZERO),
+                       lock_time: locktime.unwrap_or(LockTime::ZERO),
                        input,
                        output: outputs,
                };
@@ -503,7 +506,7 @@ impl HTLCDescriptor {
        }
 
        /// Returns the witness script of the HTLC output in the commitment transaction.
-       pub fn witness_script<C: secp256k1::Signing + secp256k1::Verification>(&self, secp: &Secp256k1<C>) -> Script {
+       pub fn witness_script<C: secp256k1::Signing + secp256k1::Verification>(&self, secp: &Secp256k1<C>) -> ScriptBuf {
                let channel_params = self.channel_derivation_parameters.transaction_parameters.as_holder_broadcastable();
                let broadcaster_keys = channel_params.broadcaster_pubkeys();
                let counterparty_keys = channel_params.countersignatory_pubkeys();
@@ -697,7 +700,6 @@ pub trait EcdsaChannelSigner: ChannelSigner {
        /// [`ChannelMonitor`] [replica](https://github.com/lightningdevkit/rust-lightning/blob/main/GLOSSARY.md#monitor-replicas)
        /// broadcasts it before receiving the update for the latest commitment transaction.
        ///
-       /// [`EcdsaSighashType::All`]: bitcoin::blockdata::transaction::EcdsaSighashType::All
        /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
        fn sign_holder_htlc_transaction(&self, htlc_tx: &Transaction, input: usize,
                htlc_descriptor: &HTLCDescriptor, secp_ctx: &Secp256k1<secp256k1::All>
@@ -905,7 +907,7 @@ pub trait SignerProvider {
        ///
        /// This method should return a different value each time it is called, to avoid linking
        /// on-chain funds across channels as controlled to the same user.
-       fn get_destination_script(&self) -> Result<Script, ()>;
+       fn get_destination_script(&self) -> Result<ScriptBuf, ()>;
 
        /// Get a script pubkey which we will send funds to when closing a channel.
        ///
@@ -1108,7 +1110,7 @@ impl InMemorySigner {
        /// or if an output descriptor `script_pubkey` does not match the one we can spend.
        ///
        /// [`descriptor.outpoint`]: StaticPaymentOutputDescriptor::outpoint
-       pub fn sign_counterparty_payment_input<C: Signing>(&self, spend_tx: &Transaction, input_idx: usize, descriptor: &StaticPaymentOutputDescriptor, secp_ctx: &Secp256k1<C>) -> Result<Vec<Vec<u8>>, ()> {
+       pub fn sign_counterparty_payment_input<C: Signing>(&self, spend_tx: &Transaction, input_idx: usize, descriptor: &StaticPaymentOutputDescriptor, secp_ctx: &Secp256k1<C>) -> Result<Witness, ()> {
                // TODO: We really should be taking the SigHashCache as a parameter here instead of
                // spend_tx, but ideally the SigHashCache would expose the transaction's inputs read-only
                // so that we can check them. This requires upstream rust-bitcoin changes (as well as
@@ -1127,14 +1129,14 @@ impl InMemorySigner {
                let witness_script = if supports_anchors_zero_fee_htlc_tx {
                        chan_utils::get_to_countersignatory_with_anchors_redeemscript(&remotepubkey.inner)
                } else {
-                       Script::new_p2pkh(&remotepubkey.pubkey_hash())
+                       ScriptBuf::new_p2pkh(&remotepubkey.pubkey_hash())
                };
                let sighash = hash_to_message!(&sighash::SighashCache::new(spend_tx).segwit_signature_hash(input_idx, &witness_script, descriptor.output.value, EcdsaSighashType::All).unwrap()[..]);
                let remotesig = sign_with_aux_rand(secp_ctx, &sighash, &self.payment_key, &self);
                let payment_script = if supports_anchors_zero_fee_htlc_tx {
                        witness_script.to_v0_p2wsh()
                } else {
-                       Script::new_v0_p2wpkh(&remotepubkey.wpubkey_hash().unwrap())
+                       ScriptBuf::new_v0_p2wpkh(&remotepubkey.wpubkey_hash().unwrap())
                };
 
                if payment_script != descriptor.output.script_pubkey { return Err(()); }
@@ -1147,7 +1149,7 @@ impl InMemorySigner {
                } else {
                        witness.push(remotepubkey.to_bytes());
                }
-               Ok(witness)
+               Ok(witness.into())
        }
 
        /// Sign the single input of `spend_tx` at index `input_idx` which spends the output
@@ -1160,7 +1162,7 @@ impl InMemorySigner {
        ///
        /// [`descriptor.outpoint`]: DelayedPaymentOutputDescriptor::outpoint
        /// [`descriptor.to_self_delay`]: DelayedPaymentOutputDescriptor::to_self_delay
-       pub fn sign_dynamic_p2wsh_input<C: Signing>(&self, spend_tx: &Transaction, input_idx: usize, descriptor: &DelayedPaymentOutputDescriptor, secp_ctx: &Secp256k1<C>) -> Result<Vec<Vec<u8>>, ()> {
+       pub fn sign_dynamic_p2wsh_input<C: Signing>(&self, spend_tx: &Transaction, input_idx: usize, descriptor: &DelayedPaymentOutputDescriptor, secp_ctx: &Secp256k1<C>) -> Result<Witness, ()> {
                // TODO: We really should be taking the SigHashCache as a parameter here instead of
                // spend_tx, but ideally the SigHashCache would expose the transaction's inputs read-only
                // so that we can check them. This requires upstream rust-bitcoin changes (as well as
@@ -1174,17 +1176,19 @@ impl InMemorySigner {
                let delayed_payment_pubkey = PublicKey::from_secret_key(&secp_ctx, &delayed_payment_key);
                let witness_script = chan_utils::get_revokeable_redeemscript(&descriptor.revocation_pubkey, descriptor.to_self_delay, &delayed_payment_pubkey);
                let sighash = hash_to_message!(&sighash::SighashCache::new(spend_tx).segwit_signature_hash(input_idx, &witness_script, descriptor.output.value, EcdsaSighashType::All).unwrap()[..]);
-               let local_delayedsig = sign_with_aux_rand(secp_ctx, &sighash, &delayed_payment_key, &self);
+               let local_delayedsig = EcdsaSignature {
+                       sig: sign_with_aux_rand(secp_ctx, &sighash, &delayed_payment_key, &self),
+                       hash_ty: EcdsaSighashType::All,
+               };
                let payment_script = bitcoin::Address::p2wsh(&witness_script, Network::Bitcoin).script_pubkey();
 
                if descriptor.output.script_pubkey != payment_script { return Err(()); }
 
-               let mut witness = Vec::with_capacity(3);
-               witness.push(local_delayedsig.serialize_der().to_vec());
-               witness[0].push(EcdsaSighashType::All as u8);
-               witness.push(vec!()); //MINIMALIF
-               witness.push(witness_script.clone().into_bytes());
-               Ok(witness)
+               Ok(Witness::from_slice(&[
+                       &local_delayedsig.serialize()[..],
+                       &[], // MINIMALIF
+                       witness_script.as_bytes(),
+               ]))
        }
 }
 
@@ -1322,7 +1326,7 @@ impl EcdsaChannelSigner for InMemorySigner {
                let our_htlc_private_key = chan_utils::derive_private_key(
                        &secp_ctx, &htlc_descriptor.per_commitment_point, &self.htlc_base_key
                );
-               Ok(sign_with_aux_rand(&secp_ctx, &hash_to_message!(sighash), &our_htlc_private_key, &self))
+               Ok(sign_with_aux_rand(&secp_ctx, &hash_to_message!(sighash.as_byte_array()), &our_htlc_private_key, &self))
        }
 
        fn sign_counterparty_htlc_transaction(&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
@@ -1444,7 +1448,7 @@ pub struct KeysManager {
        node_secret: SecretKey,
        node_id: PublicKey,
        inbound_payment_key: KeyMaterial,
-       destination_script: Script,
+       destination_script: ScriptBuf,
        shutdown_pubkey: PublicKey,
        channel_master_key: ExtendedPrivKey,
        channel_child_index: AtomicUsize,
@@ -1486,7 +1490,7 @@ impl KeysManager {
                                        Ok(destination_key) => {
                                                let wpubkey_hash = WPubkeyHash::hash(&ExtendedPubKey::from_priv(&secp_ctx, &destination_key).to_pub().to_bytes());
                                                Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
-                                                       .push_slice(&wpubkey_hash.into_inner())
+                                                       .push_slice(&wpubkey_hash.to_byte_array())
                                                        .into_script()
                                        },
                                        Err(_) => panic!("Your RNG is busted"),
@@ -1505,7 +1509,7 @@ impl KeysManager {
                                rand_bytes_engine.input(&starting_time_nanos.to_be_bytes());
                                rand_bytes_engine.input(seed);
                                rand_bytes_engine.input(b"LDK PRNG Seed");
-                               let rand_bytes_unique_start = Sha256::from_engine(rand_bytes_engine).into_inner();
+                               let rand_bytes_unique_start = Sha256::from_engine(rand_bytes_engine).to_byte_array();
 
                                let mut res = KeysManager {
                                        secp_ctx,
@@ -1554,13 +1558,13 @@ impl KeysManager {
                        ).expect("Your RNG is busted");
                unique_start.input(&child_privkey.private_key[..]);
 
-               let seed = Sha256::from_engine(unique_start).into_inner();
+               let seed = Sha256::from_engine(unique_start).to_byte_array();
 
                let commitment_seed = {
                        let mut sha = Sha256::engine();
                        sha.input(&seed);
                        sha.input(&b"commitment seed"[..]);
-                       Sha256::from_engine(sha).into_inner()
+                       Sha256::from_engine(sha).to_byte_array()
                };
                macro_rules! key_step {
                        ($info: expr, $prev_key: expr) => {{
@@ -1568,7 +1572,7 @@ impl KeysManager {
                                sha.input(&seed);
                                sha.input(&$prev_key[..]);
                                sha.input(&$info[..]);
-                               SecretKey::from_slice(&Sha256::from_engine(sha).into_inner()).expect("SHA-256 is busted")
+                               SecretKey::from_slice(&Sha256::from_engine(sha).to_byte_array()).expect("SHA-256 is busted")
                        }}
                }
                let funding_key = key_step!(b"funding key", commitment_seed);
@@ -1613,7 +1617,7 @@ impl KeysManager {
                                                }
                                                keys_cache = Some((signer, descriptor.channel_keys_id));
                                        }
-                                       let witness = Witness::from_vec(keys_cache.as_ref().unwrap().0.sign_counterparty_payment_input(&psbt.unsigned_tx, input_idx, &descriptor, &secp_ctx)?);
+                                       let witness = keys_cache.as_ref().unwrap().0.sign_counterparty_payment_input(&psbt.unsigned_tx, input_idx, &descriptor, &secp_ctx)?;
                                        psbt.inputs[input_idx].final_script_witness = Some(witness);
                                },
                                SpendableOutputDescriptor::DelayedPaymentOutput(descriptor) => {
@@ -1623,7 +1627,7 @@ impl KeysManager {
                                                        self.derive_channel_keys(descriptor.channel_value_satoshis, &descriptor.channel_keys_id),
                                                        descriptor.channel_keys_id));
                                        }
-                                       let witness = Witness::from_vec(keys_cache.as_ref().unwrap().0.sign_dynamic_p2wsh_input(&psbt.unsigned_tx, input_idx, &descriptor, &secp_ctx)?);
+                                       let witness = keys_cache.as_ref().unwrap().0.sign_dynamic_p2wsh_input(&psbt.unsigned_tx, input_idx, &descriptor, &secp_ctx)?;
                                        psbt.inputs[input_idx].final_script_witness = Some(witness);
                                },
                                SpendableOutputDescriptor::StaticOutput { ref outpoint, ref output } => {
@@ -1658,7 +1662,7 @@ impl KeysManager {
                                        let sig = sign_with_aux_rand(secp_ctx, &sighash, &secret.private_key, &self);
                                        let mut sig_ser = sig.serialize_der().to_vec();
                                        sig_ser.push(EcdsaSighashType::All as u8);
-                                       let witness = Witness::from_vec(vec![sig_ser, pubkey.inner.serialize().to_vec()]);
+                                       let witness = Witness::from_slice(&[&sig_ser, &pubkey.inner.serialize().to_vec()]);
                                        psbt.inputs[input_idx].final_script_witness = Some(witness);
                                },
                        }
@@ -1684,16 +1688,16 @@ impl KeysManager {
        ///
        /// May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
        /// this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
-       pub fn spend_spendable_outputs<C: Signing>(&self, descriptors: &[&SpendableOutputDescriptor], outputs: Vec<TxOut>, change_destination_script: Script, feerate_sat_per_1000_weight: u32, locktime: Option<PackedLockTime>, secp_ctx: &Secp256k1<C>) -> Result<Transaction, ()> {
+       pub fn spend_spendable_outputs<C: Signing>(&self, descriptors: &[&SpendableOutputDescriptor], outputs: Vec<TxOut>, change_destination_script: ScriptBuf, feerate_sat_per_1000_weight: u32, locktime: Option<LockTime>, secp_ctx: &Secp256k1<C>) -> Result<Transaction, ()> {
                let (mut psbt, expected_max_weight) = SpendableOutputDescriptor::create_spendable_outputs_psbt(descriptors, outputs, change_destination_script, feerate_sat_per_1000_weight, locktime)?;
                psbt = self.sign_spendable_outputs_psbt(descriptors, psbt, secp_ctx)?;
 
                let spend_tx = psbt.extract_tx();
 
-               debug_assert!(expected_max_weight >= spend_tx.weight());
+               debug_assert!(expected_max_weight >= spend_tx.weight().to_wu());
                // Note that witnesses with a signature vary somewhat in size, so allow
                // `expected_max_weight` to overshoot by up to 3 bytes per input.
-               debug_assert!(expected_max_weight <= spend_tx.weight() + descriptors.len() * 3);
+               debug_assert!(expected_max_weight <= spend_tx.weight().to_wu() + descriptors.len() as u64 * 3);
 
                Ok(spend_tx)
        }
@@ -1737,7 +1741,7 @@ impl NodeSigner for KeysManager {
                        Recipient::Node => Ok(&self.node_secret),
                        Recipient::PhantomNode => Err(())
                }?;
-               Ok(self.secp_ctx.sign_ecdsa_recoverable(&hash_to_message!(&Sha256::hash(&preimage)), secret))
+               Ok(self.secp_ctx.sign_ecdsa_recoverable(&hash_to_message!(&Sha256::hash(&preimage).to_byte_array()), secret))
        }
 
        fn sign_bolt12_invoice_request(
@@ -1791,7 +1795,7 @@ impl SignerProvider for KeysManager {
                InMemorySigner::read(&mut io::Cursor::new(reader), self)
        }
 
-       fn get_destination_script(&self) -> Result<Script, ()> {
+       fn get_destination_script(&self) -> Result<ScriptBuf, ()> {
                Ok(self.destination_script.clone())
        }
 
@@ -1863,7 +1867,7 @@ impl NodeSigner for PhantomKeysManager {
                        Recipient::Node => &self.inner.node_secret,
                        Recipient::PhantomNode => &self.phantom_secret,
                };
-               Ok(self.inner.secp_ctx.sign_ecdsa_recoverable(&hash_to_message!(&Sha256::hash(&preimage)), secret))
+               Ok(self.inner.secp_ctx.sign_ecdsa_recoverable(&hash_to_message!(&Sha256::hash(&preimage).to_byte_array()), secret))
        }
 
        fn sign_bolt12_invoice_request(
@@ -1898,7 +1902,7 @@ impl SignerProvider for PhantomKeysManager {
                self.inner.read_chan_signer(reader)
        }
 
-       fn get_destination_script(&self) -> Result<Script, ()> {
+       fn get_destination_script(&self) -> Result<ScriptBuf, ()> {
                self.inner.get_destination_script()
        }
 
@@ -1933,7 +1937,7 @@ impl PhantomKeysManager {
        }
 
        /// See [`KeysManager::spend_spendable_outputs`] for documentation on this method.
-       pub fn spend_spendable_outputs<C: Signing>(&self, descriptors: &[&SpendableOutputDescriptor], outputs: Vec<TxOut>, change_destination_script: Script, feerate_sat_per_1000_weight: u32, locktime: Option<PackedLockTime>, secp_ctx: &Secp256k1<C>) -> Result<Transaction, ()> {
+       pub fn spend_spendable_outputs<C: Signing>(&self, descriptors: &[&SpendableOutputDescriptor], outputs: Vec<TxOut>, change_destination_script: ScriptBuf, feerate_sat_per_1000_weight: u32, locktime: Option<LockTime>, secp_ctx: &Secp256k1<C>) -> Result<Transaction, ()> {
                self.inner.spend_spendable_outputs(descriptors, outputs, change_destination_script, feerate_sat_per_1000_weight, locktime, secp_ctx)
        }
 
index cdd00d92af9c5f3cd0a2fe3a61c3447310a0bba2..bb5903b2c8d166783c8b6a275441282e9e7d1b27 100644 (file)
@@ -11,14 +11,14 @@ macro_rules! hkdf_extract_expand {
        ($salt: expr, $ikm: expr) => {{
                let mut hmac = HmacEngine::<Sha256>::new($salt);
                hmac.input($ikm);
-               let prk = Hmac::from_engine(hmac).into_inner();
+               let prk = Hmac::from_engine(hmac).to_byte_array();
                let mut hmac = HmacEngine::<Sha256>::new(&prk[..]);
                hmac.input(&[1; 1]);
-               let t1 = Hmac::from_engine(hmac).into_inner();
+               let t1 = Hmac::from_engine(hmac).to_byte_array();
                let mut hmac = HmacEngine::<Sha256>::new(&prk[..]);
                hmac.input(&t1);
                hmac.input(&[2; 1]);
-               (t1, Hmac::from_engine(hmac).into_inner(), prk)
+               (t1, Hmac::from_engine(hmac).to_byte_array(), prk)
        }};
        ($salt: expr, $ikm: expr, 2) => {{
                let (k1, k2, _) = hkdf_extract_expand!($salt, $ikm);
@@ -30,17 +30,17 @@ macro_rules! hkdf_extract_expand {
                let mut hmac = HmacEngine::<Sha256>::new(&prk[..]);
                hmac.input(&k2);
                hmac.input(&[3; 1]);
-               let k3 = Hmac::from_engine(hmac).into_inner();
+               let k3 = Hmac::from_engine(hmac).to_byte_array();
 
                let mut hmac = HmacEngine::<Sha256>::new(&prk[..]);
                hmac.input(&k3);
                hmac.input(&[4; 1]);
-               let k4 = Hmac::from_engine(hmac).into_inner();
+               let k4 = Hmac::from_engine(hmac).to_byte_array();
 
                let mut hmac = HmacEngine::<Sha256>::new(&prk[..]);
                hmac.input(&k4);
                hmac.input(&[5; 1]);
-               let k5 = Hmac::from_engine(hmac).into_inner();
+               let k5 = Hmac::from_engine(hmac).to_byte_array();
 
                (k1, k2, k3, k4, k5)
        }}
index 477cbcbdd9aa93493de6703e0d4d57cd81c135d2..88ff18ff204c8ae96ee723bd0a718bed0ae3394a 100644 (file)
@@ -57,7 +57,7 @@ pub fn sign(msg: &[u8], sk: &SecretKey) -> Result<String, Error> {
        let secp_ctx = Secp256k1::signing_only();
        let msg_hash = sha256d::Hash::hash(&[LN_MESSAGE_PREFIX, msg].concat());
 
-       let sig = secp_ctx.sign_ecdsa_recoverable(&Message::from_slice(&msg_hash)?, sk);
+       let sig = secp_ctx.sign_ecdsa_recoverable(&Message::from_slice(msg_hash.as_byte_array())?, sk);
        Ok(base32::Alphabet::ZBase32.encode(&sigrec_encode(sig)))
 }
 
@@ -69,7 +69,7 @@ pub fn recover_pk(msg: &[u8], sig: &str) ->  Result<PublicKey, Error> {
        match base32::Alphabet::ZBase32.decode(&sig) {
                Ok(sig_rec) => {
                        match sigrec_decode(sig_rec) {
-                               Ok(sig) => secp_ctx.recover_ecdsa(&Message::from_slice(&msg_hash)?, &sig),
+                               Ok(sig) => secp_ctx.recover_ecdsa(&Message::from_slice(msg_hash.as_byte_array())?, &sig),
                                Err(e) => Err(e)
                        }
                },
@@ -90,13 +90,14 @@ pub fn verify(msg: &[u8], sig: &str, pk: &PublicKey) -> bool {
 mod test {
        use core::str::FromStr;
        use crate::util::message_signing::{sign, recover_pk, verify};
-       use bitcoin::secp256k1::ONE_KEY;
-       use bitcoin::secp256k1::{PublicKey, Secp256k1};
+       use bitcoin::secp256k1::constants::ONE;
+       use bitcoin::secp256k1::{PublicKey, SecretKey, Secp256k1};
 
        #[test]
        fn test_sign() {
                let message = "test message";
-               let zbase32_sig = sign(message.as_bytes(), &ONE_KEY);
+               let one_key = SecretKey::from_slice(&ONE).unwrap();
+               let zbase32_sig = sign(message.as_bytes(), &one_key);
 
                assert_eq!(zbase32_sig.unwrap(), "d9tibmnic9t5y41hg7hkakdcra94akas9ku3rmmj4ag9mritc8ok4p5qzefs78c9pqfhpuftqqzhydbdwfg7u6w6wdxcqpqn4sj4e73e")
        }
@@ -104,17 +105,19 @@ mod test {
        #[test]
        fn test_recover_pk() {
                let message = "test message";
+               let one_key = SecretKey::from_slice(&ONE).unwrap();
                let sig = "d9tibmnic9t5y41hg7hkakdcra94akas9ku3rmmj4ag9mritc8ok4p5qzefs78c9pqfhpuftqqzhydbdwfg7u6w6wdxcqpqn4sj4e73e";
                let pk = recover_pk(message.as_bytes(), sig);
 
-               assert_eq!(pk.unwrap(), PublicKey::from_secret_key(&Secp256k1::signing_only(), &ONE_KEY))
+               assert_eq!(pk.unwrap(), PublicKey::from_secret_key(&Secp256k1::signing_only(), &one_key))
        }
 
        #[test]
        fn test_verify() {
                let message = "another message";
-               let sig = sign(message.as_bytes(), &ONE_KEY).unwrap();
-               let pk = PublicKey::from_secret_key(&Secp256k1::signing_only(), &ONE_KEY);
+               let one_key = SecretKey::from_slice(&ONE).unwrap();
+               let sig = sign(message.as_bytes(), &one_key).unwrap();
+               let pk = PublicKey::from_secret_key(&Secp256k1::signing_only(), &one_key);
 
                assert!(verify(message.as_bytes(), &sig, &pk))
        }
index 35e473c42a690f47a216b87d344ab6a3ace87999..9928597fb8a2b10b112b25ca4bef1e70e065dc03 100644 (file)
@@ -11,7 +11,7 @@
 use core::cmp;
 use core::convert::{TryFrom, TryInto};
 use core::ops::Deref;
-use bitcoin::hashes::hex::{FromHex, ToHex};
+use core::str::FromStr;
 use bitcoin::{BlockHash, Txid};
 
 use crate::{io, log_error};
@@ -194,7 +194,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner, K: KVStore> Persist<ChannelSign
        // just shut down the node since we're not retrying persistence!
 
        fn persist_new_channel(&self, funding_txo: OutPoint, monitor: &ChannelMonitor<ChannelSigner>, _update_id: MonitorUpdateId) -> chain::ChannelMonitorUpdateStatus {
-               let key = format!("{}_{}", funding_txo.txid.to_hex(), funding_txo.index);
+               let key = format!("{}_{}", funding_txo.txid.to_string(), funding_txo.index);
                match self.write(
                        CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE,
                        CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE,
@@ -206,7 +206,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner, K: KVStore> Persist<ChannelSign
        }
 
        fn update_persisted_channel(&self, funding_txo: OutPoint, _update: Option<&ChannelMonitorUpdate>, monitor: &ChannelMonitor<ChannelSigner>, _update_id: MonitorUpdateId) -> chain::ChannelMonitorUpdateStatus {
-               let key = format!("{}_{}", funding_txo.txid.to_hex(), funding_txo.index);
+               let key = format!("{}_{}", funding_txo.txid.to_string(), funding_txo.index);
                match self.write(
                        CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE,
                        CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE,
@@ -238,7 +238,7 @@ where
                                "Stored key has invalid length"));
                }
 
-               let txid = Txid::from_hex(stored_key.split_at(64).0).map_err(|_| {
+               let txid = Txid::from_str(stored_key.split_at(64).0).map_err(|_| {
                        io::Error::new(io::ErrorKind::InvalidData, "Invalid tx ID in stored key")
                })?;
 
@@ -780,7 +780,7 @@ impl MonitorName {
        fn do_try_into_outpoint(name: &str) -> Result<OutPoint, io::Error> {
                let mut parts = name.splitn(2, '_');
                let txid = if let Some(part) = parts.next() {
-                       Txid::from_hex(part).map_err(|_| {
+                       Txid::from_str(part).map_err(|_| {
                                io::Error::new(io::ErrorKind::InvalidData, "Invalid tx ID in stored key")
                        })?
                } else {
@@ -813,7 +813,7 @@ impl TryFrom<&MonitorName> for OutPoint {
 
 impl From<OutPoint> for MonitorName {
        fn from(value: OutPoint) -> Self {
-               MonitorName(format!("{}_{}", value.txid.to_hex(), value.index))
+               MonitorName(format!("{}_{}", value.txid.to_string(), value.index))
        }
 }
 
@@ -873,13 +873,13 @@ mod tests {
        #[test]
        fn monitor_from_outpoint_works() {
                let monitor_name1 = MonitorName::from(OutPoint {
-                       txid: Txid::from_hex("deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef").unwrap(),
+                       txid: Txid::from_str("deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef").unwrap(),
                        index: 1,
                });
                assert_eq!(monitor_name1.as_str(), "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef_1");
 
                let monitor_name2 = MonitorName::from(OutPoint {
-                       txid: Txid::from_hex("f33dbeeff33dbeeff33dbeeff33dbeeff33dbeeff33dbeeff33dbeeff33dbeef").unwrap(),
+                       txid: Txid::from_str("f33dbeeff33dbeeff33dbeeff33dbeeff33dbeeff33dbeeff33dbeeff33dbeef").unwrap(),
                        index: u16::MAX,
                });
                assert_eq!(monitor_name2.as_str(), "f33dbeeff33dbeeff33dbeeff33dbeeff33dbeeff33dbeeff33dbeeff33dbeef_65535");
@@ -1062,7 +1062,7 @@ mod tests {
                        let update_id = update_map.get(&added_monitors[0].0.to_channel_id()).unwrap();
                        let cmu_map = nodes[1].chain_monitor.monitor_updates.lock().unwrap();
                        let cmu = &cmu_map.get(&added_monitors[0].0.to_channel_id()).unwrap()[0];
-                       let test_txo = OutPoint { txid: Txid::from_hex("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(), index: 0 };
+                       let test_txo = OutPoint { txid: Txid::from_str("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(), index: 0 };
 
                        let ro_persister = MonitorUpdatingPersister {
                                kv_store: &TestStore::new(true),
index 9682c09d95c9aa4e096c6213513b980f9a5ed98b..0d5cfc81906fddacfe24ae97d202fe3f20f7383e 100644 (file)
@@ -29,7 +29,7 @@ use bitcoin::secp256k1::constants::{PUBLIC_KEY_SIZE, SECRET_KEY_SIZE, COMPACT_SI
 use bitcoin::secp256k1::ecdsa;
 use bitcoin::secp256k1::schnorr;
 use bitcoin::blockdata::constants::ChainHash;
-use bitcoin::blockdata::script::{self, Script};
+use bitcoin::blockdata::script::{self, ScriptBuf};
 use bitcoin::blockdata::transaction::{OutPoint, Transaction, TxOut};
 use bitcoin::{consensus, Witness};
 use bitcoin::consensus::Encodable;
@@ -675,14 +675,14 @@ impl<'a, T> From<&'a Vec<T>> for WithoutLength<&'a Vec<T>> {
        fn from(v: &'a Vec<T>) -> Self { Self(v) }
 }
 
-impl Writeable for WithoutLength<&Script> {
+impl Writeable for WithoutLength<&ScriptBuf> {
        #[inline]
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
                writer.write_all(self.0.as_bytes())
        }
 }
 
-impl Readable for WithoutLength<Script> {
+impl Readable for WithoutLength<ScriptBuf> {
        #[inline]
        fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
                let v: WithoutLength<Vec<u8>> = Readable::read(r)?;
@@ -885,19 +885,19 @@ impl Readable for Vec<Witness> {
        }
 }
 
-impl Writeable for Script {
+impl Writeable for ScriptBuf {
        fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
                (self.len() as u16).write(w)?;
                w.write_all(self.as_bytes())
        }
 }
 
-impl Readable for Script {
+impl Readable for ScriptBuf {
        fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
                let len = <u16 as Readable>::read(r)? as usize;
                let mut buf = vec![0; len];
                r.read_exact(&mut buf)?;
-               Ok(Script::from(buf))
+               Ok(ScriptBuf::from(buf))
        }
 }
 
@@ -1140,7 +1140,7 @@ impl Writeable for ChainHash {
 impl Readable for ChainHash {
        fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
                let buf: [u8; 32] = Readable::read(r)?;
-               Ok(ChainHash::from(&buf[..]))
+               Ok(ChainHash::from(buf))
        }
 }
 
@@ -1444,6 +1444,7 @@ impl Readable for ClaimId {
 #[cfg(test)]
 mod tests {
        use core::convert::TryFrom;
+       use bitcoin::hashes::hex::FromHex;
        use bitcoin::secp256k1::ecdsa;
        use crate::util::ser::{Readable, Hostname, Writeable};
 
@@ -1492,11 +1493,11 @@ mod tests {
                        "ffffffffffffffffff"
                ];
                for i in 0..=7 {
-                       let mut stream = crate::io::Cursor::new(::hex::decode(bytes[i]).unwrap());
+                       let mut stream = crate::io::Cursor::new(<Vec<u8>>::from_hex(bytes[i]).unwrap());
                        assert_eq!(super::BigSize::read(&mut stream).unwrap().0, values[i]);
                        let mut stream = super::VecWriter(Vec::new());
                        super::BigSize(values[i]).write(&mut stream).unwrap();
-                       assert_eq!(stream.0, ::hex::decode(bytes[i]).unwrap());
+                       assert_eq!(stream.0, <Vec<u8>>::from_hex(bytes[i]).unwrap());
                }
                let err_bytes = vec![
                        "fd00fc",
@@ -1511,7 +1512,7 @@ mod tests {
                        ""
                ];
                for i in 0..=9 {
-                       let mut stream = crate::io::Cursor::new(::hex::decode(err_bytes[i]).unwrap());
+                       let mut stream = crate::io::Cursor::new(<Vec<u8>>::from_hex(err_bytes[i]).unwrap());
                        if i < 3 {
                                assert_eq!(super::BigSize::read(&mut stream).err(), Some(crate::ln::msgs::DecodeError::InvalidValue));
                        } else {
index 247fdf60074dc4ff0bad148bef3c89ae374f26d6..782e786ff843eb08f5b5e0146decc9e8b1138af5 100644 (file)
@@ -1116,6 +1116,7 @@ mod tests {
        use crate::prelude::*;
        use crate::ln::msgs::DecodeError;
        use crate::util::ser::{Writeable, HighZeroBytesDroppedBigSize, VecWriter};
+       use bitcoin::hashes::hex::FromHex;
        use bitcoin::secp256k1::PublicKey;
 
        // The BOLT TLV test cases don't include any tests which use our "required-value" logic since
@@ -1133,7 +1134,7 @@ mod tests {
        #[test]
        fn tlv_v_short_read() {
                // We only expect a u32 for type 3 (which we are given), but the L says its 8 bytes.
-               if let Err(DecodeError::ShortRead) = tlv_reader(&::hex::decode(
+               if let Err(DecodeError::ShortRead) = tlv_reader(&<Vec<u8>>::from_hex(
                                concat!("0100", "0208deadbeef1badbeef", "0308deadbeef")
                                ).unwrap()[..]) {
                } else { panic!(); }
@@ -1141,12 +1142,12 @@ mod tests {
 
        #[test]
        fn tlv_types_out_of_order() {
-               if let Err(DecodeError::InvalidValue) = tlv_reader(&::hex::decode(
+               if let Err(DecodeError::InvalidValue) = tlv_reader(&<Vec<u8>>::from_hex(
                                concat!("0100", "0304deadbeef", "0208deadbeef1badbeef")
                                ).unwrap()[..]) {
                } else { panic!(); }
                // ...even if its some field we don't understand
-               if let Err(DecodeError::InvalidValue) = tlv_reader(&::hex::decode(
+               if let Err(DecodeError::InvalidValue) = tlv_reader(&<Vec<u8>>::from_hex(
                                concat!("0208deadbeef1badbeef", "0100", "0304deadbeef")
                                ).unwrap()[..]) {
                } else { panic!(); }
@@ -1155,17 +1156,17 @@ mod tests {
        #[test]
        fn tlv_req_type_missing_or_extra() {
                // It's also bad if they included even fields we don't understand
-               if let Err(DecodeError::UnknownRequiredFeature) = tlv_reader(&::hex::decode(
+               if let Err(DecodeError::UnknownRequiredFeature) = tlv_reader(&<Vec<u8>>::from_hex(
                                concat!("0100", "0208deadbeef1badbeef", "0304deadbeef", "0600")
                                ).unwrap()[..]) {
                } else { panic!(); }
                // ... or if they're missing fields we need
-               if let Err(DecodeError::InvalidValue) = tlv_reader(&::hex::decode(
+               if let Err(DecodeError::InvalidValue) = tlv_reader(&<Vec<u8>>::from_hex(
                                concat!("0100", "0208deadbeef1badbeef")
                                ).unwrap()[..]) {
                } else { panic!(); }
                // ... even if that field is even
-               if let Err(DecodeError::InvalidValue) = tlv_reader(&::hex::decode(
+               if let Err(DecodeError::InvalidValue) = tlv_reader(&<Vec<u8>>::from_hex(
                                concat!("0304deadbeef", "0500")
                                ).unwrap()[..]) {
                } else { panic!(); }
@@ -1173,11 +1174,11 @@ mod tests {
 
        #[test]
        fn tlv_simple_good_cases() {
-               assert_eq!(tlv_reader(&::hex::decode(
+               assert_eq!(tlv_reader(&<Vec<u8>>::from_hex(
                                concat!("0208deadbeef1badbeef", "03041bad1dea")
                                ).unwrap()[..]).unwrap(),
                        (0xdeadbeef1badbeef, 0x1bad1dea, None));
-               assert_eq!(tlv_reader(&::hex::decode(
+               assert_eq!(tlv_reader(&<Vec<u8>>::from_hex(
                                concat!("0208deadbeef1badbeef", "03041bad1dea", "040401020304")
                                ).unwrap()[..]).unwrap(),
                        (0xdeadbeef1badbeef, 0x1bad1dea, Some(0x01020304)));
@@ -1201,12 +1202,12 @@ mod tests {
 
        #[test]
        fn upgradable_tlv_simple_good_cases() {
-               assert_eq!(upgradable_tlv_reader(&::hex::decode(
+               assert_eq!(upgradable_tlv_reader(&<Vec<u8>>::from_hex(
                        concat!("0204deadbeef", "03041bad1dea", "0404deadbeef")
                ).unwrap()[..]).unwrap(),
                Some(TestUpgradable { a: 0xdeadbeef, b: 0x1bad1dea, c: Some(0xdeadbeef) }));
 
-               assert_eq!(upgradable_tlv_reader(&::hex::decode(
+               assert_eq!(upgradable_tlv_reader(&<Vec<u8>>::from_hex(
                        concat!("0204deadbeef", "03041bad1dea")
                ).unwrap()[..]).unwrap(),
                Some(TestUpgradable { a: 0xdeadbeef, b: 0x1bad1dea, c: None}));
@@ -1214,11 +1215,11 @@ mod tests {
 
        #[test]
        fn missing_required_upgradable() {
-               if let Err(DecodeError::InvalidValue) = upgradable_tlv_reader(&::hex::decode(
+               if let Err(DecodeError::InvalidValue) = upgradable_tlv_reader(&<Vec<u8>>::from_hex(
                        concat!("0100", "0204deadbeef")
                        ).unwrap()[..]) {
                } else { panic!(); }
-               if let Err(DecodeError::InvalidValue) = upgradable_tlv_reader(&::hex::decode(
+               if let Err(DecodeError::InvalidValue) = upgradable_tlv_reader(&<Vec<u8>>::from_hex(
                        concat!("0100", "03041bad1dea")
                ).unwrap()[..]) {
                } else { panic!(); }
@@ -1239,7 +1240,7 @@ mod tests {
        fn bolt_tlv_bogus_stream() {
                macro_rules! do_test {
                        ($stream: expr, $reason: ident) => {
-                               if let Err(DecodeError::$reason) = tlv_reader_n1(&::hex::decode($stream).unwrap()[..]) {
+                               if let Err(DecodeError::$reason) = tlv_reader_n1(&<Vec<u8>>::from_hex($stream).unwrap()[..]) {
                                } else { panic!(); }
                        }
                }
@@ -1264,7 +1265,7 @@ mod tests {
        fn bolt_tlv_bogus_n1_stream() {
                macro_rules! do_test {
                        ($stream: expr, $reason: ident) => {
-                               if let Err(DecodeError::$reason) = tlv_reader_n1(&::hex::decode($stream).unwrap()[..]) {
+                               if let Err(DecodeError::$reason) = tlv_reader_n1(&<Vec<u8>>::from_hex($stream).unwrap()[..]) {
                                } else { panic!(); }
                        }
                }
@@ -1304,7 +1305,7 @@ mod tests {
        fn bolt_tlv_valid_n1_stream() {
                macro_rules! do_test {
                        ($stream: expr, $tlv1: expr, $tlv2: expr, $tlv3: expr, $tlv4: expr) => {
-                               if let Ok((tlv1, tlv2, tlv3, tlv4)) = tlv_reader_n1(&::hex::decode($stream).unwrap()[..]) {
+                               if let Ok((tlv1, tlv2, tlv3, tlv4)) = tlv_reader_n1(&<Vec<u8>>::from_hex($stream).unwrap()[..]) {
                                        assert_eq!(tlv1.map(|v| v.0), $tlv1);
                                        assert_eq!(tlv2, $tlv2);
                                        assert_eq!(tlv3, $tlv3);
@@ -1333,7 +1334,7 @@ mod tests {
                do_test!(concat!("02", "08", "0000000000000226"), None, Some((0 << 30) | (0 << 5) | (550 << 0)), None, None);
                do_test!(concat!("03", "31", "023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb00000000000000010000000000000002"),
                        None, None, Some((
-                               PublicKey::from_slice(&::hex::decode("023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb").unwrap()[..]).unwrap(), 1, 2)),
+                               PublicKey::from_slice(&<Vec<u8>>::from_hex("023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb").unwrap()[..]).unwrap(), 1, 2)),
                        None);
                do_test!(concat!("fd00fe", "02", "0226"), None, None, None, Some(550));
        }
@@ -1343,27 +1344,27 @@ mod tests {
 
                stream.0.clear();
                _encode_varint_length_prefixed_tlv!(&mut stream, {(1, 1u8, required), (42, None::<u64>, option)});
-               assert_eq!(stream.0, ::hex::decode("03010101").unwrap());
+               assert_eq!(stream.0, <Vec<u8>>::from_hex("03010101").unwrap());
 
                stream.0.clear();
                _encode_varint_length_prefixed_tlv!(&mut stream, {(1, Some(1u8), option)});
-               assert_eq!(stream.0, ::hex::decode("03010101").unwrap());
+               assert_eq!(stream.0, <Vec<u8>>::from_hex("03010101").unwrap());
 
                stream.0.clear();
                _encode_varint_length_prefixed_tlv!(&mut stream, {(4, 0xabcdu16, required), (42, None::<u64>, option)});
-               assert_eq!(stream.0, ::hex::decode("040402abcd").unwrap());
+               assert_eq!(stream.0, <Vec<u8>>::from_hex("040402abcd").unwrap());
 
                stream.0.clear();
                _encode_varint_length_prefixed_tlv!(&mut stream, {(42, None::<u64>, option), (0xff, 0xabcdu16, required)});
-               assert_eq!(stream.0, ::hex::decode("06fd00ff02abcd").unwrap());
+               assert_eq!(stream.0, <Vec<u8>>::from_hex("06fd00ff02abcd").unwrap());
 
                stream.0.clear();
                _encode_varint_length_prefixed_tlv!(&mut stream, {(0, 1u64, required), (42, None::<u64>, option), (0xff, HighZeroBytesDroppedBigSize(0u64), required)});
-               assert_eq!(stream.0, ::hex::decode("0e00080000000000000001fd00ff00").unwrap());
+               assert_eq!(stream.0, <Vec<u8>>::from_hex("0e00080000000000000001fd00ff00").unwrap());
 
                stream.0.clear();
                _encode_varint_length_prefixed_tlv!(&mut stream, {(0, Some(1u64), option), (0xff, HighZeroBytesDroppedBigSize(0u64), required)});
-               assert_eq!(stream.0, ::hex::decode("0e00080000000000000001fd00ff00").unwrap());
+               assert_eq!(stream.0, <Vec<u8>>::from_hex("0e00080000000000000001fd00ff00").unwrap());
 
                Ok(())
        }
index ab576fee90de6c9920ad1e6836b3e9b207bec92b..fe1c8cfe06fbaefcaad288b327c02b67f5e49057 100644 (file)
@@ -17,8 +17,10 @@ use core::cmp;
 use crate::sync::{Mutex, Arc};
 #[cfg(test)] use crate::sync::MutexGuard;
 
-use bitcoin::blockdata::transaction::{Transaction, EcdsaSighashType};
-use bitcoin::util::sighash;
+use bitcoin::blockdata::transaction::Transaction;
+use bitcoin::hashes::Hash;
+use bitcoin::sighash;
+use bitcoin::sighash::EcdsaSighashType;
 
 use bitcoin::secp256k1;
 use bitcoin::secp256k1::{SecretKey, PublicKey};
@@ -234,7 +236,7 @@ impl EcdsaChannelSigner for TestChannelSigner {
                                &secp_ctx, &htlc_descriptor.per_commitment_point, &self.inner.counterparty_pubkeys().unwrap().htlc_basepoint
                        );
                        secp_ctx.verify_ecdsa(
-                               &hash_to_message!(&sighash), &htlc_descriptor.counterparty_sig, &countersignatory_htlc_key
+                               &hash_to_message!(sighash.as_byte_array()), &htlc_descriptor.counterparty_sig, &countersignatory_htlc_key
                        ).unwrap();
                }
                Ok(self.inner.sign_holder_htlc_transaction(htlc_tx, input, htlc_descriptor, secp_ctx).unwrap())
index 8dc0111ef95c128d66671d498996c1860028955f..e9a7f0ebfca856cfb3a88aec9c32fad4e3f50507 100644 (file)
@@ -40,16 +40,15 @@ use crate::util::logger::{Logger, Level, Record};
 use crate::util::ser::{Readable, ReadableArgs, Writer, Writeable};
 use crate::util::persist::KVStore;
 
-use bitcoin::EcdsaSighashType;
 use bitcoin::blockdata::constants::ChainHash;
 use bitcoin::blockdata::constants::genesis_block;
 use bitcoin::blockdata::transaction::{Transaction, TxOut};
-use bitcoin::blockdata::script::{Builder, Script};
+use bitcoin::blockdata::script::{Builder, Script, ScriptBuf};
 use bitcoin::blockdata::opcodes;
 use bitcoin::blockdata::block::Block;
 use bitcoin::network::constants::Network;
 use bitcoin::hash_types::{BlockHash, Txid};
-use bitcoin::util::sighash::SighashCache;
+use bitcoin::sighash::{SighashCache, EcdsaSighashType};
 
 use bitcoin::secp256k1::{PublicKey, Scalar, Secp256k1, SecretKey};
 use bitcoin::secp256k1::ecdh::SharedSecret;
@@ -193,7 +192,7 @@ impl SignerProvider for OnlyReadsKeysInterface {
                ))
        }
 
-       fn get_destination_script(&self) -> Result<Script, ()> { Err(()) }
+       fn get_destination_script(&self) -> Result<ScriptBuf, ()> { Err(()) }
        fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> { Err(()) }
 }
 
@@ -302,12 +301,12 @@ pub(crate) struct WatchtowerPersister {
        /// After receiving a revoke_and_ack for a commitment number, we'll form and store the justice
        /// tx which would be used to provide a watchtower with the data it needs.
        watchtower_state: Mutex<HashMap<OutPoint, HashMap<Txid, Transaction>>>,
-       destination_script: Script,
+       destination_script: ScriptBuf,
 }
 
 impl WatchtowerPersister {
        #[cfg(test)]
-       pub(crate) fn new(destination_script: Script) -> Self {
+       pub(crate) fn new(destination_script: ScriptBuf) -> Self {
                WatchtowerPersister {
                        persister: TestPersister::new(),
                        unsigned_justice_tx_data: Mutex::new(HashMap::new()),
@@ -561,9 +560,9 @@ impl TestBroadcaster {
 impl chaininterface::BroadcasterInterface for TestBroadcaster {
        fn broadcast_transactions(&self, txs: &[&Transaction]) {
                for tx in txs {
-                       let lock_time = tx.lock_time.0;
+                       let lock_time = tx.lock_time.to_consensus_u32();
                        assert!(lock_time < 1_500_000_000);
-                       if bitcoin::LockTime::from(tx.lock_time).is_block_height() && lock_time > self.blocks.lock().unwrap().last().unwrap().1 {
+                       if tx.lock_time.is_block_height() && lock_time > self.blocks.lock().unwrap().last().unwrap().1 {
                                for inp in tx.input.iter() {
                                        if inp.sequence != Sequence::MAX {
                                                panic!("We should never broadcast a transaction before its locktime ({})!", tx.lock_time);
@@ -1122,7 +1121,7 @@ impl SignerProvider for TestKeysInterface {
                ))
        }
 
-       fn get_destination_script(&self) -> Result<Script, ()> { self.backing.get_destination_script() }
+       fn get_destination_script(&self) -> Result<ScriptBuf, ()> { self.backing.get_destination_script() }
 
        fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
                match &mut *self.expectations.lock().unwrap() {
@@ -1212,8 +1211,8 @@ pub struct TestChainSource {
        pub chain_hash: ChainHash,
        pub utxo_ret: Mutex<UtxoResult>,
        pub get_utxo_call_count: AtomicUsize,
-       pub watched_txn: Mutex<HashSet<(Txid, Script)>>,
-       pub watched_outputs: Mutex<HashSet<(OutPoint, Script)>>,
+       pub watched_txn: Mutex<HashSet<(Txid, ScriptBuf)>>,
+       pub watched_outputs: Mutex<HashSet<(OutPoint, ScriptBuf)>>,
 }
 
 impl TestChainSource {
@@ -1242,7 +1241,7 @@ impl UtxoLookup for TestChainSource {
 
 impl chain::Filter for TestChainSource {
        fn register_tx(&self, txid: &Txid, script_pubkey: &Script) {
-               self.watched_txn.lock().unwrap().insert((*txid, script_pubkey.clone()));
+               self.watched_txn.lock().unwrap().insert((*txid, script_pubkey.into()));
        }
 
        fn register_output(&self, output: WatchedOutput) {
@@ -1362,9 +1361,9 @@ impl WalletSource for TestWalletSource {
                Ok(self.utxos.borrow().clone())
        }
 
-       fn get_change_script(&self) -> Result<Script, ()> {
+       fn get_change_script(&self) -> Result<ScriptBuf, ()> {
                let public_key = bitcoin::PublicKey::new(self.secret_key.public_key(&self.secp));
-               Ok(Script::new_p2pkh(&public_key.pubkey_hash()))
+               Ok(ScriptBuf::new_p2pkh(&public_key.pubkey_hash()))
        }
 
        fn sign_tx(&self, mut tx: Transaction) -> Result<Transaction, ()> {
@@ -1374,10 +1373,10 @@ impl WalletSource for TestWalletSource {
                                let sighash = SighashCache::new(&tx)
                                        .legacy_signature_hash(i, &utxo.output.script_pubkey, EcdsaSighashType::All as u32)
                                        .map_err(|_| ())?;
-                               let sig = self.secp.sign_ecdsa(&sighash.as_hash().into(), &self.secret_key);
-                               let bitcoin_sig = bitcoin::EcdsaSig { sig, hash_ty: EcdsaSighashType::All }.to_vec();
+                               let sig = self.secp.sign_ecdsa(&(*sighash.as_raw_hash()).into(), &self.secret_key);
+                               let bitcoin_sig = bitcoin::ecdsa::Signature { sig, hash_ty: EcdsaSighashType::All };
                                tx.input[i].script_sig = Builder::new()
-                                       .push_slice(&bitcoin_sig)
+                                       .push_slice(&bitcoin_sig.serialize())
                                        .push_slice(&self.secret_key.public_key(&self.secp).serialize())
                                        .into_script();
                        }
index db1460283324c9cedb247cbb7758e76230a5e289..12b504a69ef8dd50aceeeaed1ea9431fd905d8eb 100644 (file)
@@ -8,7 +8,7 @@
 // licenses.
 
 use bitcoin::blockdata::transaction::{Transaction, TxOut};
-use bitcoin::blockdata::script::Script;
+use bitcoin::blockdata::script::ScriptBuf;
 use bitcoin::consensus::Encodable;
 use bitcoin::consensus::encode::VarInt;
 
@@ -33,10 +33,10 @@ pub fn sort_outputs<T, C : Fn(&T, &T) -> Ordering>(outputs: &mut Vec<(TxOut, T)>
 /// Assumes at least one input will have a witness (ie spends a segwit output).
 /// Returns an Err(()) if the requested feerate cannot be met.
 /// Returns the expected maximum weight of the fully signed transaction on success.
-pub(crate) fn maybe_add_change_output(tx: &mut Transaction, input_value: u64, witness_max_weight: usize, feerate_sat_per_1000_weight: u32, change_destination_script: Script) -> Result<usize, ()> {
+pub(crate) fn maybe_add_change_output(tx: &mut Transaction, input_value: u64, witness_max_weight: u64, feerate_sat_per_1000_weight: u32, change_destination_script: ScriptBuf) -> Result<u64, ()> {
        if input_value > MAX_VALUE_MSAT / 1000 { return Err(()); }
 
-       const WITNESS_FLAG_BYTES: i64 = 2;
+       const WITNESS_FLAG_BYTES: u64 = 2;
 
        let mut output_value = 0;
        for output in tx.output.iter() {
@@ -50,7 +50,7 @@ pub(crate) fn maybe_add_change_output(tx: &mut Transaction, input_value: u64, wi
                value: 0,
        };
        let change_len = change_output.consensus_encode(&mut sink()).unwrap();
-       let starting_weight = tx.weight() + WITNESS_FLAG_BYTES as usize + witness_max_weight;
+       let starting_weight = tx.weight().to_wu() + WITNESS_FLAG_BYTES + witness_max_weight as u64;
        let mut weight_with_change: i64 = starting_weight as i64 + change_len as i64 * 4;
        // Include any extra bytes required to push an extra output.
        weight_with_change += (VarInt(tx.output.len() as u64 + 1).len() - VarInt(tx.output.len() as u64).len()) as i64 * 4;
@@ -59,7 +59,7 @@ pub(crate) fn maybe_add_change_output(tx: &mut Transaction, input_value: u64, wi
        if change_value >= dust_value.to_sat() as i64 {
                change_output.value = change_value as u64;
                tx.output.push(change_output);
-               Ok(weight_with_change as usize)
+               Ok(weight_with_change as u64)
        } else if (input_value - output_value) as i64 - (starting_weight as i64) * feerate_sat_per_1000_weight as i64 / 1000 < 0 {
                Err(())
        } else {
@@ -71,14 +71,13 @@ pub(crate) fn maybe_add_change_output(tx: &mut Transaction, input_value: u64, wi
 mod tests {
        use super::*;
 
+       use bitcoin::blockdata::locktime::absolute::LockTime;
        use bitcoin::blockdata::transaction::{Transaction, TxOut, TxIn, OutPoint};
-       use bitcoin::blockdata::script::{Script, Builder};
+       use bitcoin::blockdata::script::{ScriptBuf, Builder};
        use bitcoin::hash_types::{PubkeyHash, Txid};
-
        use bitcoin::hashes::Hash;
-       use bitcoin::{PackedLockTime, Sequence, Witness};
-
-       use hex::decode;
+       use bitcoin::hashes::hex::FromHex;
+       use bitcoin::{Sequence, Witness};
 
        use alloc::vec;
 
@@ -169,8 +168,8 @@ mod tests {
                );
        }
 
-       fn script_from_hex(hex_str: &str) -> Script {
-               Script::from(decode(hex_str).unwrap())
+       fn script_from_hex(hex_str: &str) -> ScriptBuf {
+               ScriptBuf::from(<Vec<u8>>::from_hex(hex_str).unwrap())
        }
 
        macro_rules! bip_txout_tests {
@@ -214,23 +213,23 @@ mod tests {
        #[test]
        fn test_tx_value_overrun() {
                // If we have a bogus input amount or outputs valued more than inputs, we should fail
-               let mut tx = Transaction { version: 2, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: vec![TxOut {
-                       script_pubkey: Script::new(), value: 1000
+               let mut tx = Transaction { version: 2, lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut {
+                       script_pubkey: ScriptBuf::new(), value: 1000
                }] };
-               assert!(maybe_add_change_output(&mut tx, 21_000_000_0000_0001, 0, 253, Script::new()).is_err());
-               assert!(maybe_add_change_output(&mut tx, 400, 0, 253, Script::new()).is_err());
-               assert!(maybe_add_change_output(&mut tx, 4000, 0, 253, Script::new()).is_ok());
+               assert!(maybe_add_change_output(&mut tx, 21_000_000_0000_0001, 0, 253, ScriptBuf::new()).is_err());
+               assert!(maybe_add_change_output(&mut tx, 400, 0, 253, ScriptBuf::new()).is_err());
+               assert!(maybe_add_change_output(&mut tx, 4000, 0, 253, ScriptBuf::new()).is_ok());
        }
 
        #[test]
        fn test_tx_change_edge() {
                // Check that we never add dust outputs
-               let mut tx = Transaction { version: 2, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: Vec::new() };
+               let mut tx = Transaction { version: 2, lock_time: LockTime::ZERO, input: Vec::new(), output: Vec::new() };
                let orig_wtxid = tx.wtxid();
-               let output_spk = Script::new_p2pkh(&PubkeyHash::hash(&[0; 0]));
+               let output_spk = ScriptBuf::new_p2pkh(&PubkeyHash::hash(&[0; 0]));
                assert_eq!(output_spk.dust_value().to_sat(), 546);
                // 9 sats isn't enough to pay fee on a dummy transaction...
-               assert_eq!(tx.weight() as u64, 40); // ie 10 vbytes
+               assert_eq!(tx.weight().to_wu(), 40); // ie 10 vbytes
                assert!(maybe_add_change_output(&mut tx, 9, 0, 250, output_spk.clone()).is_err());
                assert_eq!(tx.wtxid(), orig_wtxid); // Failure doesn't change the transaction
                // but 10-564 is, just not enough to add a change output...
@@ -250,7 +249,7 @@ mod tests {
                assert_eq!(tx.output.len(), 1);
                assert_eq!(tx.output[0].value, 546);
                assert_eq!(tx.output[0].script_pubkey, output_spk);
-               assert_eq!(tx.weight() / 4, 590-546); // New weight is exactly the fee we wanted.
+               assert_eq!(tx.weight().to_wu() / 4, 590-546); // New weight is exactly the fee we wanted.
 
                tx.output.pop();
                assert_eq!(tx.wtxid(), orig_wtxid); // The only change is the addition of one output.
@@ -259,13 +258,13 @@ mod tests {
        #[test]
        fn test_tx_extra_outputs() {
                // Check that we correctly handle existing outputs
-               let mut tx = Transaction { version: 2, lock_time: PackedLockTime::ZERO, input: vec![TxIn {
-                       previous_output: OutPoint::new(Txid::all_zeros(), 0), script_sig: Script::new(), witness: Witness::new(), sequence: Sequence::ZERO,
+               let mut tx = Transaction { version: 2, lock_time: LockTime::ZERO, input: vec![TxIn {
+                       previous_output: OutPoint::new(Txid::all_zeros(), 0), script_sig: ScriptBuf::new(), witness: Witness::new(), sequence: Sequence::ZERO,
                }], output: vec![TxOut {
                        script_pubkey: Builder::new().push_int(1).into_script(), value: 1000
                }] };
                let orig_wtxid = tx.wtxid();
-               let orig_weight = tx.weight();
+               let orig_weight = tx.weight().to_wu();
                assert_eq!(orig_weight / 4, 61);
 
                assert_eq!(Builder::new().push_int(2).into_script().dust_value().to_sat(), 474);
@@ -284,7 +283,7 @@ mod tests {
                assert_eq!(tx.output.len(), 2);
                assert_eq!(tx.output[1].value, 474);
                assert_eq!(tx.output[1].script_pubkey, Builder::new().push_int(2).into_script());
-               assert_eq!(tx.weight() - orig_weight, 40); // Weight difference matches what we had to add above
+               assert_eq!(tx.weight().to_wu() - orig_weight, 40); // Weight difference matches what we had to add above
                tx.output.pop();
                assert_eq!(tx.wtxid(), orig_wtxid); // The only change is the addition of one output.
        }