diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9011cb07..b55a0b27 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,4 +1,8 @@ -on: [push, pull_request] +on: + push: + branches: + - master + pull_request: {} name: Continuous integration diff --git a/Cargo.toml b/Cargo.toml index 43961a09..a36f68df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,9 +20,9 @@ rand = ["bitcoin/rand"] base64 = ["bitcoin/base64"] [dependencies] -bitcoin = "0.29.1" -elements = "0.21.0" -bitcoin-miniscript = { package = "miniscript", version = "9.0", git = "https://github.com/rust-bitcoin/rust-miniscript", rev = "1351c20a5ead4f308e18bce88cc01983c7d0e876" } +bitcoin = "0.30.0" +elements = "0.22.0" +bitcoin-miniscript = { package = "miniscript", version = "10.0" } # Do NOT use this as a feature! Use the `serde` feature instead. actual-serde = { package = "serde", version = "1.0", optional = true } @@ -31,8 +31,8 @@ actual-serde = { package = "serde", version = "1.0", optional = true } serde_json = "1.0" actual-rand = { package = "rand", version = "0.8.4"} serde_test = "1.0.147" -bitcoin = { version = "0.29.2", features = ["base64"] } -secp256k1 = {version = "0.24.0", features = ["rand-std"]} +bitcoin = { version = "0.30.0", features = ["base64"] } +secp256k1 = {version = "0.27.0", features = ["rand-std"]} actual-base64 = { package = "base64", version = "0.13.0" } @@ -58,4 +58,4 @@ required-features = ["compiler"] [[example]] name = "psbt_sign_finalize" -required-features = ["base64"] \ No newline at end of file +required-features = ["base64"] diff --git a/bitcoind-tests/tests/setup/mod.rs b/bitcoind-tests/tests/setup/mod.rs index 387883e5..135af444 100644 --- a/bitcoind-tests/tests/setup/mod.rs +++ b/bitcoind-tests/tests/setup/mod.rs @@ -3,7 +3,7 @@ pub extern crate elements_miniscript; use std::str::FromStr; use miniscript::elements; use elements::encode::{deserialize, serialize_hex}; -use elements::hashes::hex::FromHex; +use elements::hex::FromHex; use elements::BlockHash; pub use elements_miniscript as miniscript; use elementsd::bitcoincore_rpc::jsonrpc::serde_json::{json, Value}; diff --git a/bitcoind-tests/tests/setup/test_util.rs b/bitcoind-tests/tests/setup/test_util.rs index facb324c..fc2fafe4 100644 --- a/bitcoind-tests/tests/setup/test_util.rs +++ b/bitcoind-tests/tests/setup/test_util.rs @@ -21,10 +21,9 @@ use std::collections::HashMap; use std::str::FromStr; use miniscript::{elements, bitcoin}; -use elements::hashes::hex::ToHex; +use elements::hex::{FromHex, ToHex}; use elements::hashes::{hash160, ripemd160, sha256, Hash}; use elements::secp256k1_zkp as secp256k1; -use elements::hashes::hex::FromHex; use elements::{confidential, encode, AddressParams, BlockHash}; use miniscript::descriptor::{SinglePub, SinglePubKey}; use miniscript::extensions::param::ExtParamTranslator; @@ -41,7 +40,7 @@ pub static PARAMS: AddressParams = AddressParams::ELEMENTS; #[derive(Clone, Debug)] pub struct PubData { pub pks: Vec, - pub x_only_pks: Vec, + pub x_only_pks: Vec, pub sha256: sha256::Hash, pub hash256: hash256::Hash, pub ripemd160: ripemd160::Hash, @@ -79,7 +78,7 @@ fn setup_keys( Vec, Vec, Vec, - Vec, + Vec, ) { let secp_sign = secp256k1::Secp256k1::signing_only(); let mut sk = [0; 32]; @@ -104,7 +103,7 @@ fn setup_keys( for i in 0..n { let keypair = bitcoin::KeyPair::from_secret_key(&secp_sign, &sks[i]); - let (xpk, _parity) = bitcoin::XOnlyPublicKey::from_keypair(&keypair); + let (xpk, _parity) = bitcoin::key::XOnlyPublicKey::from_keypair(&keypair); x_only_keypairs.push(keypair); x_only_pks.push(xpk); } diff --git a/bitcoind-tests/tests/test_csfs.rs b/bitcoind-tests/tests/test_csfs.rs index 6561bbd6..2258e69a 100644 --- a/bitcoind-tests/tests/test_csfs.rs +++ b/bitcoind-tests/tests/test_csfs.rs @@ -162,7 +162,7 @@ pub fn test_desc_satisfy(cl: &ElementsD, testdata: &TestData, desc: &str) -> Vec impl<'a> Satisfier for CsfsSatisfier<'a> { fn lookup_csfs_sig( &self, - pk: &bitcoin::XOnlyPublicKey, + pk: &bitcoin::key::XOnlyPublicKey, msg: &miniscript::extensions::CsfsMsg, ) -> Option { let xpk = pk.to_x_only_pubkey(); @@ -182,7 +182,7 @@ pub fn test_desc_satisfy(cl: &ElementsD, testdata: &TestData, desc: &str) -> Vec fn lookup_price_oracle_sig( &self, - pk: &bitcoin::XOnlyPublicKey, + pk: &bitcoin::key::XOnlyPublicKey, time: u64, ) -> Option<(secp256k1::schnorr::Signature, i64, u64)> { let xpk = pk.to_x_only_pubkey(); diff --git a/examples/psbt_sign_finalize.rs b/examples/psbt_sign_finalize.rs index f4849f18..6c0dd1e3 100644 --- a/examples/psbt_sign_finalize.rs +++ b/examples/psbt_sign_finalize.rs @@ -4,8 +4,7 @@ use elements::bitcoin::PrivateKey; use elements::encode::{serialize, serialize_hex}; use elements::hashes::Hash; use elements::sighash::SigHashCache; -use elements::{confidential, AssetId, PackedLockTime, TxOutWitness}; -use miniscript::elements::hashes::hex::FromHex; +use elements::{confidential, AssetId, LockTime, TxOutWitness}; use miniscript::elements::pset::PartiallySignedTransaction as Psbt; use miniscript::elements::{ self, pset, secp256k1_zkp as secp256k1, Address, AddressParams, OutPoint, Script, Sequence, @@ -74,7 +73,7 @@ fn main() { let spend_tx = Transaction { version: 2, - lock_time: PackedLockTime(5000), + lock_time: LockTime::from_height(5000).unwrap(), input: vec![], output: vec![], }; @@ -89,7 +88,7 @@ fn main() { let amount = 100000000; let outpoint = elements::OutPoint { - txid: elements::Txid::from_hex( + txid: elements::Txid::from_str( "7a3565454fe1b749bccaef22aff72843a9c3efefd7b16ac54537a0c23f0ec0de", ) .unwrap(), @@ -100,7 +99,7 @@ fn main() { // In practice, you would have to get the outpoint and witness utxo from the blockchain. // something like this: - // let depo_tx = elements::Transction::from_hex("...").unwrap(); + // let depo_tx = elements::Transction::from_str("...").unwrap(); // let (outpoint, witness_utxo) = get_vout(&depo_tx, bridge_descriptor.script_pubkey()); let mut txin = TxIn::default(); @@ -193,7 +192,7 @@ fn bitcoin_asset_txout(spk: Script, amt: u64) -> TxOut { script_pubkey: spk, value: confidential::Value::Explicit(amt), asset: confidential::Asset::Explicit( - AssetId::from_hex("088f6b381694259fd20599e71f7eb46e392f36b43cc20d131d95c8a4b8cc1aa8") + AssetId::from_str("088f6b381694259fd20599e71f7eb46e392f36b43cc20d131d95c8a4b8cc1aa8") .unwrap(), ), nonce: confidential::Nonce::Null, diff --git a/examples/sign_multisig.rs b/examples/sign_multisig.rs index 80f01ed1..6da5d93b 100644 --- a/examples/sign_multisig.rs +++ b/examples/sign_multisig.rs @@ -19,7 +19,7 @@ extern crate elements_miniscript as miniscript; use std::collections::HashMap; use std::str::FromStr; -use elements::{secp256k1_zkp, PackedLockTime, Sequence}; +use elements::{secp256k1_zkp, LockTime, Sequence}; fn main() { // Avoid repeatedly typing a pretty-common descriptor type @@ -28,7 +28,7 @@ fn main() { // Transaction which spends some output let mut tx = elements::Transaction { version: 2, - lock_time: PackedLockTime::ZERO, + lock_time: LockTime::ZERO, input: vec![elements::TxIn { previous_output: elements::OutPoint::default(), script_sig: elements::Script::new(), diff --git a/examples/taproot.rs b/examples/taproot.rs index e2ca4827..3d8ef091 100644 --- a/examples/taproot.rs +++ b/examples/taproot.rs @@ -3,7 +3,7 @@ extern crate elements_miniscript as miniscript; use std::collections::HashMap; use std::str::FromStr; -use bitcoin::util::address::WitnessVersion; +use bitcoin::address::WitnessVersion; use miniscript::descriptor::DescriptorType; use miniscript::policy::Concrete; use miniscript::{ @@ -15,18 +15,18 @@ use secp256k1::{rand, KeyPair}; // for a detailed explanation of the policy and it's compilation struct StrPkTranslator { - pk_map: HashMap, + pk_map: HashMap, } -impl Translator for StrPkTranslator { - fn pk(&mut self, pk: &String) -> Result { +impl Translator for StrPkTranslator { + fn pk(&mut self, pk: &String) -> Result { self.pk_map.get(pk).copied().ok_or(()) } // We don't need to implement these methods as we are not using them in the policy // Fail if we encounter any hash fragments. // See also translate_hash_clone! macro - translate_hash_fail!(String, bitcoin::XOnlyPublicKey, ()); + translate_hash_fail!(String, bitcoin::key::XOnlyPublicKey, ()); } fn main() { @@ -89,7 +89,7 @@ fn main() { let secp = secp256k1::Secp256k1::new(); let key_pair = KeyPair::new(&secp, &mut rand::thread_rng()); // Random unspendable XOnlyPublicKey provided for compilation to Taproot Descriptor - let (unspendable_pubkey, _parity) = bitcoin::XOnlyPublicKey::from_keypair(&key_pair); + let (unspendable_pubkey, _parity) = bitcoin::key::XOnlyPublicKey::from_keypair(&key_pair); pk_map.insert("UNSPENDABLE_KEY".to_string(), unspendable_pubkey); let pubkeys = hardcoded_xonlypubkeys(); @@ -120,7 +120,7 @@ fn main() { assert_eq!(addr, expected_addr); } -fn hardcoded_xonlypubkeys() -> Vec { +fn hardcoded_xonlypubkeys() -> Vec { let serialized_keys: [[u8; 32]; 4] = [ [ 22, 37, 41, 4, 57, 254, 191, 38, 14, 184, 200, 133, 111, 226, 145, 183, 245, 112, 100, @@ -139,9 +139,9 @@ fn hardcoded_xonlypubkeys() -> Vec { 168, 39, 134, 58, 19, 181, 3, 63, 235, 103, 155, 213, ], ]; - let mut keys: Vec = vec![]; + let mut keys: Vec = vec![]; for idx in 0..4 { - keys.push(bitcoin::XOnlyPublicKey::from_slice(&serialized_keys[idx][..]).unwrap()); + keys.push(bitcoin::key::XOnlyPublicKey::from_slice(&serialized_keys[idx][..]).unwrap()); } keys } diff --git a/examples/verify_tx.rs b/examples/verify_tx.rs index 219e8b09..baf5febe 100644 --- a/examples/verify_tx.rs +++ b/examples/verify_tx.rs @@ -27,7 +27,7 @@ use crate::miniscript::interpreter::KeySigPair; // secp256k1 re-exported from ru fn main() { // some random liquid tx from mempool(Dec 3rd 2020) // txid: f23c8973027aa8c1e86580a729833914f5b1fa710367db07f1f5515aa3729f16 - let tx_bytes : Vec = elements::hashes::hex::FromHex::from_hex( + let tx_bytes : Vec = elements::hex::FromHex::from_hex( "02000000010232228caa1ed022bba919d55646169e6094fcff7580cfd51767c52ad1f1f7be1501000000171600142e7c87cd55d9163b58a0e98cb0c076e8fbc916c5feffffff28b3920a83b2507ca5f3993c84cf7b69021be6887e86e1ec8855ac432199de6b0100000017160014edfc058e1c059532d7aa90cfd47d1bf4f7d2d9b3feffffff030ae977a025f8432195181d77bc6523b7769b8b4d4c3cf8f5a45bdb940c7dfb561e0878ac4e6ab21b09f64a262d0342e88928cfa68bc9e8d004109f9caca1b305d37e0217abccf88d3488db1e40f79dfaf14ca816431441095bcb2570c9a0dcca01456c17a914b5687f4af9ba5dfb00ed22cb32a857e607bc844d870b892d93c6accf6253edd8340a6c27caaee3d5dc067e626d3c1647dd895299404a0936e562586398b4e95fb34c108afd4a9de4268bd5cd41749833e7a9265e383a0e02658aa567bb9656cd06b563855dfd63fb3e8b37b7991f86895c536af5692e819d17a9149f03346fa3e2a4fbeed0e5c379f2f2ba28025bc187016d521c38ec1ea15734ae22b7c46064412829c0d0579f0a713d1c04ede979026f0100000000000001060000e6bf1000000002473044022020d643f80c3cab90a76dfca198bdba119db97cf4fd8d8adfa2609cdbcf594f570220324c54a8e3170d06cea60511e5e8a84d1f41b21fc252181d69aa8b7d190c26a90121029e831ee2345cc698c730b713b82b99e8c16ffe5ddd51c9b36607bb1fa68b1395000000024730440220645f22a912344b4f8d165814c3513e9bfa06d42066fa4d392f783a57444eff0202200b98199177d9e13c9f3872f433154be430e82cc2e312791a47bea2a91167ff4c01210303a640e79b1e941f2d7867e4eabffd79f30daaabc80fe1c4d974775fc29339810063020003c7b8cf924dff6cef0c9f9b507abc741e431e1a793206b5fca623748f583e6ad3f3f7a4fd1b27d78bf3b4debc9a2c849b5f85722cab872a9c08f19e6eb59ceef74fcf9a7c38acd6fdb7821c33bc731011b6440e8aae7beff3ee6ffc1009c849bcfd4e10603300000000000000012361c401dc40cd92cf93029e64c20c463d17c6e15d2997ab43e8c4b1c412b99a1a337c3cff34c6e7269580727c27404a131606aa85dd8bdf6d46b6ddb23948a0507e31666b531e753eb8fece006050bc7b7e2e06db86833f9adc4f6b77c7b88537617c3accea246a8fe303a23697801181efa8bbcded7690aeac04b58e32f4cd94279cff059a5c9f679d973007042fa1e5e4268a884dbce7acba614d57e1f7a56f81354779ab353c04806ad280417f656a10bcbc683348608d7f6e08367d9c21318cfe6f03a0a60bb8269d667a3ddd57f77f8774364e6a946a6163896db4a8b7e2446d229d8d3718f9a8d7b57a2dfe43baa79bce705512635c775602404d55a2a61fee93c00f1e0cc466bf2cf0bc070591e228de578bc51a38b1927ae29f0e7daad95380f5be599f50367ae1028e57f2e1d9b35d45f0fd860491c2c03a46500f2fabf3c8c7cc9ede16af01eb3d42633ddb8ef87bc043c136f727fffcb4aebdb19f674864e2d2a20aa0d61f7e635c582a79320ff2dbbe8ee74c4c51ee09e03e89581378fcc4d2a6f44524add57be3d31d3054468662a805fb82bd047e5b52e13415ea92c57532940985ded222477f5bed2bdedbbe1f2471b0a85c32a70b0d07a5c734ce90e62b51babee95c63f2cd5ba7b6716a9ecb2f44e5f30f2bc07ea7fef5257aff812558385b23966608191436cbeb1f9fc6a907c1841e1dfcea0e5719749969d447bbb9b332389b2e046d107a873c1b557319250c6469ea03c7bd2c61e6a31963921f1854c5546479044dc992f09c2e781c782fa7dc116074787495bedd991b530a7a8b49bd0f85e32ea19bdfac28152bf63eef1a8bd9294b51eaba8b5bc4db1d89031e4dafffff9bae4329fce27eac3db83e6d5d22ec4e04850b7af49329828e087f2c998882249cb74234002c6ea20641f6b4dd0199e4d6d932e75cf0e59a07b25724826fdfedae239d8275c992456c53a2d4c469f08120554e86c4693c32284616279eeb048d434288f6f73dec16d3d37ef0ed2a98e5c11cf6ac046137bbd8b76c1ebb00e8804133e0e647751ab6b395cc49c92d5084bbac242cbd8369c8f56548ca92b8a1da586e12f6163d2d0b42b4774e6c8eac23240c51ec79d71dbd1a69441265c6d5e4974e3ef6358b30106649744c9799f6ec1de0cc98929f02be8396c4d807e87a767e3e2903633da774ff39141e14aba0c01fe3331d7b888360722ebb1c3e1fdb1b3226ecd2003cfe2400ec9ef29f431d6e5182eb98c8aa4384b60dca8dd0d28ea52fdb6b181c4788b6d0d2ce9c5dad4dad259a83eda33c21704d4230660f8962c69d290e77e60f16916d5e1bf811eadd054d464fe33232541070371a69b120402a9598ceeb9c8ffe0622c90fcffcf271eda70128ed21c5c1990c3361c11f7f697eb56a32bc15c5e79596274043eb80da990fb40e31a0d8a83d62e53e9d9f3f786de418ee3c9a1adc54ebb43b74db84d550dc8fb64aa5a0947f23d9e07fc370e141217b0766186315ad088c2ccbb426e3a184ad74b5469ff24b596670617bb967aaf8976438415d851bc89a98887e2388161c967b8ae9e5814af518097c4e0604b6ecf755527ade18ae0a50234a95f4b45c1bf68ada13991928dc88b61abf23445ec95d3f06830852bba27e09a7747b1c06a1d4948214be7e0bb47f2c14f6ac02715a250232ed15767da55717adb239149d8021f33bb14316622947d98d30506aaabadf90add3cd639f5e558450642ac7b4457da522efb710124518a0a3f41b6798127d209768cc526ecc9a6f70edbe3c3b9f45536295c2bcccc384b0d13bd6d741e8d1d01ac83e09cf35a9e7ff71ffbe2926d8b3c5d5eb131fe9b023d427c4c8c3e4310df6b3c45c2de0092df59e98176b1bcce17889b3667854785a668e3c08aec571506e5074ddc5e53eba12a5c2adde7a0fb7c1e5b86b1463e7634980985dff039d90abdb0d11cc701bc8122e22000d3eb4ee0ef422a08e85bf13d5bc856e79c0eb00f415a8a76d6d7bcb087b090954e0476c81ad1ba3ef89b8b5338c78a8c0b5b25cda36ff35c307900066fcf775cf71069a1e396b0efc611b21ecde8b5f080252d16690767137307aade91486ff23fd4ebd206d0b9bbe9f2221003967fb76e51925954fd5df40d0c331277c35bc7bd40c05ed32a4cf577ccd5219b113df6454258cf1cdf123e8ffb7fab3debb05ac9f3a3874221bc6d08db4c0e2676257ba26d2b780c6102014f980987c6826cdab6a713cbfeae703af2dd8838378dec58b406ce2e796a560e1bf1f7f4d09f32c0cad9ad2fc3720ce3963273b6768250c3119eb4d9c0c722cf64733432fa76abf07e845d55f089df83dfb784cd7bae06e1fa26b7464667945774f2c61afac025d4f5dcc909cfaf064ff9b622b680eab1e5ba31b8374fd2402ffae1481cb8ef180060c8ac01aac5a4f9df8b5e84b7872cdeda17cc5b37a4438b6c31b917a88336cbbd535f95710f1d4bda8dee8f9613c0e62e9914dbc8f2f812783b7b8a154c74c17ceb1df61880f61a9038ade4a15542a2258d0533988303e1d22910448fa3d8aa29660efc1af8d8c470da4071960ab55a83627da6c1d955e337fff0f18e6e4b0516ef21beabdd3174ffe816ac945ab7c54a60a56898fce13b782820ad6b6e4f72a82122366695b4d5c332490fe8caf98b3e77749ac06fcaa0a1be7e283201e7dd0ec43cb728da2597af4a4d1d20836d1d443c6fd24d57881ec9b9d0af6b99f04511ba2f526c1647f0c67328f7ea7952bbeaf41198ba56ddeca73e8f1e028d64c9e8bc9515aa9f16830add7c705d6aa4fbf20ba5aef213088d6e4ef4453dfe0b0c531ea19ba772969881e5945e353b43ce2940d9b6898855092f6426b32ff0f1037e1d9799e30d93b1b1df71b70bdc52fcd9db0cc87c55894244da38cc6534dae903d84f7b636cac2d26ee2ee3c60a60c9482dcf3ad679936b6fb4e6a16bd3275f6452a0a47dc0f5acdcf9fe17c9fb34ac669ff277964d5d77062d4dc69ffb3f376665972fc8300df0d3eca41c769891013cb14d70b7600300d030e3ad5d6f9394786551857c5beb49c0eab658b6253ad647365912062b1895ceb0e5ddcfbc73034414bb7eef9bc7a201f735d67edfc7c07c89f3ea8a98bdef324f606ed2b4b3989d0d019b73cd8ac9bdf062c53a40c13ca97f848e152756c388bc54d4ec86104962ea8df3a9430ee4f1bf6eb57862faf2cd49e21db5982dfb5386a23b47b4d010b4ad79f600161ba2d5307b9199977493c1e8a696d2aed4b85d7d52074438c76203baaa50bd96f5d2c9063b4e3033f090021c996261344e44aece16bf926614a5163b70d7f6a03d13462e0858b1911763700503b96505f471bf084d966dd7cd8603e3ffb9b22c572526526d8568e6bb55fa77bfe334ffee4edab2a58719aab70e9e8e8102eadb5391d6a188006a42daee2b2ca71da99b80360fadc4710e7a33d8c3173cc69b5824d93b5021718a276b0ab706029d4378df2fd1183cff056d463a2984c5aa397b9cafd1d3e4a209c04e499130980265d5e2930638bd12656145667bf0dfa09bb61c5c6801d158fead98b3ccc6619c5ff643bc629a57cd6e9b535033d29d4ebdfcff607c50b6ff979fd22fc1a07d796672d98d8b2be6c6c4a4f4911179d18cb29c4c8c490a091d334975033e2ae1a0db38f77ee252f22d4555d0202b39671b6ff29d564cf7b0252ed748cb1a5770bb5aa913d37a7e6e86814e1f34baa5ce474fdaca3bb316cebc4e7893c6452d856a4245434b26b52a37d8aab8f5da3a325e313858e40a9405307de7f4e80d25b3cddea6c75f8595a1c235005a3f0fc948019cfe9e68e3cd0a2affb2f073374d0a03ac55ce9644a92b28409173f763e6a1f7946c1d16ac14a792bd5aea57e404d8a684bdea0b430572d2e5034c949e6c9e74a989d0f91dd740b174e4853e2e693c011d2d29e50bef9fee62079eafe87516448c5a045a16eb569314c9410d4363619ea19aee6460e72440d1cc2a368429c99f10dc8707662d64262113d8eda7842a6233e9ec5c1f7d8c71dc6efedc4bfed53fa9646171caa26daaa0bf4ce50d7b02864ffa0d860014e4d08425f0c1fb840d69a55ec84a833b45dd4572d05d2bcd7dbc6a78974dd2ed0bd52a0343fbd5421c05900da0b7c4e9e42e59183bd2f6e5058482fdd165e346b3ca22f35934538e97110321709394ee446087d97630aa17305fd5d1fd697a4ff3477fc7d02a65afd16e2a5aeccf9402c9dc90f4550140b6bebe6554203e44b9b02472a47c524f4a9554dc25484eb8f173a878a975cdabdfb7993b5e097dc04ef93a7833e51a61b64a6b62743252bf60bf665b9c398688eb24db0d8d2acea848859864f426c08649d29aa7e1d1027318d55624ef750572616ca5b5a118afb83b6e0c872c29a5388f954fcaf8f6d0e67396bd54b9115abe02ffdf52878cd55cb0c5d97cedf41794880ca2b88f960a37d0241ad3e268b3ed142285cfb464c9b0917234df19aa37daa95b935b9f035687d1ac0b7334855e5bf0473175d54c31cf520735d04f5b4ac272cb57999fbb8cf49bd5de6b44616c6a103f53dfc86f874cd847c5adda25c50f3615c0c9c63b34c32142ed62e49f72921fd35753e0ec9333add42838b383684e5246c154cd3ff6310933a36798a4020a027e8f0f951f0dc2dcdb26f0922c69a8dee7183332aa534fa25523469e7bca5917f37fc822b4e7ea5123ef1b8250b2d3dfc9c24ade46394ade3694d528db41108801c3618fd98878e837794023e5ca756e584fd2853829c53380bbb8a281998db43e3ee44e4e6cd08a46c958fee413af351467b7c8275f4c74d4111614eb90b3b10c044c88e1c00f3c2b7959b71bbabb25afa0f564b1449ca585066cd77721fbde395a2c6337be3d546a58498c5f21abf8177c7299fca76e4ae951847858f50fb07cfb10744b770f115e35f57dc70858cafe3a9f66fa406b8a5da94a07699672eefb557fa6adbea267961fd9e4af73a1efdea261a249a573258dae670de24a3d96f36cd146d02370921cacdc155b30a80ad5b43c5db9390ee94e5fcb33b574f82e039371d25fe1128effcb536d5d53727ef341043dd7b07db4c41c117356b3c5379e486f19a4bdef1d3afd4cd0f5fced5a2fba436ee2b84d0b326cc4fe19e69ce05906d3e36c62d9b9a4695bd3ec0d0e5c5e8578dc36094fe879702cf95577a2616244fa3dd7f07c998836793f367d973f640138896f18461b877df9c5a86b046bfab5ac5692d85c5ae632ac51dd726aea59ff471e3f50579204ba6c5868530205faaf81821a57d462ffc697bdd82ba50edd8d3d7973235b57be2d0f9a84ded1d0f3cb68555c2300987f2d14768d2f0214abaf29a06d5d37c5296b5c2db62b2169e1a7bd425cef00db2745d5e246f66191c522f58f0c14fb1d1c8fe6b5b95a45570334125c190a3a9a3e77deb9ae7ca45d973fc64a89d2bb6420286ce01649d5de80ccf89d34bc0c2d9e49d8ec713d2c83286bded0d30a8c42740678c6538d8a7e491b2d1007df7d5037016018c6bd36a21247c13c1cccad168a6a0c2dab4c01185b6d61c31f0f2410b83c16a58d7cdcc0f2522fbe62fb27b1094f77229bff259433e9265d5656931b6d47210bd1e1a66a6c6a3dc9c6a2912a8fc1f05eecf40b751555e569ac2f92d1e5b540037c0cf5c9e658a17fb9dabdd23a087ebb90411f5e75f70bc7786855a2adbebd889d1946ecd6be827e2a624e256c36226ec87f2b92f978be8ffa98169f8dd4947390509d2397322da63757dff25a86f9872414209c50983c570558fc1a630d3caa8f6a59a16cd024f00b2323d2884187ec92feb19e078690f51940229c6076dea7064e71fcc6c55ffd643ccff5b63020003f6512e0b2e6dd0d8cf0a8cde59f4ae60632a902889a27e469b0e844d8477b471a779f720b7650e56645f8a044bebcf4660405a5185e75d13d0c15a221fc707860cfc260b9f9ab3c98e616cc574bd05a494faea98c1e06f9c7ff9643b72692a4afd4e1060330000000000000001cda9b801f96b13ea639d611a15e8f3e899ccf6718b7add1e0309d6c16a3f9b5699cea2fe90fb96147e22f3b025013bb9e7e824614a2c2c2e2e9a420a98b91d71170d89e7aebb414266337a636ec3031021a51701dda9113e9c1ce1291fa9ccab9dd8f30ab98d9c5ba12894af05b42573202c8a5a35d4a49dea9873c2f9aa51ee263a10e49cced91debeff76caca98e07cb7e7705fb647f3ea846cafa1ea4e8449022aedc5210ac18c0a2585a435cc2249cc997aa7e2e180fcee7ee92b1dfee29b3fb125c3d78938b8e6cec68f9fa16643460617013d0bf65b453a124fb843326020adba9ea96bb1832cefd6ac4126329187329b1f31f713b097d34cd2be2c42b70db5e5153a7c5508496f4608c8b7c1c3d8fa7dad87c76c06c278caf0a429d49f4d4fe367894ed493b1e91f331e0533b8364241527adbb867a29bb47fa8e8b5156d5c0ec9042c900f5b9bbe352488b0c671bcd381f090b7fd5ce469d21e01cf5b3f01fcdd51b3fb0eefb4145de49a9444ab161522dbd465169f6d9814b2646142fcc9020aee9742246442a63486e80aa341c81be71f8568080f7d700308f0f79dd8295345da0bd852f5aca16e5fc0e686d7642ef70f46f6d836f3a5bd2b14919fcd5e55ed2dfa8d6920681cc26d1a31f68bf6580c6693b8b877630746cf3a4bea53b4862872941f535345e69a7e7f0108cc72b741a952f4aee5436e918c6fae307277cf20b1fc4035f9235b82c18a24e3159563afd240b0cbe671f2138e6d3b9a4efb5e073b5428e4073a3610c79643b441165121d2d85a311f334b751fac62afec8e1bab82138c5ccd2154f1e00d11e00fae9fc1621ed68e1a32c71b7bd98d5d6328bf7bb3ab5227391eed36335fccd1f83a4b6854a2ddeca1942f8478391be3468693cec629918dd66f00f3a520b495c7f6eaa22aa90a3ee22f29c9ff4e473b739e7a7581411ae966f0d5aa9f157d33066f868a39a0af75199fe886d62c8112ba5242becc11cbbf038c28c41674c643d24448ec7336c98dec3ce09db944476df456e661dec9ffe471243b16888496d17093cb21f0cf5360c884107ed584a24ea151f6f91ddbf92848afe9ca936aa68f992d13aa42e470284454e3b7fe31ec28c33480cbd17d44b941f4f99fe269aa51319cdae2f454d548a41d801061beb6466cf3c27c0efdbf4ea556d57dfd9f52798214f73c3506525426a59820d037285f61465a141e394de9970b6c9b6297ada4d4d65fc5b9921a8f9e6aad8a9ab2d587f193b741c8e5ed879498e7374bf1744f6a72566745e21012cec8412ea8b8eab9712c740cc71c1c798c1d2df850426f69ce311ff1f537b87ae9a31935525eda54780f15dc73214043ece83f1629e36c55747af1ad8e84fa5e535422b09db9a3145022691e189c9ccbacae70ebea3f6b5f2e09376b6402767c85a2ede43761b4ee5edb436d9f711dfdd84e1ff0dbd35c607ea59d9d5c8adf7fa4bf08634e8cb5027da6bb8a8cd7ba1e87c40be3bd9c5554fae6bf7683d25a57320b63d20c66f0df976dbd688e8c4ccf0dbe755f0d31fd6d1b81c6f1ea0538f73c99cd239efbe92b32b946f07b8b53aba95f05d9e0686e188027061c0c912bf2c27cb83a46cff714e57e4f072bd1df08e23640bb64143ee7c866097f8d360800abbff28a94ef7b035563ce396c9c68ee5c7751c070c364e0fcfb015749b480a8bf4cd9626541e40af879213812612c2e04d688629239f609219a45657693c4cb81c85e156a0c9b377d6123340f009a265cec1a2fde0dfa4676b80dec9b6544712b202cec1467d8f440c2c2a1d13862fab29cb266e9185ed6bbb2c3f3e168bce4720ae079194948d41ed8bf7913fa1d9d8c0dbd39e4f7855f807f6192d3269fa0a98a3d6c27992798b70b59e04dd63918c7ca99054abe15fad0f567d9e993ca49eae695a820552575ee569c4aae328c5db0c3d04d1692ff561064345ed32571d072ea4a2613ce163022287b86b9797223619e556f978deb6711051eab698b43fcac2d62729addc0d699f775b516ed1952af9c5faad43601a4a23007ee2d6fbb10316bbb047e04596a57d5ee871496f85ea460f3f078e6c5a3f629aa6b67e4dbba3ace0a3ebf870a2800a5c7f27a866f6d58b33b1daf49c27a0e8057c169eb9be30d3a42e92676f45be824c12aee3f35a59e1cd23bb39e0ab5a87d43e5894e7aedfa7e74ee6554873db5646eb0e7d2b79f970c4210bd9be2b9294284aa26156ba9773c3422aac0489ba21878bf569c79cc548519221c3c90a706460a2d32e073564d7b6133ef25e14a6e327bc15e33555a299251ca49006225b18d8890b45b49e8c16aab18b6e7ba1e932750e81de679d7b6dff571a4cdf737e06eeec7cbac678b8a58e2142615b71cce7f26187a9c1490407b32c48783bf848a830a41ae89989fe68e50307044c34ac27f360b3679b1e4b76bf590cc131f2e25634c9979b4c98c392fa862cbda18e5c5ac0dd25f3ea6d9fe88691aa4d6399d4bc1da5218b95a8f8ab6683a1916eca043fbdb23137799f8e8e6e240ae4693e1896b942ae548a9e948ba77b2770ac8d98737bdb47d04e5c233da80d84c806e8585e73ab7d4f24ef5415a8ff01392e05b267159736f222a7e88652801cc7b9a3ce955494df7c556d1747255f9492da41ce8dc9a615c9b926f83436190e458f7b3994e425d560f35d3a79753e637c8f7dcfae559e8a76a956927c870e5f6da04a8fbb805253af55e52f3895811825d720e35e305c164ebad8a8f5535e6f1a9023bf6a6f1087361a93741a245b4b98920f539b21958c47b68e8f11bd764b10fba33c607fc70b126263a07216d72eef2d432083a6e373747e345cf6f9362a9bcd52e865062cb026484a21a5794dd4a1171560caec70cb607c324537007b74a36a1ec02033d8fe76196854c4158c47d0535a98eb15b74e347ec308728a32f7b75f06f3ee753cd0598ecc47a563978eba8535eaa012ae9555551a1c3f39c1fadbb66b08cf6f560a820fc4ae281f2bf57fb092f4d2c61568192483e86e65d5d58e86b1a873d06541227228209a98050728216b70185cb0243b893882db43e9a7aaeea366b2dbb13e9c3e707f1be4473d790d676695f1ae7bf1064c6f0a38e8706d37b652cff8e9e1979236a1482dcedb391f7f62da88843221043e472328e7b3fa57e7e06e4eaad1afe822f65002b18382ee5ccd890bd84f26ab467bef4265828e7331c31f119beadf4dca3773ff4a1f1b55b6377bfd9ff5277e740e2c60faa7111547f3ed0325a509582c4185de57a7f0b97b841736df3e69f7f73dfd831967ca615e29c4ffece4c229a3da65ce8e9e7bf12ae10b338290fd80f887cd11cc452ac0b89800c1694e38fbae1d83d7ca0112ad57797354315adceecef61c35fecf618144ed59f84c6f5b9be75de6aa218616bac4eade6dd148b9d692f5df6dcded45b3c3e4a3d679ac91a4eff540f608a86432a749aa119db5e3ea92ceec1ffea5c467bdd5dd3798dd8893e8e3972709025619cada7a880f675faff2a257e18164dbfb1752cfbd5dd8194cfca896298165c0dc4369724b59af981350c4514107c8ff09fa39eed4d76e636a21cdbb3e0c0e5e8f510d087a591135b52f974576432d3e3bf2f46b036c7e140547f96ebabfd0cb242102b3f66aee8560be27657d0900494c33eb8a02dd36b8d8b0e6df3d9931fceeefbc32590050838eec27fa778ae6347102442dd21e300b50faf8fdfabbc1161a6bfe5bc795fbcda8994091ee954edf66f1ba75c4acf7965b31d56db077396bb1e7e9c8286e63e54b34cf5ca11bd8998e40f2c4594c55d7fa8fc2cf9476612d567996307d21caf06e49daf16300bc1f70d70d145e64d92a0b307df6a3d3554d6ccd0c550ba193ff6b818c6f2b0008f17359e8617aa927b9f771203faf28c2a04116f8f048ab0228adad39c8aa3e8c8381b1e60886138face97ae7f3c02d2ef854fab2ef27425b23fcf05bcbeb3d752db854313084ddf7a8833369c17123c92d63c744df22ffaf10188b2f4f4cdb53e5f530279d4419b0858d44a8a8f76a26b78be327bd233bf12709ea04a4cc6b6ccfb20808519f316d293bb4d605e4cee8373202f4e95e28bfef9c42354672526a7a81391239783b64d74c2b04686438411614e7228d34e457151f71d742bc514aedfc96966ea35297d5efa513e8dbbc10e8e16eac2ae14848a20c165f59f1362b57b457f6786b0e1fd492ca47d6aba03774e58f4e09fb480156b9c96ddd13c441fc8202e40a12b30396482778ebc439b5abebcd140ad3848726b2908f6b594e0ac7b307857d68fad4ab05e4362140ad2e4b4606e365e894224dfc033f4c069dafdd7f819d340f6a202592243a27f67a38f20e5b07136f5b503c3ca209736c0a7b99749a9d36a82b2a6926a426c95b5f60c835ab85038469e1e5bce2b6bc2d47345d8f1beed8e678423ca3db106b554890e8a701e5d43f6358d957b8c799d1cf20da1f577df0261717227113e5d1127849bccc076947beab3e3aed964b83c94de9322591b67d6fad860d5a5c642a545aee2d1ee6756723a96d74ae2f431876fce6d8da50628fc51560760c97aa66a258f41a9d958a1e3bb0e27a58eda5f6806a115ac6aadab545aebe2d9c6c6c01cb2dc7e8b36c7b37609563f84f409b0813047fea9220872becbc9cd976d502576d1dc2a0a5612a7a1452e46b35149528ed2cb74b18a221c2281d7b766d28a30f763d7375f6242f4c361807efb711d21426696f77606cf1c37c4c162fe79e444c622297b0849c88995cf248a47c49d1932b6ee79c2c2f3dc77fe97389855c50cb797b0fddaa94c31d5b23f4b7f7d24131aa24d6d53e9a43a3e2c360c3254573355ddbe850299f7ad13f8d0676c8a39ee2a63ec700eb3b53d9abee536a6a2bef272527ede483a09913d8d839cf69c828654ccac0581552b342b0735f49cd5af77bca8e8926173e58320fd4738e574114736cd480900c001766cc72266f7c7ee34dd27a109ad4e932c28d0ce1292df46a0df42f23a48531da38ee14bae23d27e3370434efb85546c5e53c10e8407084e833a65a91d07df741174fbdd7e1e5475d273b1c30fc3db1227d32739889b45ac3ce208f82523d51e2c5a54b6c325ed1fbda4748b61090a838bdc5ebdbf1eb2280ad73028ed8ec40fda49cdf17ce0e158521ea5c99cb8fca79a91e7a4011e6aefa4235b4cdd5344356ed7fb31b1e575592fa2dd89c0a2ce151e07d049d67463d6fff3b2b830451fd89c596d9c807f57aba74fba0a24649e27c849376ab134c5c7f501fd1746b75866f3e74f854029e2e73455a60ec76df9df208b8ce5feccf2b6a2bb743e461924cbd22b91c9e89dcbe231474f26678dd91bda846034f4d55ae97aa1a569c5a3bbb399682ba6b066597a1be9d9a1612cf3faa7cd9b0dc9a3d47c9e382604d7004bb10b2e29fadfa2e374c806a1c7f95b169c4e461bcbe907d3a7ffa6af042f351fc908dd67c522802f0ef18eb57ecfc6f2e95322928e5b561d715a29667ee44382be6eba5ea8577fc926ba742d0d1f345263991610174ec46c5989d8546cd37904089d5327e0787d136d3b13412b536bbdc385990ed35cf6454874c9ce362acb0a8146f78b3f20140c34519c9be23051ad0e0620d50dc3319bfe072c46952cccfa44a62c7afeb9bd596673dcaead2a279175b9324c922a6c17959eef9e6b15a1d952bdbdd74e6eaca13735db8132e0c26fd8eaac1acc66feb76e62760e6746dba93492891a048babd276ae5c4ec2fdd0afc8c1e570a2be342e6d98c3ed004e627ce95e06770227f7b6976a0b2b8e2769e8a1061b15834582c581cc36c0e28909153881e4ee0f8770392a04b3459b1bea67a4f4a68270000" ).unwrap(); let transaction = @@ -86,7 +86,7 @@ fn main() { .unwrap(); // Get the previous confidential amount - let conf_val: Vec = elements::hashes::hex::FromHex::from_hex( + let conf_val: Vec = elements::hex::FromHex::from_hex( "080e8899a3c271573359a179b27b59af180b36461f959ee00f762d9c2d84192a06", ) .unwrap(); diff --git a/src/descriptor/csfs_cov/mod.rs b/src/descriptor/csfs_cov/mod.rs index 6ed21743..1714be30 100644 --- a/src/descriptor/csfs_cov/mod.rs +++ b/src/descriptor/csfs_cov/mod.rs @@ -59,12 +59,12 @@ mod tests { use bitcoin; use elements::encode::serialize; - use elements::hashes::hex::ToHex; + use elements::hex::ToHex; use elements::opcodes::all::OP_PUSHNUM_1; use elements::secp256k1_zkp::ZERO_TWEAK; use elements::{ self, confidential, opcodes, script, secp256k1_zkp, AssetId, AssetIssuance, - EcdsaSigHashType, LockTime, OutPoint, PackedLockTime, Script, Sequence, Transaction, TxIn, + EcdsaSigHashType, LockTime, OutPoint, Script, Sequence, Transaction, TxIn, TxInWitness, TxOut, Txid, }; @@ -191,7 +191,7 @@ mod tests { // Now create a transaction spending this. let mut spend_tx = Transaction { version: 2, - lock_time: PackedLockTime::ZERO, + lock_time: LockTime::ZERO, input: vec![txin_from_txid_vout( "141f79c7c254ee3a9a9bc76b4f60564385b784bdfc1882b25154617801fe2237", 1, @@ -393,7 +393,7 @@ mod tests { // Now create a transaction spending this. let mut spend_tx = Transaction { version: 2, - lock_time: PackedLockTime::ZERO, + lock_time: LockTime::ZERO, input: vec![txin_from_txid_vout( "7c8e615c8da947fefd2d9b6f83f313a9b59d249c93a5f232287633195b461cb7", 0, diff --git a/src/descriptor/csfs_cov/satisfy.rs b/src/descriptor/csfs_cov/satisfy.rs index c2cb03cd..6490c73e 100644 --- a/src/descriptor/csfs_cov/satisfy.rs +++ b/src/descriptor/csfs_cov/satisfy.rs @@ -133,7 +133,7 @@ impl<'tx, 'ptx, Pk: MiniscriptKey + ToPublicKey> Satisfier for LegacyCovSati } fn lookup_nlocktime(&self) -> Option { - Some(self.tx.lock_time.to_u32()) + Some(self.tx.lock_time.to_consensus_u32()) } fn lookup_sighashu32(&self) -> Option { diff --git a/src/descriptor/key.rs b/src/descriptor/key.rs index d08cc7c7..630e2252 100644 --- a/src/descriptor/key.rs +++ b/src/descriptor/key.rs @@ -1,11 +1,11 @@ -use std::borrow::Borrow; // SPDX-License-Identifier: CC0-1.0 +use std::borrow::Borrow; +use std::convert::TryInto; use std::str::FromStr; use std::{error, fmt}; -use bitcoin::util::bip32; -use bitcoin::{self, XpubIdentifier}; -use elements::hashes::hex::FromHex; +use bitcoin::bip32; +use bitcoin::{self, hash_types::XpubIdentifier}; use elements::hashes::{hash160, ripemd160, sha256, Hash, HashEngine}; use elements::secp256k1_zkp::{Secp256k1, Signing, Verification}; @@ -19,7 +19,7 @@ pub enum SinglePubKey { /// FullKey (compressed or uncompressed) FullKey(bitcoin::PublicKey), /// XOnlyPublicKey - XOnly(bitcoin::XOnlyPublicKey), + XOnly(bitcoin::key::XOnlyPublicKey), } /// The MiniscriptKey corresponding to Descriptors. This can @@ -388,7 +388,7 @@ fn maybe_fmt_master_id( ) -> fmt::Result { if let Some((ref master_id, ref master_deriv)) = *origin { fmt::Formatter::write_str(f, "[")?; - for byte in master_id.into_bytes().iter() { + for byte in master_id.as_bytes() { write!(f, "{:02x}", byte)?; } fmt_derivation_path(f, master_deriv)?; @@ -461,7 +461,7 @@ impl FromStr for DescriptorPublicKey { } else { let key = match key_part.len() { 64 => { - let x_only_key = bitcoin::XOnlyPublicKey::from_str(key_part).map_err(|_| { + let x_only_key = bitcoin::key::XOnlyPublicKey::from_str(key_part).map_err(|_| { DescriptorKeyParseError("Error while parsing simple xonly key") })?; SinglePubKey::XOnly(x_only_key) @@ -548,7 +548,11 @@ impl DescriptorPublicKey { } SinglePubKey::XOnly(x_only_pk) => engine.input(&x_only_pk.serialize()), }; - bip32::Fingerprint::from(&XpubIdentifier::from_engine(engine)[..4]) + bip32::Fingerprint::from( + &XpubIdentifier::from_engine(engine)[..4] + .try_into() + .expect("4 byte slice"), + ) } } } @@ -751,7 +755,7 @@ fn parse_key_origin(s: &str) -> Result<(&str, Option), Descrip "Master fingerprint should be 8 characters long", )); } - let parent_fingerprint = bip32::Fingerprint::from_hex(origin_id_hex).map_err(|_| { + let parent_fingerprint = bip32::Fingerprint::from_str(origin_id_hex).map_err(|_| { DescriptorKeyParseError("Malformed master fingerprint, expected 8 hex chars") })?; let origin_path = raw_origin @@ -897,7 +901,7 @@ impl DescriptorXKey { /// # extern crate elements_miniscript as miniscript; /// # use std::str::FromStr; /// # fn body() -> Result<(), Box> { - /// use miniscript::bitcoin::util::bip32; + /// use miniscript::bitcoin::bip32; /// use miniscript::descriptor::DescriptorPublicKey; /// /// let ctx = miniscript::elements::secp256k1_zkp::Secp256k1::signing_only(); @@ -1158,7 +1162,7 @@ mod test { use std::str::FromStr; use bitcoin::secp256k1; - use bitcoin::util::bip32; + use bitcoin::bip32; use elements::secp256k1_zkp; #[cfg(feature = "serde")] use serde_test::{assert_tokens, Token}; diff --git a/src/descriptor/mod.rs b/src/descriptor/mod.rs index 1c07c6dc..acbd7ce9 100644 --- a/src/descriptor/mod.rs +++ b/src/descriptor/mod.rs @@ -20,7 +20,7 @@ use std::sync::Arc; pub mod pegin; -use bitcoin::util::address::WitnessVersion; +use bitcoin::address::WitnessVersion; use elements::hashes::{hash160, ripemd160, sha256}; use elements::{secp256k1_zkp as secp256k1, secp256k1_zkp, Script, TxIn}; use {bitcoin, elements}; @@ -861,7 +861,7 @@ impl Descriptor { } /// Convert all the public keys in the descriptor to [`bitcoin::PublicKey`] by deriving them or - /// otherwise converting them. All [`bitcoin::XOnlyPublicKey`]s are converted to by adding a + /// otherwise converting them. All [`bitcoin::key::XOnlyPublicKey`]s are converted to by adding a /// default(0x02) y-coordinate. /// /// This is a shorthand for: @@ -1140,7 +1140,7 @@ impl Descriptor { impl Descriptor { /// Convert all the public keys in the descriptor to [`bitcoin::PublicKey`] by deriving them or - /// otherwise converting them. All [`bitcoin::XOnlyPublicKey`]s are converted to by adding a + /// otherwise converting them. All [`bitcoin::key::XOnlyPublicKey`]s are converted to by adding a /// default(0x02) y-coordinate. /// /// # Examples @@ -1279,9 +1279,9 @@ mod tests { use std::str::FromStr; use bitcoin; - use bitcoin::util::bip32; + use bitcoin::bip32; use bitcoin::PublicKey; - use elements::hashes::hex::{FromHex, ToHex}; + use elements::hex::{FromHex, ToHex}; use elements::hashes::{hash160, sha256}; use elements::opcodes::all::{OP_CLTV, OP_CSV}; use elements::script::Instruction; @@ -1420,7 +1420,7 @@ mod tests { .push_opcode(opcodes::all::OP_DUP) .push_opcode(opcodes::all::OP_HASH160) .push_slice( - &hash160::Hash::from_hex("84e9ed95a38613f0527ff685a9928abe2d4754d4",).unwrap() + &hash160::Hash::from_str("84e9ed95a38613f0527ff685a9928abe2d4754d4",).unwrap() [..] ) .push_opcode(opcodes::all::OP_EQUALVERIFY) @@ -1445,7 +1445,7 @@ mod tests { script::Builder::new() .push_opcode(opcodes::all::OP_PUSHBYTES_0) .push_slice( - &hash160::Hash::from_hex("84e9ed95a38613f0527ff685a9928abe2d4754d4",).unwrap() + &hash160::Hash::from_str("84e9ed95a38613f0527ff685a9928abe2d4754d4",).unwrap() [..] ) .into_script() @@ -1468,7 +1468,7 @@ mod tests { script::Builder::new() .push_opcode(opcodes::all::OP_HASH160) .push_slice( - &hash160::Hash::from_hex("f1c3b9a431134cb90a500ec06e0067cfa9b8bba7",).unwrap() + &hash160::Hash::from_str("f1c3b9a431134cb90a500ec06e0067cfa9b8bba7",).unwrap() [..] ) .push_opcode(opcodes::all::OP_EQUAL) @@ -1493,7 +1493,7 @@ mod tests { script::Builder::new() .push_opcode(opcodes::all::OP_HASH160) .push_slice( - &hash160::Hash::from_hex("aa5282151694d3f2f32ace7d00ad38f927a33ac8",).unwrap() + &hash160::Hash::from_str("aa5282151694d3f2f32ace7d00ad38f927a33ac8",).unwrap() [..] ) .push_opcode(opcodes::all::OP_EQUAL) @@ -1517,7 +1517,7 @@ mod tests { script::Builder::new() .push_opcode(opcodes::all::OP_PUSHBYTES_0) .push_slice( - &sha256::Hash::from_hex( + &sha256::Hash::from_str( "\ f9379edc8983152dc781747830075bd5\ 3896e4b0ce5bff73777fd77d124ba085\ @@ -1545,7 +1545,7 @@ mod tests { script::Builder::new() .push_opcode(opcodes::all::OP_HASH160) .push_slice( - &hash160::Hash::from_hex("4bec5d7feeed99e1d0a23fe32a4afe126a7ff07e",).unwrap() + &hash160::Hash::from_str("4bec5d7feeed99e1d0a23fe32a4afe126a7ff07e",).unwrap() [..] ) .push_opcode(opcodes::all::OP_EQUAL) @@ -1640,7 +1640,7 @@ mod tests { let redeem_script = script::Builder::new() .push_opcode(opcodes::all::OP_PUSHBYTES_0) .push_slice( - &hash160::Hash::from_hex("d1b2a1faf62e73460af885c687dee3b7189cd8ab").unwrap()[..], + &hash160::Hash::from_str("d1b2a1faf62e73460af885c687dee3b7189cd8ab").unwrap()[..], ) .into_script(); let expected_ssig = script::Builder::new() @@ -1889,7 +1889,7 @@ mod tests { let key = "[78412e3a/44'/0'/0']xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL/1/*"; let expected = DescriptorPublicKey::XPub(DescriptorXKey { origin: Some(( - bip32::Fingerprint::from(&[0x78, 0x41, 0x2e, 0x3a][..]), + bip32::Fingerprint::from([0x78, 0x41, 0x2e, 0x3a]), (&[ bip32::ChildNumber::from_hardened_idx(44).unwrap(), bip32::ChildNumber::from_hardened_idx(0).unwrap(), @@ -1974,7 +1974,7 @@ mod tests { .unwrap(), ), origin: Some(( - bip32::Fingerprint::from(&[0x78, 0x41, 0x2e, 0x3a][..]), + bip32::Fingerprint::from([0x78, 0x41, 0x2e, 0x3a]), (&[ bip32::ChildNumber::from_hardened_idx(0).unwrap(), bip32::ChildNumber::from_normal_idx(42).unwrap(), diff --git a/src/descriptor/pegin/dynafed_pegin.rs b/src/descriptor/pegin/dynafed_pegin.rs index c874ea73..97386573 100644 --- a/src/descriptor/pegin/dynafed_pegin.rs +++ b/src/descriptor/pegin/dynafed_pegin.rs @@ -20,11 +20,12 @@ //! Unlike Pegin descriptors these are Miniscript, so dealing //! with these is easier. +use std::convert::TryFrom; use std::fmt; -use bitcoin::blockdata::script; +use bitcoin::blockdata::script::{self, PushBytes}; use bitcoin::hashes::Hash; -use bitcoin::{self, hashes, Script as BtcScript}; +use bitcoin::{self, hashes, ScriptBuf as BtcScript}; use elements::secp256k1_zkp; use crate::descriptor::checksum::{desc_checksum, verify_checksum}; @@ -186,8 +187,10 @@ impl Pegin { let witness_script = self .bitcoin_witness_script(secp) .expect("TODO after taproot"); + let push_bytes = <&PushBytes>::try_from(witness_script.as_bytes()) + .expect("Witness script is not too larg"); script::Builder::new() - .push_slice(&witness_script.to_v0_p2wsh()[..]) + .push_slice(push_bytes) .into_script() } diff --git a/src/descriptor/pegin/legacy_pegin.rs b/src/descriptor/pegin/legacy_pegin.rs index f9a23bb1..6f7dbbe7 100644 --- a/src/descriptor/pegin/legacy_pegin.rs +++ b/src/descriptor/pegin/legacy_pegin.rs @@ -22,13 +22,15 @@ //! Thus, as a simple solution we implement these as a separate //! struct with it's own API. +use std::convert::TryFrom; use std::fmt; use std::str::FromStr; use std::sync::Arc; use bitcoin::blockdata::{opcodes, script}; +use bitcoin::blockdata::script::PushBytes; use bitcoin::hashes::{hash160, ripemd160, sha256, Hash}; -use bitcoin::{self, hashes, Script as BtcScript}; +use bitcoin::{self, hashes, ScriptBuf as BtcScript}; use bitcoin_miniscript::TranslatePk as BtcTranslatePk; use elements::secp256k1_zkp; @@ -227,7 +229,7 @@ impl LegacyPegin { .push_int(self.fed_k as i64); for key in &self.fed_pks { - let tweaked_pk = tweak_key(key.as_untweaked(), secp, tweak.as_inner()); + let tweaked_pk = tweak_key(key.as_untweaked(), secp, tweak.as_byte_array()); builder = builder.push_key(&tweaked_pk); } let mut nearly_done = builder @@ -267,7 +269,7 @@ impl LegacyPegin { let insert_point = nearly_done.len() - 1; nearly_done.insert(insert_point, 0x68); - bitcoin::Script::from(nearly_done) + BtcScript::from(nearly_done) } /// Create a new descriptor with hard coded values for the @@ -436,8 +438,10 @@ impl LegacyPegin { Pk: ToPublicKey, { let witness_script = self.explicit_script(secp); + let push_bytes = <&PushBytes>::try_from(witness_script.as_bytes()) + .expect("Witness script is not too larg"); script::Builder::new() - .push_slice(&witness_script.to_v0_p2wsh()[..]) + .push_slice(push_bytes) .into_script() } /// Computes the bitcoin "witness script" of the descriptor, i.e. the underlying @@ -471,7 +475,7 @@ impl LegacyPegin { let unsigned_script_sig = self.bitcoin_unsigned_script_sig(secp); let mut sigs = vec![]; for key in &self.fed_pks { - let tweaked_pk = tweak_key(key.as_untweaked(), secp, tweak.as_inner()); + let tweaked_pk = tweak_key(key.as_untweaked(), secp, tweak.as_byte_array()); match satisfier.lookup_ecdsa_sig(&tweaked_pk) { Some(sig) => sigs.push(sig.to_vec()), None => {} diff --git a/src/extensions/arith.rs b/src/extensions/arith.rs index 43d2eeb5..92485caf 100644 --- a/src/extensions/arith.rs +++ b/src/extensions/arith.rs @@ -4,7 +4,7 @@ use std::convert::TryInto; use std::str::FromStr; use std::{cmp, error, fmt}; -use bitcoin::XOnlyPublicKey; +use bitcoin::key::XOnlyPublicKey; use bitcoin_miniscript::MiniscriptKey; use elements::opcodes::all::*; use elements::sighash::Prevouts; @@ -1631,7 +1631,7 @@ where #[cfg(test)] mod tests { use bitcoin::hashes::Hash; - use bitcoin::XOnlyPublicKey; + use bitcoin::key::XOnlyPublicKey; use super::*; use crate::extensions::check_sig_price_oracle_1; diff --git a/src/extensions/csfs.rs b/src/extensions/csfs.rs index 9d935dba..b8195f75 100644 --- a/src/extensions/csfs.rs +++ b/src/extensions/csfs.rs @@ -4,9 +4,8 @@ use std::fmt; use std::str::FromStr; -use bitcoin::hashes::hex::{FromHex, ToHex}; -use bitcoin::XOnlyPublicKey; -use elements::hashes::hex; +use bitcoin::key::XOnlyPublicKey; +use elements::hex::{self, FromHex, ToHex}; use elements::{self, opcodes, secp256k1_zkp}; use super::param::{ExtParamTranslator, TranslateExtParam}; @@ -201,7 +200,7 @@ impl ArgFromStr for CsfsMsg { /// Wrapper around XOnlyKeys used in CheckSigfromstack #[derive(Debug, Clone, Eq, Ord, PartialOrd, PartialEq, Hash)] -pub struct CsfsKey(pub bitcoin::XOnlyPublicKey); +pub struct CsfsKey(pub bitcoin::key::XOnlyPublicKey); impl fmt::Display for CsfsKey { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -216,7 +215,7 @@ impl ArgFromStr for CsfsKey { "Key must be at first position in csfs".to_string(), )); } - let k = bitcoin::XOnlyPublicKey::from_str(s)?; + let k = bitcoin::key::XOnlyPublicKey::from_str(s)?; Ok(Self(k)) } } @@ -349,7 +348,7 @@ where #[cfg(test)] mod tests { - use bitcoin::XOnlyPublicKey; + use bitcoin::key::XOnlyPublicKey; use super::*; use crate::test_utils::{StrExtTranslator, StrXOnlyKeyTranslator}; @@ -388,7 +387,7 @@ mod tests { let mut t = StrXOnlyKeyTranslator::default(); t.pk_map.insert( "B".to_string(), - bitcoin::XOnlyPublicKey::from_str( + bitcoin::key::XOnlyPublicKey::from_str( "9064b3ac01fb4cb648e8899723ee4d50433920ae558c572e96d945805e0bc3ec", ) .unwrap(), @@ -401,7 +400,7 @@ mod tests { ext_t.ext_map.insert( "A".to_string(), CovExtArgs::XOnlyKey(CsfsKey( - bitcoin::XOnlyPublicKey::from_str( + bitcoin::key::XOnlyPublicKey::from_str( "26d137d15e2ae24f2d5158663d190d1269ad6b1a6ce330aa825ba502e7519d44", ) .unwrap(), diff --git a/src/extensions/introspect_ops.rs b/src/extensions/introspect_ops.rs index d5bc9faa..dd3cd8b9 100644 --- a/src/extensions/introspect_ops.rs +++ b/src/extensions/introspect_ops.rs @@ -4,10 +4,10 @@ use std::convert::TryFrom; use std::fmt; use std::str::FromStr; -use bitcoin::hashes::hex::{FromHex, ToHex}; use bitcoin::hashes::{sha256, Hash}; use elements::address::Payload; use elements::confidential::Asset; +use elements::hex::{FromHex, ToHex}; use elements::opcodes::all::*; use elements::{confidential, encode, script, Address, AddressParams}; @@ -642,7 +642,7 @@ fn spk(pref: i8, prog: &[u8]) -> Option { // This converts legacy programs to (-1, sha256::Hash(spk)) fn spk_to_components(s: &elements::Script) -> (i8, Vec) { if !s.is_witness_program() { - (-1, sha256::Hash::hash(s.as_bytes()).to_vec()) + (-1, sha256::Hash::hash(s.as_bytes()).to_byte_array().to_vec()) } else { // indirect way to get payload. // The address parameters don't really matter here @@ -664,7 +664,7 @@ impl AssetExpr { AssetExpr::Const(CovExtArgs::Asset(a)) => { match a { Asset::Null => unreachable!("Attempt to push Null asset"), - Asset::Explicit(a) => builder.push_slice(&a.into_inner()).push_int(1), // explicit prefix + Asset::Explicit(a) => builder.push_slice(a.into_inner().as_ref()).push_int(1), // explicit prefix Asset::Confidential(c) => { let ser = c.serialize(); builder.push_slice(&ser[1..]).push_int(ser[0] as i64) @@ -839,7 +839,7 @@ impl SpkExpr { SpkExpr::Const(CovExtArgs::Script(s)) => { let (ver, prog) = match &s.0 { SpkInner::Script(s) => spk_to_components(s), - SpkInner::Hashed(h) => (-1, h.to_vec()), + SpkInner::Hashed(h) => (-1, h.to_byte_array().to_vec()), }; builder.push_slice(&prog).push_int(ver as i64) } @@ -864,7 +864,7 @@ impl SpkExpr { let res = match self { SpkExpr::Const(CovExtArgs::Script(s)) => match &s.0 { SpkInner::Script(s) => spk_to_components(s), - SpkInner::Hashed(h) => (-1, h.to_vec()), + SpkInner::Hashed(h) => (-1, h.to_byte_array().to_vec()), }, SpkExpr::Const(_) => unreachable!( "Both constructors from_str and from_token_iter @@ -908,7 +908,7 @@ impl SpkExpr { } else if let Some(&[Tk::Bytes32(spk_vec), Tk::NumNeg1]) = tks.get(e.checked_sub(2)?..e) { let mut inner = [0u8; 32]; inner.copy_from_slice(spk_vec); - let hashed_spk = Spk(SpkInner::Hashed(sha256::Hash::from_inner(inner))); + let hashed_spk = Spk(SpkInner::Hashed(sha256::Hash::from_byte_array(inner))); Some((SpkExpr::Const(CovExtArgs::Script(hashed_spk)), e - 2)) } else if let Some(&[Tk::Push(ref spk_vec), Tk::Num(i)]) = tks.get(e.checked_sub(2)?..e) { let script = spk(i8::try_from(i).ok()?, spk_vec)?; @@ -1218,7 +1218,7 @@ where #[cfg(test)] mod tests { - use bitcoin::XOnlyPublicKey; + use bitcoin::key::XOnlyPublicKey; use super::*; use crate::test_utils::{StrExtTranslator, StrXOnlyKeyTranslator}; diff --git a/src/extensions/outputs_pref.rs b/src/extensions/outputs_pref.rs index b035c2ec..1167140d 100644 --- a/src/extensions/outputs_pref.rs +++ b/src/extensions/outputs_pref.rs @@ -5,7 +5,7 @@ use std::fmt; use elements::encode::serialize; -use elements::hashes::hex::{FromHex, ToHex}; +use elements::hex::{FromHex, ToHex}; use elements::hashes::{sha256d, Hash}; use super::{ParseableExt, TxEnv}; @@ -264,7 +264,7 @@ impl ParseableExt for LegacyOutputsPref { for _ in 0..max_elems { stack.pop().unwrap(); } - if sha256d::Hash::hash(&outputs_builder).as_inner() == hash_outputs { + if sha256d::Hash::hash(&outputs_builder).as_byte_array() == hash_outputs { stack.push(interpreter::Element::Satisfied); Ok(true) } else { diff --git a/src/extensions/param.rs b/src/extensions/param.rs index f15a22f2..fa0cac72 100644 --- a/src/extensions/param.rs +++ b/src/extensions/param.rs @@ -2,9 +2,9 @@ use std::{fmt, hash}; -use bitcoin::hashes::hex::ToHex; use elements::confidential; use elements::encode::serialize; +use elements::hex::ToHex; use super::csfs::{CsfsKey, CsfsMsg}; use super::introspect_ops::Spk; @@ -105,7 +105,7 @@ impl From for CovExtArgs { impl CovExtArgs { /// Creates a new csfs key variant of [`CovExtArgs`] - pub fn csfs_key(key: bitcoin::XOnlyPublicKey) -> Self { + pub fn csfs_key(key: bitcoin::key::XOnlyPublicKey) -> Self { CovExtArgs::XOnlyKey(CsfsKey(key)) } diff --git a/src/interpreter/error.rs b/src/interpreter/error.rs index e093ae52..49e9448b 100644 --- a/src/interpreter/error.rs +++ b/src/interpreter/error.rs @@ -4,7 +4,7 @@ use std::{error, fmt}; use elements::hashes::hash160; -use elements::hashes::hex::ToHex; +use elements::hex::ToHex; use elements::{secp256k1_zkp, taproot}; use {bitcoin, elements}; @@ -30,7 +30,7 @@ pub enum Error { /// General Interpreter error. CouldNotEvaluate, /// EcdsaSig related error - EcdsaSig(bitcoin::EcdsaSigError), + EcdsaSig(bitcoin::ecdsa::Error), /// We expected a push (including a `OP_1` but no other numeric pushes) ExpectedPush, /// The preimage to the hash function must be exactly 32 bytes. @@ -50,7 +50,7 @@ pub enum Error { /// ecdsa Signature failed to verify InvalidEcdsaSignature(bitcoin::PublicKey), /// Signature failed to verify - InvalidSchnorrSignature(bitcoin::XOnlyPublicKey), + InvalidSchnorrSignature(bitcoin::key::XOnlyPublicKey), /// Last byte of this signature isn't a standard sighash type NonStandardSigHash(Vec), /// Miniscript error @@ -285,7 +285,7 @@ pub enum PkEvalErrInner { /// Full Key FullKey(bitcoin::PublicKey), /// XOnly Key - XOnlyKey(bitcoin::XOnlyPublicKey), + XOnlyKey(bitcoin::key::XOnlyPublicKey), } impl From for PkEvalErrInner { diff --git a/src/interpreter/inner.rs b/src/interpreter/inner.rs index 51c755a8..600a1dc6 100644 --- a/src/interpreter/inner.rs +++ b/src/interpreter/inner.rs @@ -2,9 +2,9 @@ // SPDX-License-Identifier: CC0-1.0 use bitcoin; -use bitcoin::util::taproot::TAPROOT_ANNEX_PREFIX; +use bitcoin::taproot::TAPROOT_ANNEX_PREFIX; use elements::hashes::{hash160, sha256, Hash}; -use elements::schnorr::TapTweak; +use elements::schnorr::TweakedPublicKey; use elements::taproot::ControlBlock; use elements::{self, script}; @@ -242,7 +242,7 @@ pub fn from_txdata<'txin, Ext: ParseableExt>( if !ssig_stack.is_empty() { Err(Error::NonEmptyScriptSig) } else { - let output_key = bitcoin::XOnlyPublicKey::from_slice(&spk[2..]) + let output_key = bitcoin::key::XOnlyPublicKey::from_slice(&spk[2..]) .map_err(|_| Error::XOnlyPublicKeyParseError)?; let has_annex = wit_stack .last() @@ -280,7 +280,7 @@ pub fn from_txdata<'txin, Ext: ParseableExt>( // This is fixed in rust-bitcoin. Should also be fixed in rust-elements if ctrl_blk.verify_taproot_commitment( &secp, - &output_key.dangerous_assume_tweaked(), + &TweakedPublicKey::new(output_key), &tap_script, ) { Ok(( @@ -434,18 +434,18 @@ impl ToNoChecks } impl ToNoChecks - for Miniscript + for Miniscript { fn to_no_checks_ms(&self) -> Miniscript { // specify the () error type as this cannot error struct TranslateXOnlyPk; - impl Translator for TranslateXOnlyPk { - fn pk(&mut self, pk: &bitcoin::XOnlyPublicKey) -> Result { + impl Translator for TranslateXOnlyPk { + fn pk(&mut self, pk: &bitcoin::key::XOnlyPublicKey) -> Result { Ok(BitcoinKey::XOnlyPublicKey(*pk)) } - translate_hash_clone!(bitcoin::XOnlyPublicKey, BitcoinKey, ()); + translate_hash_clone!(bitcoin::key::XOnlyPublicKey, BitcoinKey, ()); } self.real_translate_pk(&mut TranslateXOnlyPk) .expect("Translation should succeed") @@ -457,8 +457,8 @@ mod tests { use std::str::FromStr; - use elements::hashes::hex::FromHex; use elements::hashes::{hash160, sha256, Hash}; + use elements::hex::FromHex; use elements::{self, script, Script}; use super::*; diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index ad2c8e53..764edcaf 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -8,6 +8,7 @@ //! assuming that the spent coin was descriptor controlled. //! +use std::borrow::Borrow; use std::fmt; use std::str::FromStr; @@ -49,7 +50,7 @@ pub enum KeySigPair { /// A Full public key and corresponding Ecdsa signature Ecdsa(bitcoin::PublicKey, ElementsSig), /// A x-only key and corresponding Schnorr signature - Schnorr(bitcoin::XOnlyPublicKey, elements::SchnorrSig), + Schnorr(bitcoin::key::XOnlyPublicKey, elements::SchnorrSig), } impl KeySigPair { @@ -61,8 +62,8 @@ impl KeySigPair { } } - /// Obtain a pair of ([`bitcoin::XOnlyPublicKey`], [`elements::SchnorrSig`]) from [`KeySigPair`] - pub fn as_schnorr(&self) -> Option<(bitcoin::XOnlyPublicKey, elements::SchnorrSig)> { + /// Obtain a pair of ([`bitcoin::key::XOnlyPublicKey`], [`elements::SchnorrSig`]) from [`KeySigPair`] + pub fn as_schnorr(&self) -> Option<(bitcoin::key::XOnlyPublicKey, elements::SchnorrSig)> { match self { KeySigPair::Ecdsa(_, _) => None, KeySigPair::Schnorr(pk, sig) => Some((*pk, *sig)), @@ -90,7 +91,7 @@ pub enum BitcoinKey { /// Full key Fullkey(bitcoin::PublicKey), /// Xonly key - XOnlyPublicKey(bitcoin::XOnlyPublicKey), + XOnlyPublicKey(bitcoin::key::XOnlyPublicKey), } impl BitcoinKey { @@ -118,8 +119,8 @@ impl From for BitcoinKey { } } -impl From for BitcoinKey { - fn from(xpk: bitcoin::XOnlyPublicKey) -> Self { +impl From for BitcoinKey { + fn from(xpk: bitcoin::key::XOnlyPublicKey) -> Self { BitcoinKey::XOnlyPublicKey(xpk) } } @@ -234,19 +235,19 @@ where /// - Insufficient sighash information is present /// - sighash single without corresponding output // TODO: Create a good first isse to change this to error - pub fn verify_sig( + pub fn verify_sig>( &self, secp: &secp256k1_zkp::Secp256k1, tx: &elements::Transaction, input_idx: usize, - prevouts: &sighash::Prevouts<'_>, + prevouts: &sighash::Prevouts<'_, T>, genesis_hash: elements::BlockHash, sig: &KeySigPair, ) -> bool { - fn get_prevout<'u>( - prevouts: &sighash::Prevouts<'u>, + fn get_prevout<'u, T: Borrow>( + prevouts: &'u sighash::Prevouts<'u, T>, input_index: usize, - ) -> Option<&'u elements::TxOut> { + ) -> Option<&'u T> { match prevouts { sighash::Prevouts::One(index, prevout) => { if input_index == *index { @@ -266,7 +267,7 @@ where cache.legacy_sighash(input_idx, script_pubkey, ecdsa_sig.1) } else if self.is_segwit_v0() { let amt = match get_prevout(prevouts, input_idx) { - Some(txout) => txout.value, + Some(txout) => txout.borrow().value, None => return false, }; cache.segwitv0_sighash(input_idx, script_pubkey, amt, ecdsa_sig.1) @@ -304,7 +305,7 @@ where return false; }; let msg = sighash_msg - .map(|hash| secp256k1_zkp::Message::from_slice(&hash).expect("32 byte")); + .map(|hash| secp256k1_zkp::Message::from_slice(hash.as_ref()).expect("32 byte")); let success = msg.map(|msg| secp.verify_schnorr(&schnorr_sig.sig, &msg, xpk).is_ok()); success.unwrap_or(false) // unwrap_or_default checks for errors, while success would have checksig results @@ -698,7 +699,7 @@ where Terminal::After(ref n) => { debug_assert_eq!(node_state.n_evaluated, 0); debug_assert_eq!(node_state.n_satisfied, 0); - let res = self.stack.evaluate_after(&n.into(), self.lock_time); + let res = self.stack.evaluate_after(&LockTime::from(*n), self.lock_time); if res.is_some() { return res; } @@ -1212,7 +1213,7 @@ mod tests { Vec, secp256k1_zkp::Message, Secp256k1, - Vec, + Vec, Vec, Vec>, ) { @@ -1244,8 +1245,8 @@ mod tests { pks.push(pk); der_sigs.push(sigser); - let keypair = bitcoin::KeyPair::from_secret_key(&secp, &sk); - let (x_only_pk, _parity) = bitcoin::XOnlyPublicKey::from_keypair(&keypair); + let keypair = bitcoin::key::KeyPair::from_secret_key(&secp, &sk); + let (x_only_pk, _parity) = bitcoin::key::XOnlyPublicKey::from_keypair(&keypair); x_only_pks.push(x_only_pk); let schnorr_sig = secp.sign_schnorr_with_aux_rand(&msg, &keypair, &[0u8; 32]); let schnorr_sig = elements::SchnorrSig { @@ -1754,7 +1755,7 @@ mod tests { } fn x_only_no_checks_ms(ms: &str) -> Miniscript { - let elem: Miniscript = + let elem: Miniscript = Miniscript::from_str_ext(ms, &ExtParams::allow_all()).unwrap(); elem.to_no_checks_ms() } diff --git a/src/interpreter/stack.rs b/src/interpreter/stack.rs index a121a97b..deda9afa 100644 --- a/src/interpreter/stack.rs +++ b/src/interpreter/stack.rs @@ -193,7 +193,7 @@ impl<'txin> Stack<'txin> { // We don't really store information about which key error. fn bitcoin_key_from_slice(sl: &[u8], sig_type: SigType) -> Option { let key: BitcoinKey = match sig_type { - SigType::Schnorr => bitcoin::XOnlyPublicKey::from_slice(sl).ok()?.into(), + SigType::Schnorr => bitcoin::key::XOnlyPublicKey::from_slice(sl).ok()?.into(), SigType::Ecdsa => bitcoin::PublicKey::from_slice(sl).ok()?.into(), }; Some(key) diff --git a/src/lib.rs b/src/lib.rs index 1aefd52c..1e197cb7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -114,15 +114,15 @@ extern crate test; // It can be confusing to code when we have two miniscript libraries // As a rule, only import the library here and pub use all the required // items. Should help in faster code development in the long run -pub(crate) use bitcoin_miniscript::expression::{FromTree as BtcFromTree, Tree as BtcTree}; -pub(crate) use bitcoin_miniscript::policy::semantic::Policy as BtcPolicy; -pub(crate) use bitcoin_miniscript::policy::Liftable as BtcLiftable; -// re-export imports -pub use bitcoin_miniscript::{hash256, ForEachKey, MiniscriptKey, SigType, ToPublicKey}; -pub(crate) use bitcoin_miniscript::{ +use bitcoin_miniscript::expression::{FromTree as BtcFromTree, Tree as BtcTree}; +use bitcoin_miniscript::policy::semantic::Policy as BtcPolicy; +use bitcoin_miniscript::policy::Liftable as BtcLiftable; +use bitcoin_miniscript::{ Descriptor as BtcDescriptor, Error as BtcError, Miniscript as BtcMiniscript, Satisfier as BtcSatisfier, Segwitv0 as BtcSegwitv0, Terminal as BtcTerminal, }; +// re-export imports +pub use bitcoin_miniscript::{hash256, ForEachKey, MiniscriptKey, SigType, ToPublicKey}; // End imports #[macro_use] @@ -145,8 +145,9 @@ pub mod psbt; mod test_utils; mod util; -use std::{error, fmt, str}; +use std::{cmp, error, fmt, str}; +use elements::locktime; use elements::hashes::sha256; use elements::secp256k1_zkp::Secp256k1; use elements::{opcodes, script, secp256k1_zkp}; @@ -179,7 +180,7 @@ mod contracthash { .inner .add_exp_tweak( secp, - &Scalar::from_be_bytes(hmac_result.into_inner()) + &Scalar::from_be_bytes(hmac_result.to_byte_array()) .expect("Result of hash must be a valid point"), ) .expect("HMAC cannot produce invalid tweak"); @@ -294,7 +295,7 @@ pub enum Error { /// rust-bitcoin script error Script(script::Error), /// rust-bitcoin address error - AddrError(bitcoin::util::address::Error), + AddrError(bitcoin::address::Error), /// A `CHECKMULTISIG` opcode was preceded by a number > 20 CmsTooManyKeys(u32), /// A tapscript multi_a cannot support more than MAX_BLOCK_WEIGHT/32 keys @@ -322,7 +323,7 @@ pub enum Error { /// Parsed a miniscript but there were more script opcodes after it Trailing(String), /// Failed to parse a push as a public key - BadPubkey(bitcoin::util::key::Error), + BadPubkey(bitcoin::key::Error), /// Could not satisfy a script (fragment) because of a missing hash preimage MissingHash(sha256::Hash), /// Could not satisfy a script (fragment) because of a missing signature @@ -433,14 +434,14 @@ impl From for Error { } #[doc(hidden)] -impl From for Error { - fn from(e: bitcoin::util::key::Error) -> Error { +impl From for Error { + fn from(e: bitcoin::key::Error) -> Error { Error::BadPubkey(e) } } -impl From for Error { - fn from(e: bitcoin::util::address::Error) -> Error { +impl From for Error { + fn from(e: bitcoin::address::Error) -> Error { Error::AddrError(e) } } @@ -461,7 +462,7 @@ impl fmt::Display for Error { Error::NonMinimalVerify(ref tok) => write!(f, "{} VERIFY", tok), Error::InvalidPush(ref push) => { write!(f, "invalid push ")?; - bitcoin::hashes::hex::format_hex(push, f) + elements::hex::format_hex(push, f) }, Error::Script(ref e) => fmt::Display::fmt(e, f), Error::AddrError(ref e) => fmt::Display::fmt(e, f), @@ -628,10 +629,69 @@ fn push_opcode_size(script_size: usize) -> usize { } } +/// An absolute locktime that implements `Ord`. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct AbsLockTime(locktime::LockTime); + +impl AbsLockTime { + /// Constructs an `AbsLockTime` from an nLockTime value or the argument to OP_CHEKCLOCKTIMEVERIFY. + pub fn from_consensus(n: u32) -> Self { + Self(locktime::LockTime::from_consensus(n)) + } + + /// Returns the inner `u32` value. This is the value used when creating this `LockTime` + /// i.e., `n OP_CHECKLOCKTIMEVERIFY` or nLockTime. + /// + /// This calls through to `locktime::LockTime::to_consensus_u32()` and the same usage warnings + /// apply. + pub fn to_consensus_u32(self) -> u32 { + self.0.to_consensus_u32() + } + + /// Returns the inner `u32` value. + /// + /// Equivalent to `AbsLockTime::to_consensus_u32()`. + pub fn to_u32(self) -> u32 { + self.to_consensus_u32() + } +} + +impl From for AbsLockTime { + fn from(lock_time: locktime::LockTime) -> Self { + Self(lock_time) + } +} + +impl From for locktime::LockTime { + fn from(lock_time: AbsLockTime) -> locktime::LockTime { + lock_time.0 + } +} + +impl cmp::PartialOrd for AbsLockTime { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl cmp::Ord for AbsLockTime { + fn cmp(&self, other: &Self) -> cmp::Ordering { + let this = self.0.to_consensus_u32(); + let that = other.0.to_consensus_u32(); + this.cmp(&that) + } +} + +impl fmt::Display for AbsLockTime { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Display::fmt(&self.0, f) + } +} + /// Helper function used by tests #[cfg(test)] fn hex_script(s: &str) -> elements::Script { - let v: Vec = elements::hashes::hex::FromHex::from_hex(s).unwrap(); + let v: Vec = elements::hex::FromHex::from_hex(s).unwrap(); elements::Script::from(v) } diff --git a/src/miniscript/astelem.rs b/src/miniscript/astelem.rs index 340eb0c5..e47c766b 100644 --- a/src/miniscript/astelem.rs +++ b/src/miniscript/astelem.rs @@ -13,7 +13,7 @@ use std::str::FromStr; use std::sync::Arc; use bitcoin::hashes::hash160; -use elements::{opcodes, script, LockTime, Sequence}; +use elements::{opcodes, script, Sequence}; use super::limits::{MAX_SCRIPT_ELEMENT_SIZE, MAX_STANDARD_P2WSH_STACK_ITEM_SIZE}; use crate::extensions::ParseableExt; @@ -22,7 +22,7 @@ use crate::miniscript::types::{self, Property}; use crate::miniscript::ScriptContext; use crate::util::MsKeyBuilder; use crate::{ - errstr, expression, script_num_size, Error, ExtTranslator, Extension, ForEachKey, Miniscript, + errstr, expression, script_num_size, AbsLockTime, Error, ExtTranslator, Extension, ForEachKey, Miniscript, MiniscriptKey, Terminal, ToPublicKey, TranslateExt, TranslatePk, Translator, }; @@ -571,7 +571,7 @@ impl_from_tree!( } ("pk_h", 1) => expression::terminal(&top.args[0], |x| Pk::from_str(x).map(Terminal::PkH)), ("after", 1) => expression::terminal(&top.args[0], |x| { - expression::parse_num::(x).map(|x| Terminal::After(LockTime::from_consensus(x).into())) + expression::parse_num::(x).map(|x| Terminal::After(AbsLockTime::from_consensus(x).into())) }), ("older", 1) => expression::terminal(&top.args[0], |x| { expression::parse_num::(x).map(|x| Terminal::Older(Sequence::from_consensus(x))) @@ -790,7 +790,7 @@ impl Terminal builder .push_opcode(opcodes::all::OP_DUP) .push_opcode(opcodes::all::OP_HASH160) - .push_slice(hash) + .push_slice(hash.as_ref()) .push_opcode(opcodes::all::OP_EQUALVERIFY), Terminal::After(t) => builder .push_int(t.to_u32().into()) @@ -803,28 +803,28 @@ impl Terminal builder .push_opcode(opcodes::all::OP_SIZE) .push_int(32) .push_opcode(opcodes::all::OP_EQUALVERIFY) .push_opcode(opcodes::all::OP_HASH256) - .push_slice(&Pk::to_hash256(h)) + .push_slice(Pk::to_hash256(h).as_ref()) .push_opcode(opcodes::all::OP_EQUAL), Terminal::Ripemd160(ref h) => builder .push_opcode(opcodes::all::OP_SIZE) .push_int(32) .push_opcode(opcodes::all::OP_EQUALVERIFY) .push_opcode(opcodes::all::OP_RIPEMD160) - .push_slice(&Pk::to_ripemd160(h)) + .push_slice(Pk::to_ripemd160(h).as_ref()) .push_opcode(opcodes::all::OP_EQUAL), Terminal::Hash160(ref h) => builder .push_opcode(opcodes::all::OP_SIZE) .push_int(32) .push_opcode(opcodes::all::OP_EQUALVERIFY) .push_opcode(opcodes::all::OP_HASH160) - .push_slice(&Pk::to_hash160(h)) + .push_slice(Pk::to_hash160(h).as_ref()) .push_opcode(opcodes::all::OP_EQUAL), Terminal::True => builder.push_opcode(opcodes::OP_TRUE), Terminal::False => builder.push_opcode(opcodes::OP_FALSE), diff --git a/src/miniscript/decode.rs b/src/miniscript/decode.rs index 72cd4b98..6be4e0e2 100644 --- a/src/miniscript/decode.rs +++ b/src/miniscript/decode.rs @@ -12,7 +12,7 @@ use std::{error, fmt}; use elements::hashes::{hash160, ripemd160, sha256, Hash}; -use crate::elements::{LockTime, PackedLockTime, Sequence}; +use crate::elements::Sequence; use crate::extensions::ParseableExt; use crate::miniscript::lex::{Token as Tk, TokenIter}; use crate::miniscript::limits::{MAX_BLOCK_WEIGHT, MAX_PUBKEYS_PER_MULTISIG}; @@ -21,7 +21,7 @@ use crate::miniscript::types::{Property, Type}; use crate::miniscript::ScriptContext; #[cfg(doc)] use crate::Descriptor; -use crate::{bitcoin, hash256, Error, Extension, Miniscript, MiniscriptKey, NoExt, ToPublicKey}; +use crate::{bitcoin, hash256, AbsLockTime, Error, Extension, Miniscript, MiniscriptKey, NoExt, ToPublicKey}; fn return_none(_: usize) -> Option { None @@ -39,9 +39,9 @@ impl ParseableKey for bitcoin::PublicKey { } } -impl ParseableKey for bitcoin::XOnlyPublicKey { +impl ParseableKey for bitcoin::key::XOnlyPublicKey { fn from_slice(sl: &[u8]) -> Result { - bitcoin::XOnlyPublicKey::from_slice(sl).map_err(KeyParseError::XonlyKeyParseError) + bitcoin::key::XOnlyPublicKey::from_slice(sl).map_err(KeyParseError::XonlyKeyParseError) } } @@ -49,7 +49,7 @@ impl ParseableKey for bitcoin::XOnlyPublicKey { #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum KeyParseError { /// Bitcoin PublicKey parse error - FullKeyParseError(bitcoin::util::key::Error), + FullKeyParseError(bitcoin::key::Error), /// Xonly key parse Error XonlyKeyParseError(bitcoin::secp256k1::Error), } @@ -79,7 +79,7 @@ mod private { // Implement for those same types, but no others. impl Sealed for super::bitcoin::PublicKey {} - impl Sealed for super::bitcoin::XOnlyPublicKey {} + impl Sealed for super::bitcoin::key::XOnlyPublicKey {} } #[derive(Copy, Clone, Debug)] @@ -136,7 +136,7 @@ pub enum Terminal RawPkH(hash160::Hash), // timelocks /// `n CHECKLOCKTIMEVERIFY` - After(PackedLockTime), + After(AbsLockTime), /// `n CHECKSEQUENCEVERIFY` Older(Sequence), // hashlocks @@ -398,7 +398,7 @@ pub fn parse( Tk::CheckSequenceVerify, Tk::Num(n) => term.reduce0(Terminal::Older(Sequence::from_consensus(n)))?, Tk::CheckLockTimeVerify, Tk::Num(n) - => term.reduce0(Terminal::After(LockTime::from_consensus(n).into()))?, + => term.reduce0(Terminal::After(AbsLockTime::from_consensus(n)))?, // hashlocks Tk::Equal => match_token!( tokens, diff --git a/src/miniscript/iter.rs b/src/miniscript/iter.rs index 08793a85..adb61a68 100644 --- a/src/miniscript/iter.rs +++ b/src/miniscript/iter.rs @@ -268,9 +268,9 @@ pub mod test { let preimage = vec![0xab; 32]; let sha256_hash = sha256::Hash::hash(&preimage); let sha256d_hash_rev = sha256d::Hash::hash(&preimage); - let mut sha256d_hash_bytes = sha256d_hash_rev.into_inner(); + let mut sha256d_hash_bytes = sha256d_hash_rev.to_byte_array(); sha256d_hash_bytes.reverse(); - let sha256d_hash = sha256d::Hash::from_inner(sha256d_hash_bytes); + let sha256d_hash = sha256d::Hash::from_byte_array(sha256d_hash_bytes); let hash160_hash = hash160::Hash::hash(&preimage); let ripemd160_hash = ripemd160::Hash::hash(&preimage); diff --git a/src/miniscript/mod.rs b/src/miniscript/mod.rs index 2c253652..4fc73ea2 100644 --- a/src/miniscript/mod.rs +++ b/src/miniscript/mod.rs @@ -203,7 +203,7 @@ where /// use elements_miniscript::bitcoin::secp256k1::XOnlyPublicKey; /// type Segwitv0Script = Miniscript; /// type TapScript = Miniscript; - /// use bitcoin::hashes::hex::FromHex; + /// use elements::hex::FromHex; /// fn main() { /// // parse x-only miniscript in Taproot context /// let tapscript_ms = TapScript::parse(&elements::Script::from(Vec::::from_hex( @@ -522,8 +522,11 @@ serde_string_impl_pk!(Miniscript, "a miniscript", Ctx; ScriptContext => Ext2 ; E pub mod hash256 { use bitcoin::hashes::{hash_newtype, sha256d}; - #[rustfmt::skip] - hash_newtype!(Hash, sha256d::Hash, 32, doc = "A bitcoin block hash.", false); + hash_newtype! { + /// A hash256 of preimage. + #[hash_newtype(forward)] + pub struct Hash(sha256d::Hash); + } } #[cfg(test)] @@ -534,7 +537,7 @@ mod tests { use std::str::FromStr; use std::sync::Arc; - use bitcoin::{self, XOnlyPublicKey}; + use bitcoin::{self, key::XOnlyPublicKey}; use elements::hashes::{hash160, sha256, Hash}; use elements::taproot::TapLeafHash; use elements::{self, secp256k1_zkp, Sequence}; @@ -736,7 +739,7 @@ mod tests { ", ) .unwrap(); - let hash = hash160::Hash::from_inner([17; 20]); + let hash = hash160::Hash::from_byte_array([17; 20]); let pkk_ms: Miniscript = Miniscript { node: Terminal::Check(Arc::new(Miniscript { @@ -1088,7 +1091,7 @@ mod tests { ); assert_eq!( ms.unwrap_err().to_string(), - "unexpected «key hex decoding error»", + "unexpected «PublicKey hex should be 66 or 130 digits long, got: 64»", ); Tapscript::from_str_insane( "pk(2788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99)", @@ -1160,7 +1163,7 @@ mod tests { .unwrap(); // script rtt test assert_eq!( - Miniscript::::parse_insane(&tap_ms.encode()).unwrap(), + Miniscript::::parse_insane(&tap_ms.encode()).unwrap(), tap_ms ); assert_eq!(tap_ms.script_size(), 104); diff --git a/src/miniscript/satisfy.rs b/src/miniscript/satisfy.rs index e3ddd285..a9bc2c29 100644 --- a/src/miniscript/satisfy.rs +++ b/src/miniscript/satisfy.rs @@ -77,7 +77,7 @@ pub trait Satisfier { None } - /// Given a raw `Pkh`, lookup corresponding [`bitcoin::XOnlyPublicKey`] + /// Given a raw `Pkh`, lookup corresponding [`bitcoin::key::XOnlyPublicKey`] fn lookup_raw_pkh_x_only_pk(&self, _: &hash160::Hash) -> Option { None } diff --git a/src/miniscript/types/extra_props.rs b/src/miniscript/types/extra_props.rs index cb023d66..bdbee9b0 100644 --- a/src/miniscript/types/extra_props.rs +++ b/src/miniscript/types/extra_props.rs @@ -6,7 +6,7 @@ use std::cmp; use std::iter::once; -use elements::{LockTime, PackedLockTime, Sequence}; +use elements::{LockTime, Sequence}; use super::{Error, ErrorKind, Property, ScriptContext}; use crate::miniscript::context::SigType; @@ -938,7 +938,7 @@ impl Property for ExtData { // Note that for CLTV this is a limitation not of Bitcoin but Miniscript. The // number on the stack would be a 5 bytes signed integer but Miniscript's B type // only consumes 4 bytes from the stack. - if t == PackedLockTime::ZERO { + if t == LockTime::ZERO.into() { return Err(Error { fragment: fragment.clone(), error: ErrorKind::InvalidTime, diff --git a/src/miniscript/types/mod.rs b/src/miniscript/types/mod.rs index a6da769c..40135028 100644 --- a/src/miniscript/types/mod.rs +++ b/src/miniscript/types/mod.rs @@ -11,7 +11,7 @@ pub mod malleability; use std::{error, fmt}; -use elements::{LockTime, PackedLockTime, Sequence}; +use elements::{LockTime, Sequence}; pub use self::correctness::{Base, Correctness, Input}; pub use self::extra_props::ExtData; @@ -432,7 +432,7 @@ pub trait Property: Sized { // Note that for CLTV this is a limitation not of Bitcoin but Miniscript. The // number on the stack would be a 5 bytes signed integer but Miniscript's B type // only consumes 4 bytes from the stack. - if t == PackedLockTime::ZERO { + if t == LockTime::ZERO.into() { return Err(Error { fragment: fragment.clone(), error: ErrorKind::InvalidTime, @@ -831,7 +831,7 @@ impl Property for Type { // Note that for CLTV this is a limitation not of Bitcoin but Miniscript. The // number on the stack would be a 5 bytes signed integer but Miniscript's B type // only consumes 4 bytes from the stack. - if t == PackedLockTime::ZERO { + if t == LockTime::ZERO.into() { return Err(Error { fragment: fragment.clone(), error: ErrorKind::InvalidTime, diff --git a/src/policy/concrete.rs b/src/policy/concrete.rs index a3113d5e..d1ddd6b0 100644 --- a/src/policy/concrete.rs +++ b/src/policy/concrete.rs @@ -7,7 +7,7 @@ use std::collections::HashSet; use std::{error, fmt, str}; -use elements::{LockTime, PackedLockTime, Sequence}; +use elements::{LockTime, Sequence}; #[cfg(feature = "compiler")] use { crate::descriptor::TapTree, @@ -29,7 +29,7 @@ use crate::expression::{self, FromTree}; use crate::miniscript::types::extra_props::TimelockInfo; #[cfg(all(doc, not(feature = "compiler")))] use crate::Descriptor; -use crate::{errstr, Error, ForEachKey, MiniscriptKey, Translator}; +use crate::{errstr, AbsLockTime, Error, ForEachKey, MiniscriptKey, Translator}; /// Maximum TapLeafs allowed in a compiled TapTree #[cfg(feature = "compiler")] @@ -47,7 +47,7 @@ pub enum Policy { /// A public key which must sign to satisfy the descriptor Key(Pk), /// An absolute locktime restriction - After(PackedLockTime), + After(AbsLockTime), /// A relative locktime restriction Older(Sequence), /// A SHA256 whose preimage must be provided to satisfy the descriptor @@ -72,9 +72,9 @@ where Pk: MiniscriptKey, { /// Construct a `Policy::After` from `n`. Helper function equivalent to - /// `Policy::After(PackedLockTime::from(LockTime::from_consensus(n)))`. + /// `Policy::After(LockTime::from(LockTime::from_consensus(n)))`. pub fn after(n: u32) -> Policy { - Policy::After(PackedLockTime::from(LockTime::from_consensus(n))) + Policy::After(AbsLockTime::from(LockTime::from_consensus(n))) } /// Construct a `Policy::Older` from `n`. Helper function equivalent to @@ -124,7 +124,7 @@ impl From> for Policy { PolicyArc::Unsatisfiable => Policy::Unsatisfiable, PolicyArc::Trivial => Policy::Trivial, PolicyArc::Key(pk) => Policy::Key(pk), - PolicyArc::After(t) => Policy::After(PackedLockTime::from(LockTime::from_consensus(t))), + PolicyArc::After(t) => Policy::After(AbsLockTime::from(LockTime::from_consensus(t))), PolicyArc::Older(t) => Policy::Older(Sequence::from_consensus(t)), PolicyArc::Sha256(hash) => Policy::Sha256(hash), PolicyArc::Hash256(hash) => Policy::Hash256(hash), @@ -157,7 +157,7 @@ impl From> for PolicyArc { Policy::Unsatisfiable => PolicyArc::Unsatisfiable, Policy::Trivial => PolicyArc::Trivial, Policy::Key(pk) => PolicyArc::Key(pk), - Policy::After(PackedLockTime(t)) => PolicyArc::After(t), + Policy::After(t) => PolicyArc::After(t.to_consensus_u32()), Policy::Older(Sequence(t)) => PolicyArc::Older(t), Policy::Sha256(hash) => PolicyArc::Sha256(hash), Policy::Hash256(hash) => PolicyArc::Hash256(hash), @@ -940,7 +940,7 @@ impl Policy { } } Policy::After(n) => { - if n == PackedLockTime::ZERO { + if n == LockTime::ZERO.into() { Err(PolicyError::ZeroTime) } else if n.to_u32() > 2u32.pow(31) { Err(PolicyError::TimeTooFar) diff --git a/src/policy/mod.rs b/src/policy/mod.rs index 35711c17..89093fc6 100644 --- a/src/policy/mod.rs +++ b/src/policy/mod.rs @@ -25,7 +25,7 @@ pub use self::concrete::Policy as Concrete; pub use self::semantic::Policy as Semantic; use crate::descriptor::{CovError, Descriptor}; use crate::miniscript::{Miniscript, ScriptContext}; -use crate::{BtcPolicy, Error, Extension, MiniscriptKey, Terminal}; +use crate::{AbsLockTime, BtcPolicy, Error, Extension, MiniscriptKey, Terminal}; /// Policy entailment algorithm maximum number of terminals allowed const ENTAILMENT_MAX_TERMINALS: usize = 20; @@ -126,7 +126,7 @@ where Terminal::RawPkH(ref _pkh) => { return Err(Error::LiftError(LiftError::RawDescriptorLift)) } - Terminal::After(t) => Semantic::After(t), + Terminal::After(t) => Semantic::After(t.into()), Terminal::Older(t) => Semantic::Older(t), Terminal::Sha256(ref h) => Semantic::Sha256(h.clone()), Terminal::Hash256(ref h) => Semantic::Hash256(h.clone()), @@ -237,7 +237,7 @@ impl Liftable for BtcPolicy { BtcPolicy::Hash256(ref h) => Ok(Semantic::Hash256(h.clone())), BtcPolicy::Ripemd160(ref h) => Ok(Semantic::Ripemd160(h.clone())), BtcPolicy::Hash160(ref h) => Ok(Semantic::Hash160(h.clone())), - BtcPolicy::After(n) => Ok(Semantic::After(elements::PackedLockTime(n.to_u32()))), + BtcPolicy::After(n) => Ok(Semantic::After(AbsLockTime::from_consensus(n.to_consensus_u32()))), BtcPolicy::Older(n) => Ok(Semantic::Older(Sequence(n.to_consensus_u32()))), BtcPolicy::Threshold(k, ref subs) => { let new_subs: Result>, _> = diff --git a/src/policy/semantic.rs b/src/policy/semantic.rs index 8ca7405e..2a54afc7 100644 --- a/src/policy/semantic.rs +++ b/src/policy/semantic.rs @@ -6,11 +6,11 @@ use std::str::FromStr; use std::{fmt, str}; -use elements::{LockTime, PackedLockTime, Sequence}; +use elements::{LockTime, Sequence}; use super::concrete::PolicyError; use super::ENTAILMENT_MAX_TERMINALS; -use crate::{errstr, expression, Error, ForEachKey, MiniscriptKey, Translator}; +use crate::{errstr, expression, AbsLockTime, Error, ForEachKey, MiniscriptKey, Translator}; /// Abstract policy which corresponds to the semantics of a Miniscript /// and which allows complex forms of analysis, e.g. filtering and @@ -27,7 +27,7 @@ pub enum Policy { /// Signature and public key matching a given hash is required Key(Pk), /// An absolute locktime restriction - After(PackedLockTime), + After(AbsLockTime), /// A relative locktime restriction Older(Sequence), /// A SHA256 whose preimage must be provided to satisfy the descriptor @@ -47,9 +47,9 @@ where Pk: MiniscriptKey, { /// Construct a `Policy::After` from `n`. Helper function equivalent to - /// `Policy::After(PackedLockTime::from(LockTime::from_consensus(n)))`. + /// `Policy::After(AbsLockTime::from(LockTime::from_consensus(n)))`. pub fn after(n: u32) -> Policy { - Policy::After(PackedLockTime::from(LockTime::from_consensus(n))) + Policy::After(AbsLockTime::from(LockTime::from_consensus(n))) } /// Construct a `Policy::Older` from `n`. Helper function equivalent to @@ -513,7 +513,7 @@ impl Policy { | Policy::Ripemd160(..) | Policy::Hash160(..) => vec![], Policy::Older(..) => vec![], - Policy::After(t) => vec![t.0], + Policy::After(t) => vec![t.to_u32()], Policy::Threshold(_, ref subs) => subs.iter().fold(vec![], |mut acc, x| { acc.extend(x.real_absolute_timelocks()); acc diff --git a/src/psbt/finalizer.rs b/src/psbt/finalizer.rs index 27e96d56..4aa280d6 100644 --- a/src/psbt/finalizer.rs +++ b/src/psbt/finalizer.rs @@ -8,7 +8,7 @@ //! `https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki` //! -use bitcoin::{self, PublicKey, XOnlyPublicKey}; +use bitcoin::{self, PublicKey, key::XOnlyPublicKey}; use elements::secp256k1_zkp::{self, Secp256k1}; use elements::taproot::LeafVersion; use elements::{self, confidential, Script, Sequence, Transaction, TxOut}; @@ -534,7 +534,7 @@ pub fn finalize( // mod tests { // use super::*; // use elements::encode::{deserialize, serialize}; -// use elements::hashes::hex::FromHex; +// use elements::hex::FromHex; // #[test] // fn test_inp_finalize_520bytes() { diff --git a/src/psbt/mod.rs b/src/psbt/mod.rs index 363c6a99..0b722497 100644 --- a/src/psbt/mod.rs +++ b/src/psbt/mod.rs @@ -13,14 +13,14 @@ use std::ops::Deref; use std::{error, fmt}; use bitcoin; -use bitcoin::util::bip32; +use bitcoin::bip32; use elements::hashes::{hash160, sha256d, Hash}; use elements::pset::PartiallySignedTransaction as Psbt; use elements::secp256k1_zkp::{self as secp256k1, Secp256k1, VerifyOnly}; use elements::sighash::SigHashCache; use elements::taproot::{self, ControlBlock, LeafVersion, TapLeafHash}; use elements::{ - self, pset as psbt, EcdsaSigHashType, LockTime, PackedLockTime, SchnorrSigHashType, Script, + self, pset as psbt, EcdsaSigHashType, LockTime, SchnorrSigHashType, Script, Sequence, }; @@ -107,7 +107,7 @@ pub enum InputError { /// Get the secp Errors directly SecpErr(elements::secp256k1_zkp::Error), /// Key errors - KeyErr(bitcoin::util::key::Error), + KeyErr(bitcoin::key::Error), /// Error doing an interpreter-check on a finalized psbt Interpreter(interpreter::Error), /// Redeem script does not match the p2sh hash @@ -258,8 +258,8 @@ impl From for InputError { } #[doc(hidden)] -impl From for InputError { - fn from(e: bitcoin::util::key::Error) -> InputError { +impl From for InputError { + fn from(e: bitcoin::key::Error) -> InputError { InputError::KeyErr(e) } } @@ -390,7 +390,7 @@ impl<'psbt, Pk: MiniscriptKey + ToPublicKey> Satisfier for PsbtInputSatisfie .global .tx_data .fallback_locktime - .unwrap_or(PackedLockTime::ZERO), + .unwrap_or(LockTime::ZERO), ); >::check_after(&lock_time, n) @@ -431,7 +431,7 @@ impl<'psbt, Pk: MiniscriptKey + ToPublicKey> Satisfier for PsbtInputSatisfie fn lookup_hash256(&self, h: &Pk::Hash256) -> Option { self.psbt.inputs()[self.index] .hash256_preimages - .get(&sha256d::Hash::from_inner(Pk::to_hash256(h).into_inner())) // upstream psbt operates on hash256 + .get(&sha256d::Hash::from_byte_array(Pk::to_hash256(h).to_byte_array())) // upstream psbt operates on hash256 .and_then(try_vec_as_preimage32) } @@ -627,7 +627,7 @@ pub trait PsbtExt { /// * `cache`: The [`SighashCache`] for used to cache/read previously cached computations /// * `tapleaf_hash`: If the output is taproot, compute the sighash for this particular leaf. /// - /// [`SighashCache`]: bitcoin::util::sighash::SighashCache + /// [`SighashCache`]: bitcoin::sighash::SighashCache fn sighash_msg>( &self, idx: usize, @@ -1084,10 +1084,10 @@ trait PsbtFields { fn redeem_script(&mut self) -> &mut Option