Skip to content

Commit e8d2aca

Browse files
committed
WIP: Track rust-bitcoin master branch
As we develop `primitives` it is useful to have crates using the changes to catch mistakes as we go.
1 parent 1e40a8d commit e8d2aca

27 files changed

+267
-126
lines changed

Cargo.toml

+32-2
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ base64 = ["bitcoin/base64"]
2424

2525
[dependencies]
2626
bech32 = { version = "0.11.0", default-features = false }
27-
bitcoin = { version = "0.32.0", default-features = false }
27+
bitcoin = { version = "0.33.0-alpha", default-features = false }
2828

2929
# Do NOT use this as a feature! Use the `serde` feature instead.
3030
actual-serde = { package = "serde", version = "1.0.103", optional = true }
3131

3232
[dev-dependencies]
3333
serde_test = "1.0.147"
34-
bitcoin = { version = "0.32.0", features = ["base64"] }
34+
bitcoin = { version = "0.33.0-alpha", features = ["base64"] }
3535
secp256k1 = {version = "0.29.0", features = ["rand-std"]}
3636

3737
[[example]]
@@ -69,3 +69,33 @@ required-features = ["std", "base64", "compiler"]
6969
[workspace]
7070
members = ["fuzz"]
7171
exclude = ["embedded", "bitcoind-tests"]
72+
73+
# Patch rust-bitcoin crates, use `branch` here because its easier when testing new branches (worktrees).
74+
75+
[patch.crates-io.base58ck]
76+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
77+
branch = "master"
78+
79+
[patch.crates-io.bitcoin]
80+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
81+
branch = "master"
82+
83+
[patch.crates-io.bitcoin_hashes]
84+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
85+
branch = "master"
86+
87+
[patch.crates-io.bitcoin-internals]
88+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
89+
branch = "master"
90+
91+
[patch.crates-io.bitcoin-io]
92+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
93+
branch = "master"
94+
95+
[patch.crates-io.bitcoin-primitives]
96+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
97+
branch = "master"
98+
99+
[patch.crates-io.bitcoin-units]
100+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
101+
branch = "master"

bitcoind-tests/Cargo.toml

+44
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,47 @@ secp256k1 = {version = "0.29.0", features = ["rand-std"]}
3232
"0_19_1" = ["bitcoind/0_19_1"]
3333
"0_18_1" = ["bitcoind/0_18_1"]
3434
"0_17_1" = ["bitcoind/0_17_1"]
35+
36+
# Patch crates from bitcoind-json-rpc repo.
37+
38+
[patch.crates-io.bitcoind-json-rpc-client]
39+
git = "https://github.com/tcharding/rust-bitcoind-json-rpc"
40+
branch = "track-bitcoin-master"
41+
42+
[patch.crates-io.bitcoind-json-rpc-regtest]
43+
git = "https://github.com/tcharding/rust-bitcoind-json-rpc"
44+
branch = "track-bitcoin-master"
45+
46+
[patch.crates-io.bitcoind-json-rpc-types]
47+
git = "https://github.com/tcharding/rust-bitcoind-json-rpc"
48+
branch = "track-bitcoin-master"
49+
50+
# Patch rust-bitcoin crates, use `branch` here because its easier when testing new branches (worktrees).
51+
52+
[patch.crates-io.base58ck]
53+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
54+
branch = "master"
55+
56+
[patch.crates-io.bitcoin]
57+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
58+
branch = "master"
59+
60+
[patch.crates-io.bitcoin_hashes]
61+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
62+
branch = "master"
63+
64+
[patch.crates-io.bitcoin-internals]
65+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
66+
branch = "master"
67+
68+
[patch.crates-io.bitcoin-io]
69+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
70+
branch = "master"
71+
72+
[patch.crates-io.bitcoin-primitives]
73+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
74+
branch = "master"
75+
76+
[patch.crates-io.bitcoin-units]
77+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
78+
branch = "master"

bitcoind-tests/tests/setup/test_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use std::str::FromStr;
2121

2222
use actual_rand as rand;
23-
use bitcoin::hashes::{hash160, ripemd160, sha256, Hash};
23+
use bitcoin::hashes::{hash160, ripemd160, sha256};
2424
use bitcoin::hex::DisplayHex;
2525
use bitcoin::secp256k1;
2626
use miniscript::descriptor::{SinglePub, SinglePubKey};

bitcoind-tests/tests/test_cpp.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ use std::fs::File;
99
use std::io::{self, BufRead};
1010
use std::path::Path;
1111

12-
use bitcoin::hashes::{sha256d, Hash};
12+
use bitcoin::hashes::sha256d;
1313
use bitcoin::psbt::Psbt;
14+
use bitcoin::transaction::OutPointExt as _;
1415
use bitcoin::{
1516
psbt, secp256k1, transaction, Amount, OutPoint, Sequence, Transaction, TxIn, TxOut, Txid,
1617
};
@@ -119,7 +120,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
119120
// processed correctly.
120121
// We waited 50 blocks, keep 49 for safety
121122
sequence: Sequence::from_height(49),
122-
..Default::default()
123+
..TxIn::EMPTY_COINBASE
123124
};
124125
psbt.unsigned_tx.input.push(txin);
125126
// Get a new script pubkey from the node so that

bitcoind-tests/tests/test_desc.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ use std::{error, fmt};
99

1010
use actual_rand as rand;
1111
use bitcoin::blockdata::witness::Witness;
12-
use bitcoin::hashes::{sha256d, Hash};
12+
use bitcoin::hashes::sha256d;
1313
use bitcoin::psbt::Psbt;
1414
use bitcoin::sighash::SighashCache;
1515
use bitcoin::taproot::{LeafVersion, TapLeafHash};
16+
use bitcoin::transaction::OutPointExt as _;
1617
use bitcoin::{
1718
absolute, psbt, secp256k1, sighash, transaction, Amount, OutPoint, Sequence, Transaction, TxIn,
1819
TxOut, Txid,
@@ -127,7 +128,7 @@ pub fn test_desc_satisfy(
127128
// processed correctly.
128129
// We waited 2 blocks, keep 1 for safety
129130
sequence: Sequence::from_height(1),
130-
..Default::default()
131+
..TxIn::EMPTY_COINBASE
131132
};
132133
psbt.unsigned_tx.input.push(txin);
133134
// Get a new script pubkey from the node so that

examples/psbt_sign_finalize.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
use std::collections::BTreeMap;
44
use std::str::FromStr;
55

6+
use bitcoin::transaction::OutPointExt as _;
7+
68
use miniscript::bitcoin::consensus::encode::deserialize;
79
use miniscript::bitcoin::hashes::hex::FromHex;
810
use miniscript::bitcoin::psbt::{self, Psbt};
@@ -84,7 +86,7 @@ fn main() {
8486
let txin = TxIn {
8587
previous_output: outpoint,
8688
sequence: Sequence::from_height(26),
87-
..Default::default()
89+
..TxIn::EMPTY_COINBASE
8890
};
8991
psbt.unsigned_tx.input.push(txin);
9092

examples/sign_multisig.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::collections::HashMap;
66
use std::str::FromStr;
77

88
use bitcoin::blockdata::witness::Witness;
9-
use bitcoin::{absolute, ecdsa, transaction, Amount, Sequence};
9+
use bitcoin::{absolute, ecdsa, transaction, Amount, Sequence, OutPoint};
1010

1111
fn main() {
1212
let mut tx = spending_transaction();
@@ -81,7 +81,7 @@ fn spending_transaction() -> bitcoin::Transaction {
8181
version: transaction::Version::TWO,
8282
lock_time: absolute::LockTime::ZERO,
8383
input: vec![bitcoin::TxIn {
84-
previous_output: Default::default(),
84+
previous_output: OutPoint::COINBASE_PREVOUT,
8585
script_sig: bitcoin::ScriptBuf::new(),
8686
sequence: Sequence::MAX,
8787
witness: Witness::default(),

src/descriptor/bare.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use core::fmt;
1111

1212
use bitcoin::script::{self, PushBytes};
13+
use bitcoin::address::script_pubkey::BuilderExt as _;
1314
use bitcoin::{Address, Network, ScriptBuf, Weight};
1415

1516
use super::checksum::verify_checksum;
@@ -300,7 +301,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Pkh<Pk> {
300301
// serialize() does not allocate here
301302
sig.serialize().as_ref(),
302303
)
303-
.push_key(&self.pk.to_public_key())
304+
.push_key(self.pk.to_public_key())
304305
.into_script();
305306
let witness = vec![];
306307
Ok((witness, script_sig))

src/descriptor/key.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use core::str::FromStr;
66
#[cfg(feature = "std")]
77
use std::error;
88

9-
use bitcoin::bip32::{self, XKeyIdentifier};
10-
use bitcoin::hashes::{hash160, ripemd160, sha256, Hash, HashEngine};
9+
use bitcoin::bip32;
10+
use bitcoin::hashes::{hash160, ripemd160, sha256, HashEngine};
1111
use bitcoin::key::XOnlyPublicKey;
1212
use bitcoin::secp256k1::{Secp256k1, Signing, Verification};
1313

@@ -222,8 +222,7 @@ impl DescriptorXKey<bip32::Xpriv> {
222222

223223
let xprv = self
224224
.xkey
225-
.derive_priv(secp, &hardened_path)
226-
.map_err(|_| DescriptorKeyParseError("Unable to derive the hardened steps"))?;
225+
.derive_priv(secp, &hardened_path);
227226
let xpub = bip32::Xpub::from_priv(secp, &xprv);
228227

229228
let origin = match &self.origin {
@@ -524,15 +523,17 @@ impl DescriptorPublicKey {
524523
if let Some((fingerprint, _)) = single.origin {
525524
fingerprint
526525
} else {
527-
let mut engine = XKeyIdentifier::engine();
526+
let mut engine = hash160::Hash::engine();
528527
match single.key {
529528
SinglePubKey::FullKey(pk) => {
530529
pk.write_into(&mut engine).expect("engines don't error")
531530
}
532531
SinglePubKey::XOnly(x_only_pk) => engine.input(&x_only_pk.serialize()),
533532
};
533+
// FIXME: Fix the bip32 API for creating fingerprint?
534+
let xkey_id = hash160::Hash::from_engine(engine);
534535
bip32::Fingerprint::from(
535-
&XKeyIdentifier::from_engine(engine)[..4]
536+
&xkey_id.as_byte_array()[..4]
536537
.try_into()
537538
.expect("4 byte slice"),
538539
)

src/descriptor/mod.rs

+16-15
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
405405
Descriptor::Pkh(ref pkh) => pkh.script_pubkey(),
406406
Descriptor::Wpkh(ref wpkh) => wpkh.script_pubkey(),
407407
Descriptor::Wsh(ref wsh) => wsh.script_pubkey(),
408-
Descriptor::Sh(ref sh) => sh.script_pubkey(),
408+
Descriptor::Sh(ref sh) => sh.script_pubkey().expect("TODO: Handle error"),
409409
Descriptor::Tr(ref tr) => tr.script_pubkey(),
410410
}
411411
}
@@ -1010,13 +1010,14 @@ pub(crate) use write_descriptor;
10101010
mod tests {
10111011
use core::convert::TryFrom;
10121012

1013+
use bitcoin::address::script_pubkey::{BuilderExt as _, ScriptExt as _};
10131014
use bitcoin::blockdata::opcodes::all::{OP_CLTV, OP_CSV};
10141015
use bitcoin::blockdata::script::Instruction;
10151016
use bitcoin::blockdata::{opcodes, script};
10161017
use bitcoin::hashes::hex::FromHex;
1017-
use bitcoin::hashes::Hash;
1018-
use bitcoin::script::PushBytes;
1018+
use bitcoin::script::{PushBytes, ScriptExt as _, ScriptBufExt as _};
10191019
use bitcoin::sighash::EcdsaSighashType;
1020+
use bitcoin::witness::WitnessExt;
10201021
use bitcoin::{bip32, PublicKey, Sequence};
10211022

10221023
use super::checksum::desc_checksum;
@@ -1305,7 +1306,7 @@ mod tests {
13051306
let ms = ms_str!("c:pk_k({})", pk);
13061307

13071308
let mut txin = bitcoin::TxIn {
1308-
previous_output: bitcoin::OutPoint::default(),
1309+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
13091310
script_sig: bitcoin::ScriptBuf::new(),
13101311
sequence: Sequence::from_height(100),
13111312
witness: Witness::default(),
@@ -1316,7 +1317,7 @@ mod tests {
13161317
assert_eq!(
13171318
txin,
13181319
bitcoin::TxIn {
1319-
previous_output: bitcoin::OutPoint::default(),
1320+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
13201321
script_sig: script::Builder::new()
13211322
.push_slice(<&PushBytes>::try_from(sigser.as_slice()).unwrap())
13221323
.into_script(),
@@ -1331,10 +1332,10 @@ mod tests {
13311332
assert_eq!(
13321333
txin,
13331334
bitcoin::TxIn {
1334-
previous_output: bitcoin::OutPoint::default(),
1335+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
13351336
script_sig: script::Builder::new()
13361337
.push_slice(<&PushBytes>::try_from(sigser.as_slice()).unwrap())
1337-
.push_key(&pk)
1338+
.push_key(pk)
13381339
.into_script(),
13391340
sequence: Sequence::from_height(100),
13401341
witness: Witness::default(),
@@ -1347,7 +1348,7 @@ mod tests {
13471348
assert_eq!(
13481349
txin,
13491350
bitcoin::TxIn {
1350-
previous_output: bitcoin::OutPoint::default(),
1351+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
13511352
script_sig: bitcoin::ScriptBuf::new(),
13521353
sequence: Sequence::from_height(100),
13531354
witness: Witness::from_slice(&[sigser.clone(), pk.to_bytes()]),
@@ -1368,7 +1369,7 @@ mod tests {
13681369
assert_eq!(
13691370
txin,
13701371
bitcoin::TxIn {
1371-
previous_output: bitcoin::OutPoint::default(),
1372+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
13721373
script_sig: script::Builder::new()
13731374
.push_slice(<&PushBytes>::try_from(redeem_script.as_bytes()).unwrap())
13741375
.into_script(),
@@ -1389,7 +1390,7 @@ mod tests {
13891390
assert_eq!(
13901391
txin,
13911392
bitcoin::TxIn {
1392-
previous_output: bitcoin::OutPoint::default(),
1393+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
13931394
script_sig: script::Builder::new()
13941395
.push_slice(<&PushBytes>::try_from(sigser.as_slice()).unwrap())
13951396
.push_slice(<&PushBytes>::try_from(ms.encode().as_bytes()).unwrap())
@@ -1407,7 +1408,7 @@ mod tests {
14071408
assert_eq!(
14081409
txin,
14091410
bitcoin::TxIn {
1410-
previous_output: bitcoin::OutPoint::default(),
1411+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
14111412
script_sig: bitcoin::ScriptBuf::new(),
14121413
sequence: Sequence::from_height(100),
14131414
witness: Witness::from_slice(&[sigser.clone(), ms.encode().into_bytes()]),
@@ -1420,9 +1421,9 @@ mod tests {
14201421
assert_eq!(
14211422
txin,
14221423
bitcoin::TxIn {
1423-
previous_output: bitcoin::OutPoint::default(),
1424+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
14241425
script_sig: script::Builder::new()
1425-
.push_slice(<&PushBytes>::try_from(ms.encode().to_p2wsh().as_bytes()).unwrap())
1426+
.push_slice(<&PushBytes>::try_from(ms.encode().to_p2wsh().expect("TODO: Handle error").as_bytes()).unwrap())
14261427
.into_script(),
14271428
sequence: Sequence::from_height(100),
14281429
witness: Witness::from_slice(&[sigser.clone(), ms.encode().into_bytes()]),
@@ -1431,7 +1432,7 @@ mod tests {
14311432
assert_eq!(
14321433
shwsh.unsigned_script_sig(),
14331434
script::Builder::new()
1434-
.push_slice(<&PushBytes>::try_from(ms.encode().to_p2wsh().as_bytes()).unwrap())
1435+
.push_slice(<&PushBytes>::try_from(ms.encode().to_p2wsh().expect("TODO: Handle error").as_bytes()).unwrap())
14351436
.into_script()
14361437
);
14371438
}
@@ -1549,7 +1550,7 @@ mod tests {
15491550
.unwrap();
15501551

15511552
let mut txin = bitcoin::TxIn {
1552-
previous_output: bitcoin::OutPoint::default(),
1553+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
15531554
script_sig: bitcoin::ScriptBuf::new(),
15541555
sequence: Sequence::ZERO,
15551556
witness: Witness::default(),

0 commit comments

Comments
 (0)