Skip to content

Commit eb80b0a

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 eb80b0a

26 files changed

+218
-121
lines changed

Diff for: Cargo.toml

+34-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,35 @@ required-features = ["std", "base64", "compiler"]
6969
[workspace]
7070
members = ["fuzz"]
7171
exclude = ["embedded", "bitcoind-tests"]
72+
73+
[patch.crates-io.bitcoin-addresses]
74+
git = "https://github.com/tcharding/rust-bitcoin"
75+
branch = "10-16-set-version-to-alpha"
76+
77+
[patch.crates-io.base58ck]
78+
git = "https://github.com/tcharding/rust-bitcoin"
79+
branch = "10-16-set-version-to-alpha"
80+
81+
[patch.crates-io.bitcoin]
82+
git = "https://github.com/tcharding/rust-bitcoin"
83+
branch = "10-16-set-version-to-alpha"
84+
85+
[patch.crates-io.bitcoin_hashes]
86+
git = "https://github.com/tcharding/rust-bitcoin"
87+
branch = "10-16-set-version-to-alpha"
88+
89+
[patch.crates-io.bitcoin-internals]
90+
git = "https://github.com/tcharding/rust-bitcoin"
91+
branch = "10-16-set-version-to-alpha"
92+
93+
[patch.crates-io.bitcoin-io]
94+
git = "https://github.com/tcharding/rust-bitcoin"
95+
branch = "10-16-set-version-to-alpha"
96+
97+
[patch.crates-io.bitcoin-primitives]
98+
git = "https://github.com/tcharding/rust-bitcoin"
99+
branch = "10-16-set-version-to-alpha"
100+
101+
[patch.crates-io.bitcoin-units]
102+
git = "https://github.com/tcharding/rust-bitcoin"
103+
branch = "10-16-set-version-to-alpha"

Diff for: 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};

Diff for: 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

Diff for: 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

Diff for: 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

Diff for: 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(),

Diff for: 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))

Diff for: 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
)

Diff for: src/descriptor/mod.rs

+15-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,12 +1010,12 @@ 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;
10201020
use bitcoin::{bip32, PublicKey, Sequence};
10211021

@@ -1305,7 +1305,7 @@ mod tests {
13051305
let ms = ms_str!("c:pk_k({})", pk);
13061306

13071307
let mut txin = bitcoin::TxIn {
1308-
previous_output: bitcoin::OutPoint::default(),
1308+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
13091309
script_sig: bitcoin::ScriptBuf::new(),
13101310
sequence: Sequence::from_height(100),
13111311
witness: Witness::default(),
@@ -1316,7 +1316,7 @@ mod tests {
13161316
assert_eq!(
13171317
txin,
13181318
bitcoin::TxIn {
1319-
previous_output: bitcoin::OutPoint::default(),
1319+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
13201320
script_sig: script::Builder::new()
13211321
.push_slice(<&PushBytes>::try_from(sigser.as_slice()).unwrap())
13221322
.into_script(),
@@ -1331,10 +1331,10 @@ mod tests {
13311331
assert_eq!(
13321332
txin,
13331333
bitcoin::TxIn {
1334-
previous_output: bitcoin::OutPoint::default(),
1334+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
13351335
script_sig: script::Builder::new()
13361336
.push_slice(<&PushBytes>::try_from(sigser.as_slice()).unwrap())
1337-
.push_key(&pk)
1337+
.push_key(pk)
13381338
.into_script(),
13391339
sequence: Sequence::from_height(100),
13401340
witness: Witness::default(),
@@ -1347,7 +1347,7 @@ mod tests {
13471347
assert_eq!(
13481348
txin,
13491349
bitcoin::TxIn {
1350-
previous_output: bitcoin::OutPoint::default(),
1350+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
13511351
script_sig: bitcoin::ScriptBuf::new(),
13521352
sequence: Sequence::from_height(100),
13531353
witness: Witness::from_slice(&[sigser.clone(), pk.to_bytes()]),
@@ -1368,7 +1368,7 @@ mod tests {
13681368
assert_eq!(
13691369
txin,
13701370
bitcoin::TxIn {
1371-
previous_output: bitcoin::OutPoint::default(),
1371+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
13721372
script_sig: script::Builder::new()
13731373
.push_slice(<&PushBytes>::try_from(redeem_script.as_bytes()).unwrap())
13741374
.into_script(),
@@ -1389,7 +1389,7 @@ mod tests {
13891389
assert_eq!(
13901390
txin,
13911391
bitcoin::TxIn {
1392-
previous_output: bitcoin::OutPoint::default(),
1392+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
13931393
script_sig: script::Builder::new()
13941394
.push_slice(<&PushBytes>::try_from(sigser.as_slice()).unwrap())
13951395
.push_slice(<&PushBytes>::try_from(ms.encode().as_bytes()).unwrap())
@@ -1407,7 +1407,7 @@ mod tests {
14071407
assert_eq!(
14081408
txin,
14091409
bitcoin::TxIn {
1410-
previous_output: bitcoin::OutPoint::default(),
1410+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
14111411
script_sig: bitcoin::ScriptBuf::new(),
14121412
sequence: Sequence::from_height(100),
14131413
witness: Witness::from_slice(&[sigser.clone(), ms.encode().into_bytes()]),
@@ -1420,9 +1420,9 @@ mod tests {
14201420
assert_eq!(
14211421
txin,
14221422
bitcoin::TxIn {
1423-
previous_output: bitcoin::OutPoint::default(),
1423+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
14241424
script_sig: script::Builder::new()
1425-
.push_slice(<&PushBytes>::try_from(ms.encode().to_p2wsh().as_bytes()).unwrap())
1425+
.push_slice(<&PushBytes>::try_from(ms.encode().to_p2wsh().expect("TODO: Handle error").as_bytes()).unwrap())
14261426
.into_script(),
14271427
sequence: Sequence::from_height(100),
14281428
witness: Witness::from_slice(&[sigser.clone(), ms.encode().into_bytes()]),
@@ -1431,7 +1431,7 @@ mod tests {
14311431
assert_eq!(
14321432
shwsh.unsigned_script_sig(),
14331433
script::Builder::new()
1434-
.push_slice(<&PushBytes>::try_from(ms.encode().to_p2wsh().as_bytes()).unwrap())
1434+
.push_slice(<&PushBytes>::try_from(ms.encode().to_p2wsh().expect("TODO: Handle error").as_bytes()).unwrap())
14351435
.into_script()
14361436
);
14371437
}
@@ -1549,7 +1549,7 @@ mod tests {
15491549
.unwrap();
15501550

15511551
let mut txin = bitcoin::TxIn {
1552-
previous_output: bitcoin::OutPoint::default(),
1552+
previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
15531553
script_sig: bitcoin::ScriptBuf::new(),
15541554
sequence: Sequence::ZERO,
15551555
witness: Witness::default(),

Diff for: src/descriptor/segwitv0.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use core::convert::TryFrom;
99
use core::fmt;
1010

11+
use bitcoin::address::script_pubkey::ScriptExt;
1112
use bitcoin::{Address, Network, ScriptBuf, Weight};
1213

1314
use super::checksum::verify_checksum;
@@ -144,13 +145,13 @@ impl<Pk: MiniscriptKey> Wsh<Pk> {
144145

145146
impl<Pk: MiniscriptKey + ToPublicKey> Wsh<Pk> {
146147
/// Obtains the corresponding script pubkey for this descriptor.
147-
pub fn script_pubkey(&self) -> ScriptBuf { self.inner_script().to_p2wsh() }
148+
pub fn script_pubkey(&self) -> ScriptBuf { self.inner_script().to_p2wsh().expect("TODO: Handle error") }
148149

149150
/// Obtains the corresponding script pubkey for this descriptor.
150151
pub fn address(&self, network: Network) -> Address {
151152
match self.inner {
152-
WshInner::SortedMulti(ref smv) => Address::p2wsh(&smv.encode(), network),
153-
WshInner::Ms(ref ms) => Address::p2wsh(&ms.encode(), network),
153+
WshInner::SortedMulti(ref smv) => Address::p2wsh(&smv.encode(), network).expect("TODO: Handle error"),
154+
WshInner::Ms(ref ms) => Address::p2wsh(&ms.encode(), network).expect("TODO: Handle error"),
154155
}
155156
}
156157

@@ -384,7 +385,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Wpkh<Pk> {
384385
let compressed = bitcoin::key::CompressedPublicKey::try_from(pk)
385386
.expect("wpkh descriptors have compressed keys");
386387

387-
let addr = Address::p2wpkh(&compressed, Network::Bitcoin);
388+
let addr = Address::p2wpkh(compressed, Network::Bitcoin);
388389
addr.script_pubkey()
389390
}
390391

@@ -394,7 +395,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Wpkh<Pk> {
394395
let compressed = bitcoin::key::CompressedPublicKey::try_from(pk)
395396
.expect("Rust Miniscript types don't allow uncompressed pks in segwit descriptors");
396397

397-
Address::p2wpkh(&compressed, network)
398+
Address::p2wpkh(compressed, network)
398399
}
399400

400401
/// Obtains the underlying miniscript for this descriptor.

Diff for: src/descriptor/sh.rs

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

13+
use bitcoin::address::script_pubkey::ScriptExt;
1314
use bitcoin::script::PushBytes;
1415
use bitcoin::{script, Address, Network, ScriptBuf, Weight};
1516

@@ -277,7 +278,7 @@ impl<Pk: MiniscriptKey> Sh<Pk> {
277278

278279
impl<Pk: MiniscriptKey + ToPublicKey> Sh<Pk> {
279280
/// Obtains the corresponding script pubkey for this descriptor.
280-
pub fn script_pubkey(&self) -> ScriptBuf {
281+
pub fn script_pubkey(&self) -> Result<ScriptBuf, bitcoin::script::RedeemScriptSizeError> {
281282
match self.inner {
282283
ShInner::Wsh(ref wsh) => wsh.script_pubkey().to_p2sh(),
283284
ShInner::Wpkh(ref wpkh) => wpkh.script_pubkey().to_p2sh(),
@@ -341,7 +342,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Sh<Pk> {
341342
match self.inner {
342343
ShInner::Wsh(ref wsh) => {
343344
// wsh explicit must contain exactly 1 element
344-
let witness_script = wsh.inner_script().to_p2wsh();
345+
let witness_script = wsh.inner_script().to_p2wsh().expect("TODO: Handle error");
345346
let push_bytes = <&PushBytes>::try_from(witness_script.as_bytes())
346347
.expect("Witness script is not too large");
347348
script::Builder::new().push_slice(push_bytes).into_script()

0 commit comments

Comments
 (0)