Skip to content

Commit

Permalink
update bitcoin to 0.30.0, elements to 0.22.0, miniscript to 10.0
Browse files Browse the repository at this point in the history
Note that bitcoind-tests does not compile after this commit; it will be
fixed in the next.
  • Loading branch information
apoelstra committed Jun 15, 2023
1 parent 955f380 commit 1a00d31
Show file tree
Hide file tree
Showing 39 changed files with 296 additions and 220 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
on: [push, pull_request]
on:
push:
branches:
- master
pull_request: {}

name: Continuous integration

Expand Down
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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" }


Expand All @@ -58,4 +58,4 @@ required-features = ["compiler"]

[[example]]
name = "psbt_sign_finalize"
required-features = ["base64"]
required-features = ["base64"]
2 changes: 1 addition & 1 deletion bitcoind-tests/tests/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
9 changes: 4 additions & 5 deletions bitcoind-tests/tests/setup/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,7 +40,7 @@ pub static PARAMS: AddressParams = AddressParams::ELEMENTS;
#[derive(Clone, Debug)]
pub struct PubData {
pub pks: Vec<bitcoin::PublicKey>,
pub x_only_pks: Vec<bitcoin::XOnlyPublicKey>,
pub x_only_pks: Vec<bitcoin::key::XOnlyPublicKey>,
pub sha256: sha256::Hash,
pub hash256: hash256::Hash,
pub ripemd160: ripemd160::Hash,
Expand Down Expand Up @@ -79,7 +78,7 @@ fn setup_keys(
Vec<bitcoin::secp256k1::SecretKey>,
Vec<miniscript::bitcoin::PublicKey>,
Vec<bitcoin::KeyPair>,
Vec<bitcoin::XOnlyPublicKey>,
Vec<bitcoin::key::XOnlyPublicKey>,
) {
let secp_sign = secp256k1::Secp256k1::signing_only();
let mut sk = [0; 32];
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions bitcoind-tests/tests/test_csfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ pub fn test_desc_satisfy(cl: &ElementsD, testdata: &TestData, desc: &str) -> Vec
impl<'a> Satisfier<bitcoin::PublicKey> for CsfsSatisfier<'a> {
fn lookup_csfs_sig(
&self,
pk: &bitcoin::XOnlyPublicKey,
pk: &bitcoin::key::XOnlyPublicKey,
msg: &miniscript::extensions::CsfsMsg,
) -> Option<secp256k1::schnorr::Signature> {
let xpk = pk.to_x_only_pubkey();
Expand All @@ -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();
Expand Down
11 changes: 5 additions & 6 deletions examples/psbt_sign_finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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![],
};
Expand All @@ -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(),
Expand All @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions examples/sign_multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
Expand Down
18 changes: 9 additions & 9 deletions examples/taproot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -15,18 +15,18 @@ use secp256k1::{rand, KeyPair};
// for a detailed explanation of the policy and it's compilation

struct StrPkTranslator {
pk_map: HashMap<String, bitcoin::XOnlyPublicKey>,
pk_map: HashMap<String, bitcoin::key::XOnlyPublicKey>,
}

impl Translator<String, bitcoin::XOnlyPublicKey, ()> for StrPkTranslator {
fn pk(&mut self, pk: &String) -> Result<bitcoin::XOnlyPublicKey, ()> {
impl Translator<String, bitcoin::key::XOnlyPublicKey, ()> for StrPkTranslator {
fn pk(&mut self, pk: &String) -> Result<bitcoin::key::XOnlyPublicKey, ()> {
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() {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -120,7 +120,7 @@ fn main() {
assert_eq!(addr, expected_addr);
}

fn hardcoded_xonlypubkeys() -> Vec<bitcoin::XOnlyPublicKey> {
fn hardcoded_xonlypubkeys() -> Vec<bitcoin::key::XOnlyPublicKey> {
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,
Expand All @@ -139,9 +139,9 @@ fn hardcoded_xonlypubkeys() -> Vec<bitcoin::XOnlyPublicKey> {
168, 39, 134, 58, 19, 181, 3, 63, 235, 103, 155, 213,
],
];
let mut keys: Vec<bitcoin::XOnlyPublicKey> = vec![];
let mut keys: Vec<bitcoin::key::XOnlyPublicKey> = 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
}
4 changes: 2 additions & 2 deletions examples/verify_tx.rs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/descriptor/csfs_cov/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/descriptor/csfs_cov/satisfy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl<'tx, 'ptx, Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for LegacyCovSati
}

fn lookup_nlocktime(&self) -> Option<u32> {
Some(self.tx.lock_time.to_u32())
Some(self.tx.lock_time.to_consensus_u32())
}

fn lookup_sighashu32(&self) -> Option<u32> {
Expand Down
26 changes: 15 additions & 11 deletions src/descriptor/key.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand All @@ -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
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"),
)
}
}
}
Expand Down Expand Up @@ -751,7 +755,7 @@ fn parse_key_origin(s: &str) -> Result<(&str, Option<bip32::KeySource>), 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
Expand Down Expand Up @@ -897,7 +901,7 @@ impl<K: InnerXKey> DescriptorXKey<K> {
/// # extern crate elements_miniscript as miniscript;
/// # use std::str::FromStr;
/// # fn body() -> Result<(), Box<dyn std::error::Error>> {
/// use miniscript::bitcoin::util::bip32;
/// use miniscript::bitcoin::bip32;
/// use miniscript::descriptor::DescriptorPublicKey;
///
/// let ctx = miniscript::elements::secp256k1_zkp::Secp256k1::signing_only();
Expand Down Expand Up @@ -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};
Expand Down
Loading

0 comments on commit 1a00d31

Please sign in to comment.