Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ base64 = ["bitcoin/base64"]

[dependencies]
bech32 = { version = "0.11.0", default-features = false, features = ["alloc"] }
bitcoin = { version = "0.32.6", default-features = false }
bitcoin = { version = "0.33.0-alpha.0", default-features = false }
hex = { package = "hex-conservative", default-features = false, features = ["alloc"], version = "1.0.0" }

serde = { version = "1.0.103", optional = true }

[dev-dependencies]
serde_test = "1.0.147"
bitcoin = { version = "0.32.0", features = ["base64"] }
bitcoin = { version = "0.33.0-alpha", features = ["base64"] }
secp256k1 = {version = "0.29.0", features = ["rand-std"]}

[[example]]
Expand Down Expand Up @@ -73,3 +73,33 @@ required-features = ["compiler"]
[workspace]
members = ["fuzz"]
exclude = ["embedded", "bitcoind-tests"]

# Patch rust-bitcoin crates, use `branch` here because its easier when testing new branches (worktrees).

[patch.crates-io.base58ck]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
branch = "master"

[patch.crates-io.bitcoin]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
branch = "master"

[patch.crates-io.bitcoin_hashes]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
branch = "master"

[patch.crates-io.bitcoin-internals]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
branch = "master"

[patch.crates-io.bitcoin-io]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
branch = "master"

[patch.crates-io.bitcoin-primitives]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
branch = "master"

[patch.crates-io.bitcoin-units]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
branch = "master"
44 changes: 44 additions & 0 deletions bitcoind-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,47 @@ secp256k1 = {version = "0.29.0", features = ["rand-std"]}
"0_19_1" = ["bitcoind/0_19_1"]
"0_18_1" = ["bitcoind/0_18_1"]
"0_17_1" = ["bitcoind/0_17_1"]

# Patch crates from bitcoind-json-rpc repo.

[patch.crates-io.bitcoind-json-rpc-client]
git = "https://github.com/tcharding/rust-bitcoind-json-rpc"
branch = "track-bitcoin-master"

[patch.crates-io.bitcoind-json-rpc-regtest]
git = "https://github.com/tcharding/rust-bitcoind-json-rpc"
branch = "track-bitcoin-master"

[patch.crates-io.bitcoind-json-rpc-types]
git = "https://github.com/tcharding/rust-bitcoind-json-rpc"
branch = "track-bitcoin-master"

# Patch rust-bitcoin crates, use `branch` here because its easier when testing new branches (worktrees).

[patch.crates-io.base58ck]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
branch = "master"

[patch.crates-io.bitcoin]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
branch = "master"

[patch.crates-io.bitcoin_hashes]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
branch = "master"

[patch.crates-io.bitcoin-internals]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
branch = "master"

[patch.crates-io.bitcoin-io]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
branch = "master"

[patch.crates-io.bitcoin-primitives]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
branch = "master"

[patch.crates-io.bitcoin-units]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
branch = "master"
2 changes: 1 addition & 1 deletion bitcoind-tests/tests/setup/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use std::str::FromStr;

use actual_rand as rand;
use bitcoin::hashes::{hash160, ripemd160, sha256, Hash};
use bitcoin::hashes::{hash160, ripemd160, sha256};
use bitcoin::hex::DisplayHex;
use bitcoin::secp256k1;
use miniscript::descriptor::{SinglePub, SinglePubKey};
Expand Down
5 changes: 3 additions & 2 deletions bitcoind-tests/tests/test_cpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use std::fs::File;
use std::io::{self, BufRead};
use std::path::Path;

use bitcoin::hashes::{sha256d, Hash};
use bitcoin::hashes::sha256d;
use bitcoin::psbt::Psbt;
use bitcoin::transaction::OutPointExt as _;
use bitcoin::{
psbt, secp256k1, transaction, Amount, OutPoint, Sequence, Transaction, TxIn, TxOut, Txid,
};
Expand Down Expand Up @@ -119,7 +120,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
// processed correctly.
// We waited 50 blocks, keep 49 for safety
sequence: Sequence::from_height(49),
..Default::default()
..TxIn::EMPTY_COINBASE
};
psbt.unsigned_tx.input.push(txin);
// Get a new script pubkey from the node so that
Expand Down
8 changes: 4 additions & 4 deletions bitcoind-tests/tests/test_desc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use std::{error, fmt};

use actual_rand as rand;
use bitcoin::blockdata::witness::Witness;
use bitcoin::hashes::{sha256d, Hash};
use bitcoin::key::TapTweak as _;
use bitcoin::hashes::sha256d;
use bitcoin::psbt::Psbt;
use bitcoin::sighash::SighashCache;
use bitcoin::taproot::{LeafVersion, TapLeafHash};
use bitcoin::taproot::{LeafVersion, TapLeafHash, TapTweakHashExt as _, TapLeafHashExt as _};
use bitcoin::transaction::OutPointExt as _;
use bitcoin::{
absolute, psbt, secp256k1, sighash, transaction, Amount, OutPoint, Sequence, Transaction, TxIn,
TxOut, Txid,
Expand Down Expand Up @@ -128,7 +128,7 @@ pub fn test_desc_satisfy(
// processed correctly.
// We waited 2 blocks, keep 1 for safety
sequence: Sequence::from_height(1),
..Default::default()
..TxIn::EMPTY_COINBASE
};
psbt.unsigned_tx.input.push(txin);
// Get a new script pubkey from the node so that
Expand Down
6 changes: 4 additions & 2 deletions examples/psbt_sign_finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
use std::collections::BTreeMap;
use std::str::FromStr;

use miniscript::bitcoin::consensus::encode::deserialize_hex;
use bitcoin::transaction::OutPointExt as _;
use miniscript::bitcoin::consensus::encode::deserialize;
use miniscript::bitcoin::hashes::hex::FromHex;
use miniscript::bitcoin::psbt::{self, Psbt};
use miniscript::bitcoin::sighash::SighashCache;
//use miniscript::bitcoin::secp256k1; // https://github.com/rust-lang/rust/issues/121684
Expand Down Expand Up @@ -83,7 +85,7 @@ fn main() {
let txin = TxIn {
previous_output: outpoint,
sequence: Sequence::from_height(26),
..Default::default()
..TxIn::EMPTY_COINBASE
};
psbt.unsigned_tx.input.push(txin);

Expand Down
4 changes: 2 additions & 2 deletions examples/sign_multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::collections::HashMap;
use std::str::FromStr;

use bitcoin::blockdata::witness::Witness;
use bitcoin::{absolute, ecdsa, transaction, Amount, Sequence};
use bitcoin::{absolute, ecdsa, transaction, Amount, OutPoint, Sequence};

fn main() {
let mut tx = spending_transaction();
Expand Down Expand Up @@ -81,7 +81,7 @@ fn spending_transaction() -> bitcoin::Transaction {
version: transaction::Version::TWO,
lock_time: absolute::LockTime::ZERO,
input: vec![bitcoin::TxIn {
previous_output: Default::default(),
previous_output: OutPoint::COINBASE_PREVOUT,
script_sig: bitcoin::ScriptBuf::new(),
sequence: Sequence::MAX,
witness: Witness::default(),
Expand Down
3 changes: 2 additions & 1 deletion src/descriptor/bare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use core::fmt;

use bitcoin::address::script_pubkey::BuilderExt as _;
use bitcoin::script::{self, PushBytes};
use bitcoin::{Address, Network, ScriptBuf, Weight};

Expand Down Expand Up @@ -298,7 +299,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Pkh<Pk> {
// serialize() does not allocate here
sig.serialize().as_ref(),
)
.push_key(&self.pk.to_public_key())
.push_key(self.pk.to_public_key())
.into_script();
let witness = vec![];
Ok((witness, script_sig))
Expand Down
18 changes: 8 additions & 10 deletions src/descriptor/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use core::str::FromStr;
#[cfg(feature = "std")]
use std::error;

use bitcoin::bip32::{self, XKeyIdentifier};
use bitcoin::hashes::{hash160, ripemd160, sha256, Hash, HashEngine};
use bitcoin::key::{PublicKey, XOnlyPublicKey};
use bitcoin::bip32;
use bitcoin::hashes::{hash160, ripemd160, sha256, HashEngine};
use bitcoin::key::XOnlyPublicKey;
use bitcoin::secp256k1::{Secp256k1, Signing, Verification};
use bitcoin::NetworkKind;

Expand Down Expand Up @@ -232,11 +232,7 @@ impl DescriptorXKey<bip32::Xpriv> {
let hardened_path = &self.derivation_path[..last_hardened_idx];
let unhardened_path = &self.derivation_path[last_hardened_idx..];

let xprv = self
.xkey
.derive_priv(secp, &hardened_path)
.map_err(DescriptorKeyParseError::DeriveHardenedKey)?;

let xprv = self.xkey.derive_priv(secp, &hardened_path);
let xpub = bip32::Xpub::from_priv(secp, &xprv);

let origin = match &self.origin {
Expand Down Expand Up @@ -723,15 +719,17 @@ impl DescriptorPublicKey {
if let Some((fingerprint, _)) = single.origin {
fingerprint
} else {
let mut engine = XKeyIdentifier::engine();
let mut engine = hash160::Hash::engine();
match single.key {
SinglePubKey::FullKey(pk) => {
pk.write_into(&mut engine).expect("engines don't error")
}
SinglePubKey::XOnly(x_only_pk) => engine.input(&x_only_pk.serialize()),
};
// FIXME: Fix the bip32 API for creating fingerprint?
let xkey_id = hash160::Hash::from_engine(engine);
bip32::Fingerprint::from(
&XKeyIdentifier::from_engine(engine)[..4]
&xkey_id.as_byte_array()[..4]
.try_into()
.expect("4 byte slice"),
)
Expand Down
50 changes: 34 additions & 16 deletions src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
Descriptor::Pkh(ref pkh) => pkh.script_pubkey(),
Descriptor::Wpkh(ref wpkh) => wpkh.script_pubkey(),
Descriptor::Wsh(ref wsh) => wsh.script_pubkey(),
Descriptor::Sh(ref sh) => sh.script_pubkey(),
Descriptor::Sh(ref sh) => sh.script_pubkey().expect("TODO: Handle error"),
Descriptor::Tr(ref tr) => tr.script_pubkey(),
}
}
Expand Down Expand Up @@ -1109,13 +1109,15 @@ pub(crate) use write_descriptor;
mod tests {
use core::convert::TryFrom;

use bitcoin::address::script_pubkey::{BuilderExt as _, ScriptExt as _};
use bitcoin::blockdata::opcodes::all::{OP_CLTV, OP_CSV};
use bitcoin::blockdata::script::Instruction;
use bitcoin::blockdata::{opcodes, script};
use bitcoin::hashes::Hash;
use bitcoin::script::PushBytes;
use bitcoin::hashes::hex::FromHex;
use bitcoin::script::{PushBytes, ScriptBufExt as _, ScriptExt as _};
use bitcoin::sighash::EcdsaSighashType;
use bitcoin::{bip32, PublicKey, Sequence, XOnlyPublicKey};
use bitcoin::witness::WitnessExt;
use bitcoin::{bip32, PublicKey, Sequence};

use super::{checksum, *};
use crate::hex_script;
Expand Down Expand Up @@ -1402,7 +1404,7 @@ mod tests {
let ms = ms_str!("c:pk_k({})", pk);

let mut txin = bitcoin::TxIn {
previous_output: bitcoin::OutPoint::default(),
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
script_sig: bitcoin::ScriptBuf::new(),
sequence: Sequence::from_height(100),
witness: Witness::default(),
Expand All @@ -1413,7 +1415,7 @@ mod tests {
assert_eq!(
txin,
bitcoin::TxIn {
previous_output: bitcoin::OutPoint::default(),
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
script_sig: script::Builder::new()
.push_slice(<&PushBytes>::try_from(sigser.as_slice()).unwrap())
.into_script(),
Expand All @@ -1428,10 +1430,10 @@ mod tests {
assert_eq!(
txin,
bitcoin::TxIn {
previous_output: bitcoin::OutPoint::default(),
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
script_sig: script::Builder::new()
.push_slice(<&PushBytes>::try_from(sigser.as_slice()).unwrap())
.push_key(&pk)
.push_key(pk)
.into_script(),
sequence: Sequence::from_height(100),
witness: Witness::default(),
Expand All @@ -1444,7 +1446,7 @@ mod tests {
assert_eq!(
txin,
bitcoin::TxIn {
previous_output: bitcoin::OutPoint::default(),
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
script_sig: bitcoin::ScriptBuf::new(),
sequence: Sequence::from_height(100),
witness: Witness::from_slice(&[sigser.clone(), pk.to_bytes()]),
Expand All @@ -1465,7 +1467,7 @@ mod tests {
assert_eq!(
txin,
bitcoin::TxIn {
previous_output: bitcoin::OutPoint::default(),
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
script_sig: script::Builder::new()
.push_slice(<&PushBytes>::try_from(redeem_script.as_bytes()).unwrap())
.into_script(),
Expand All @@ -1486,7 +1488,7 @@ mod tests {
assert_eq!(
txin,
bitcoin::TxIn {
previous_output: bitcoin::OutPoint::default(),
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
script_sig: script::Builder::new()
.push_slice(<&PushBytes>::try_from(sigser.as_slice()).unwrap())
.push_slice(<&PushBytes>::try_from(ms.encode().as_bytes()).unwrap())
Expand All @@ -1504,7 +1506,7 @@ mod tests {
assert_eq!(
txin,
bitcoin::TxIn {
previous_output: bitcoin::OutPoint::default(),
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
script_sig: bitcoin::ScriptBuf::new(),
sequence: Sequence::from_height(100),
witness: Witness::from_slice(&[sigser.clone(), ms.encode().into_bytes()]),
Expand All @@ -1517,9 +1519,17 @@ mod tests {
assert_eq!(
txin,
bitcoin::TxIn {
previous_output: bitcoin::OutPoint::default(),
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
script_sig: script::Builder::new()
.push_slice(<&PushBytes>::try_from(ms.encode().to_p2wsh().as_bytes()).unwrap())
.push_slice(
<&PushBytes>::try_from(
ms.encode()
.to_p2wsh()
.expect("TODO: Handle error")
.as_bytes()
)
.unwrap()
)
.into_script(),
sequence: Sequence::from_height(100),
witness: Witness::from_slice(&[sigser.clone(), ms.encode().into_bytes()]),
Expand All @@ -1528,7 +1538,15 @@ mod tests {
assert_eq!(
shwsh.unsigned_script_sig(),
script::Builder::new()
.push_slice(<&PushBytes>::try_from(ms.encode().to_p2wsh().as_bytes()).unwrap())
.push_slice(
<&PushBytes>::try_from(
ms.encode()
.to_p2wsh()
.expect("TODO: Handle error")
.as_bytes()
)
.unwrap()
)
.into_script()
);
}
Expand Down Expand Up @@ -1664,7 +1682,7 @@ mod tests {
.unwrap();

let mut txin = bitcoin::TxIn {
previous_output: bitcoin::OutPoint::default(),
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
script_sig: bitcoin::ScriptBuf::new(),
sequence: Sequence::ZERO,
witness: Witness::default(),
Expand Down
Loading
Loading