Skip to content

Commit 81f133a

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 1fafde2 commit 81f133a

File tree

27 files changed

+329
-148
lines changed

27 files changed

+329
-148
lines changed

Cargo.toml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ base64 = ["bitcoin/base64"]
2323

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

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

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

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

bitcoind-tests/Cargo.toml

Lines changed: 44 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +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};
13-
use bitcoin::key::TapTweak as _;
12+
use bitcoin::hashes::sha256d;
1413
use bitcoin::psbt::Psbt;
1514
use bitcoin::sighash::SighashCache;
16-
use bitcoin::taproot::{LeafVersion, TapLeafHash};
15+
use bitcoin::taproot::{LeafVersion, TapLeafHash, TapTweakHashExt as _, TapLeafHashExt as _};
16+
use bitcoin::transaction::OutPointExt as _;
1717
use bitcoin::{
1818
absolute, psbt, secp256k1, sighash, transaction, Amount, OutPoint, Sequence, Transaction, TxIn,
1919
TxOut, Txid,
@@ -128,7 +128,7 @@ pub fn test_desc_satisfy(
128128
// processed correctly.
129129
// We waited 2 blocks, keep 1 for safety
130130
sequence: Sequence::from_height(1),
131-
..Default::default()
131+
..TxIn::EMPTY_COINBASE
132132
};
133133
psbt.unsigned_tx.input.push(txin);
134134
// Get a new script pubkey from the node so that

examples/psbt_sign_finalize.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
use std::collections::BTreeMap;
44
use std::str::FromStr;
55

6-
use miniscript::bitcoin::consensus::encode::deserialize_hex;
6+
use bitcoin::transaction::OutPointExt as _;
7+
use miniscript::bitcoin::consensus::encode::deserialize;
8+
use miniscript::bitcoin::hashes::hex::FromHex;
79
use miniscript::bitcoin::psbt::{self, Psbt};
810
use miniscript::bitcoin::sighash::SighashCache;
911
//use miniscript::bitcoin::secp256k1; // https://github.com/rust-lang/rust/issues/121684
@@ -83,7 +85,7 @@ fn main() {
8385
let txin = TxIn {
8486
previous_output: outpoint,
8587
sequence: Sequence::from_height(26),
86-
..Default::default()
88+
..TxIn::EMPTY_COINBASE
8789
};
8890
psbt.unsigned_tx.input.push(txin);
8991

examples/sign_multisig.rs

Lines changed: 2 additions & 2 deletions
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, OutPoint, Sequence};
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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
1010
use core::fmt;
1111

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

@@ -298,7 +299,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Pkh<Pk> {
298299
// serialize() does not allocate here
299300
sig.serialize().as_ref(),
300301
)
301-
.push_key(&self.pk.to_public_key())
302+
.push_key(self.pk.to_public_key())
302303
.into_script();
303304
let witness = vec![];
304305
Ok((witness, script_sig))

src/descriptor/key.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ 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};
11-
use bitcoin::key::{PublicKey, XOnlyPublicKey};
9+
use bitcoin::bip32;
10+
use bitcoin::hashes::{hash160, ripemd160, sha256, HashEngine};
11+
use bitcoin::key::XOnlyPublicKey;
1212
use bitcoin::secp256k1::{Secp256k1, Signing, Verification};
1313
use bitcoin::NetworkKind;
1414

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

235-
let xprv = self
236-
.xkey
237-
.derive_priv(secp, &hardened_path)
238-
.map_err(DescriptorKeyParseError::DeriveHardenedKey)?;
239-
235+
let xprv = self.xkey.derive_priv(secp, &hardened_path);
240236
let xpub = bip32::Xpub::from_priv(secp, &xprv);
241237

242238
let origin = match &self.origin {
@@ -723,15 +719,17 @@ impl DescriptorPublicKey {
723719
if let Some((fingerprint, _)) = single.origin {
724720
fingerprint
725721
} else {
726-
let mut engine = XKeyIdentifier::engine();
722+
let mut engine = hash160::Hash::engine();
727723
match single.key {
728724
SinglePubKey::FullKey(pk) => {
729725
pk.write_into(&mut engine).expect("engines don't error")
730726
}
731727
SinglePubKey::XOnly(x_only_pk) => engine.input(&x_only_pk.serialize()),
732728
};
729+
// FIXME: Fix the bip32 API for creating fingerprint?
730+
let xkey_id = hash160::Hash::from_engine(engine);
733731
bip32::Fingerprint::from(
734-
&XKeyIdentifier::from_engine(engine)[..4]
732+
&xkey_id.as_byte_array()[..4]
735733
.try_into()
736734
.expect("4 byte slice"),
737735
)

src/descriptor/mod.rs

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
468468
Descriptor::Pkh(ref pkh) => pkh.script_pubkey(),
469469
Descriptor::Wpkh(ref wpkh) => wpkh.script_pubkey(),
470470
Descriptor::Wsh(ref wsh) => wsh.script_pubkey(),
471-
Descriptor::Sh(ref sh) => sh.script_pubkey(),
471+
Descriptor::Sh(ref sh) => sh.script_pubkey().expect("TODO: Handle error"),
472472
Descriptor::Tr(ref tr) => tr.script_pubkey(),
473473
}
474474
}
@@ -1109,13 +1109,15 @@ pub(crate) use write_descriptor;
11091109
mod tests {
11101110
use core::convert::TryFrom;
11111111

1112+
use bitcoin::address::script_pubkey::{BuilderExt as _, ScriptExt as _};
11121113
use bitcoin::blockdata::opcodes::all::{OP_CLTV, OP_CSV};
11131114
use bitcoin::blockdata::script::Instruction;
11141115
use bitcoin::blockdata::{opcodes, script};
1115-
use bitcoin::hashes::Hash;
1116-
use bitcoin::script::PushBytes;
1116+
use bitcoin::hashes::hex::FromHex;
1117+
use bitcoin::script::{PushBytes, ScriptBufExt as _, ScriptExt as _};
11171118
use bitcoin::sighash::EcdsaSighashType;
1118-
use bitcoin::{bip32, PublicKey, Sequence, XOnlyPublicKey};
1119+
use bitcoin::witness::WitnessExt;
1120+
use bitcoin::{bip32, PublicKey, Sequence};
11191121

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

14041406
let mut txin = bitcoin::TxIn {
1405-
previous_output: bitcoin::OutPoint::default(),
1407+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
14061408
script_sig: bitcoin::ScriptBuf::new(),
14071409
sequence: Sequence::from_height(100),
14081410
witness: Witness::default(),
@@ -1413,7 +1415,7 @@ mod tests {
14131415
assert_eq!(
14141416
txin,
14151417
bitcoin::TxIn {
1416-
previous_output: bitcoin::OutPoint::default(),
1418+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
14171419
script_sig: script::Builder::new()
14181420
.push_slice(<&PushBytes>::try_from(sigser.as_slice()).unwrap())
14191421
.into_script(),
@@ -1428,10 +1430,10 @@ mod tests {
14281430
assert_eq!(
14291431
txin,
14301432
bitcoin::TxIn {
1431-
previous_output: bitcoin::OutPoint::default(),
1433+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
14321434
script_sig: script::Builder::new()
14331435
.push_slice(<&PushBytes>::try_from(sigser.as_slice()).unwrap())
1434-
.push_key(&pk)
1436+
.push_key(pk)
14351437
.into_script(),
14361438
sequence: Sequence::from_height(100),
14371439
witness: Witness::default(),
@@ -1444,7 +1446,7 @@ mod tests {
14441446
assert_eq!(
14451447
txin,
14461448
bitcoin::TxIn {
1447-
previous_output: bitcoin::OutPoint::default(),
1449+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
14481450
script_sig: bitcoin::ScriptBuf::new(),
14491451
sequence: Sequence::from_height(100),
14501452
witness: Witness::from_slice(&[sigser.clone(), pk.to_bytes()]),
@@ -1465,7 +1467,7 @@ mod tests {
14651467
assert_eq!(
14661468
txin,
14671469
bitcoin::TxIn {
1468-
previous_output: bitcoin::OutPoint::default(),
1470+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
14691471
script_sig: script::Builder::new()
14701472
.push_slice(<&PushBytes>::try_from(redeem_script.as_bytes()).unwrap())
14711473
.into_script(),
@@ -1486,7 +1488,7 @@ mod tests {
14861488
assert_eq!(
14871489
txin,
14881490
bitcoin::TxIn {
1489-
previous_output: bitcoin::OutPoint::default(),
1491+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
14901492
script_sig: script::Builder::new()
14911493
.push_slice(<&PushBytes>::try_from(sigser.as_slice()).unwrap())
14921494
.push_slice(<&PushBytes>::try_from(ms.encode().as_bytes()).unwrap())
@@ -1504,7 +1506,7 @@ mod tests {
15041506
assert_eq!(
15051507
txin,
15061508
bitcoin::TxIn {
1507-
previous_output: bitcoin::OutPoint::default(),
1509+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
15081510
script_sig: bitcoin::ScriptBuf::new(),
15091511
sequence: Sequence::from_height(100),
15101512
witness: Witness::from_slice(&[sigser.clone(), ms.encode().into_bytes()]),
@@ -1517,9 +1519,17 @@ mod tests {
15171519
assert_eq!(
15181520
txin,
15191521
bitcoin::TxIn {
1520-
previous_output: bitcoin::OutPoint::default(),
1522+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
15211523
script_sig: script::Builder::new()
1522-
.push_slice(<&PushBytes>::try_from(ms.encode().to_p2wsh().as_bytes()).unwrap())
1524+
.push_slice(
1525+
<&PushBytes>::try_from(
1526+
ms.encode()
1527+
.to_p2wsh()
1528+
.expect("TODO: Handle error")
1529+
.as_bytes()
1530+
)
1531+
.unwrap()
1532+
)
15231533
.into_script(),
15241534
sequence: Sequence::from_height(100),
15251535
witness: Witness::from_slice(&[sigser.clone(), ms.encode().into_bytes()]),
@@ -1528,7 +1538,15 @@ mod tests {
15281538
assert_eq!(
15291539
shwsh.unsigned_script_sig(),
15301540
script::Builder::new()
1531-
.push_slice(<&PushBytes>::try_from(ms.encode().to_p2wsh().as_bytes()).unwrap())
1541+
.push_slice(
1542+
<&PushBytes>::try_from(
1543+
ms.encode()
1544+
.to_p2wsh()
1545+
.expect("TODO: Handle error")
1546+
.as_bytes()
1547+
)
1548+
.unwrap()
1549+
)
15321550
.into_script()
15331551
);
15341552
}
@@ -1664,7 +1682,7 @@ mod tests {
16641682
.unwrap();
16651683

16661684
let mut txin = bitcoin::TxIn {
1667-
previous_output: bitcoin::OutPoint::default(),
1685+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
16681686
script_sig: bitcoin::ScriptBuf::new(),
16691687
sequence: Sequence::ZERO,
16701688
witness: Witness::default(),

0 commit comments

Comments
 (0)