Skip to content

Commit

Permalink
WIP: Track rust-bitcoin master branch
Browse files Browse the repository at this point in the history
As we develop `primitives` it is useful to have crates using the changes
to catch mistakes as we go.
  • Loading branch information
tcharding committed Oct 27, 2024
1 parent 1e40a8d commit e8d2aca
Show file tree
Hide file tree
Showing 27 changed files with 267 additions and 126 deletions.
34 changes: 32 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ base64 = ["bitcoin/base64"]

[dependencies]
bech32 = { version = "0.11.0", default-features = false }
bitcoin = { version = "0.32.0", default-features = false }
bitcoin = { version = "0.33.0-alpha", default-features = false }

# Do NOT use this as a feature! Use the `serde` feature instead.
actual-serde = { package = "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 @@ -69,3 +69,33 @@ required-features = ["std", "base64", "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
5 changes: 3 additions & 2 deletions bitcoind-tests/tests/test_desc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ use std::{error, fmt};

use actual_rand as rand;
use bitcoin::blockdata::witness::Witness;
use bitcoin::hashes::{sha256d, Hash};
use bitcoin::hashes::sha256d;
use bitcoin::psbt::Psbt;
use bitcoin::sighash::SighashCache;
use bitcoin::taproot::{LeafVersion, TapLeafHash};
use bitcoin::transaction::OutPointExt as _;
use bitcoin::{
absolute, psbt, secp256k1, sighash, transaction, Amount, OutPoint, Sequence, Transaction, TxIn,
TxOut, Txid,
Expand Down Expand Up @@ -127,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
4 changes: 3 additions & 1 deletion examples/psbt_sign_finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
use std::collections::BTreeMap;
use std::str::FromStr;

use bitcoin::transaction::OutPointExt as _;

use miniscript::bitcoin::consensus::encode::deserialize;
use miniscript::bitcoin::hashes::hex::FromHex;
use miniscript::bitcoin::psbt::{self, Psbt};
Expand Down Expand Up @@ -84,7 +86,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, Sequence, OutPoint};

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 @@ -10,6 +10,7 @@
use core::fmt;

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

use super::checksum::verify_checksum;
Expand Down Expand Up @@ -300,7 +301,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
13 changes: 7 additions & 6 deletions src/descriptor/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ 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::bip32;
use bitcoin::hashes::{hash160, ripemd160, sha256, HashEngine};
use bitcoin::key::XOnlyPublicKey;
use bitcoin::secp256k1::{Secp256k1, Signing, Verification};

Expand Down Expand Up @@ -222,8 +222,7 @@ impl DescriptorXKey<bip32::Xpriv> {

let xprv = self
.xkey
.derive_priv(secp, &hardened_path)
.map_err(|_| DescriptorKeyParseError("Unable to derive the hardened steps"))?;
.derive_priv(secp, &hardened_path);
let xpub = bip32::Xpub::from_priv(secp, &xprv);

let origin = match &self.origin {
Expand Down Expand Up @@ -524,15 +523,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
31 changes: 16 additions & 15 deletions src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,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 @@ -1010,13 +1010,14 @@ 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::hex::FromHex;
use bitcoin::hashes::Hash;
use bitcoin::script::PushBytes;
use bitcoin::script::{PushBytes, ScriptExt as _, ScriptBufExt as _};
use bitcoin::sighash::EcdsaSighashType;
use bitcoin::witness::WitnessExt;
use bitcoin::{bip32, PublicKey, Sequence};

use super::checksum::desc_checksum;
Expand Down Expand Up @@ -1305,7 +1306,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 @@ -1316,7 +1317,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 @@ -1331,10 +1332,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 @@ -1347,7 +1348,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 @@ -1368,7 +1369,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 @@ -1389,7 +1390,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 @@ -1407,7 +1408,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 @@ -1420,9 +1421,9 @@ 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 @@ -1431,7 +1432,7 @@ 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 @@ -1549,7 +1550,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

0 comments on commit e8d2aca

Please # to comment.