Skip to content

Commit e548653

Browse files
committed
Merge #606: Upgrade to rust-bitcoin 0.28
0016458 Stop using deprecated structs (Alekos Filini) a16c182 Upgrade to rust-bitcoin 0.28 and miniscript 7.0 (Alekos Filini) Pull request description: ### Description Upgrade all our dependencies to work with the new release of rust-bitcoin ### Notes to the reviewers The commits in this pr were originally part of #593 ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing #### New Features: * [x] I've updated `CHANGELOG.md` ACKs for top commit: rajarshimaitra: ACK 0016458 Tree-SHA512: eef7e94246e619686b4dfffd6e4cb685630fe2eaf9447f2f0b49ed2643d67f81c50e0d89b66267db4552a05e58f638d885eb7056270648403f716803fce9e275
2 parents 7aa2746 + 0016458 commit e548653

File tree

15 files changed

+422
-326
lines changed

15 files changed

+422
-326
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
- added `OldestFirstCoinSelection` impl to `CoinSelectionAlgorithm`
1010
- New MSRV set to `1.56`
1111
- Add traits to reuse `Blockchain`s across multiple wallets (`BlockchainFactory` and `StatelessBlockchain`).
12+
- Upgrade to rust-bitcoin `0.28`
1213

1314

1415
## [v0.18.0] - [v0.17.0]

Cargo.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ license = "MIT OR Apache-2.0"
1414
[dependencies]
1515
bdk-macros = "^0.6"
1616
log = "^0.4"
17-
miniscript = { version = "^6.1", features = ["use-serde"] }
18-
bitcoin = { version = "^0.27", features = ["use-serde", "base64"] }
17+
miniscript = { version = "7.0", features = ["use-serde"] }
18+
bitcoin = { version = "0.28", features = ["use-serde", "base64"] }
1919
serde = { version = "^1.0", features = ["derive"] }
2020
serde_json = { version = "^1.0" }
2121
rand = "^0.7"
2222

2323
# Optional dependencies
2424
sled = { version = "0.34", optional = true }
25-
electrum-client = { version = "0.8", optional = true }
25+
electrum-client = { version = "0.10", optional = true }
2626
rusqlite = { version = "0.25.3", optional = true }
2727
ahash = { version = "=0.7.4", optional = true }
2828
reqwest = { version = "0.11", optional = true, default-features = false, features = ["json"] }
@@ -37,8 +37,8 @@ lazy_static = { version = "1.4", optional = true }
3737
bip39 = { version = "1.0.1", optional = true }
3838
bitcoinconsensus = { version = "0.19.0-3", optional = true }
3939

40-
# Needed by bdk_blockchain_tests macro
41-
bitcoincore-rpc = { version = "0.14", optional = true }
40+
# Needed by bdk_blockchain_tests macro and the `rpc` feature
41+
bitcoincore-rpc = { version = "0.15", optional = true }
4242

4343
# Platform-specific dependencies
4444
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
@@ -97,7 +97,7 @@ test-md-docs = ["electrum"]
9797
lazy_static = "1.4"
9898
env_logger = "0.7"
9999
clap = "2.33"
100-
electrsd = { version= "0.15", features = ["trigger", "bitcoind_22_0"] }
100+
electrsd = { version= "0.19.1", features = ["bitcoind_22_0"] }
101101

102102
[[example]]
103103
name = "address_validator"

src/blockchain/compact_filters/peer.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// licenses.
1111

1212
use std::collections::HashMap;
13+
use std::io::BufReader;
1314
use std::net::{TcpStream, ToSocketAddrs};
1415
use std::sync::{Arc, Condvar, Mutex, RwLock};
1516
use std::thread;
@@ -19,14 +20,13 @@ use socks::{Socks5Stream, ToTargetAddr};
1920

2021
use rand::{thread_rng, Rng};
2122

22-
use bitcoin::consensus::Encodable;
23+
use bitcoin::consensus::{Decodable, Encodable};
2324
use bitcoin::hash_types::BlockHash;
2425
use bitcoin::network::constants::ServiceFlags;
2526
use bitcoin::network::message::{NetworkMessage, RawNetworkMessage};
2627
use bitcoin::network::message_blockdata::*;
2728
use bitcoin::network::message_filter::*;
2829
use bitcoin::network::message_network::VersionMessage;
29-
use bitcoin::network::stream_reader::StreamReader;
3030
use bitcoin::network::Address;
3131
use bitcoin::{Block, Network, Transaction, Txid, Wtxid};
3232

@@ -327,9 +327,10 @@ impl Peer {
327327
};
328328
}
329329

330-
let mut reader = StreamReader::new(connection, None);
330+
let mut reader = BufReader::new(connection);
331331
loop {
332-
let raw_message: RawNetworkMessage = check_disconnect!(reader.read_next());
332+
let raw_message: RawNetworkMessage =
333+
check_disconnect!(Decodable::consensus_decode(&mut reader));
333334

334335
let in_message = if raw_message.magic != network.magic() {
335336
continue;

src/blockchain/esplora/api.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! see: <https://github.com/Blockstream/esplora/blob/master/API.md>
44
use crate::BlockTime;
5-
use bitcoin::{OutPoint, Script, Transaction, TxIn, TxOut, Txid};
5+
use bitcoin::{OutPoint, Script, Transaction, TxIn, TxOut, Txid, Witness};
66

77
#[derive(serde::Deserialize, Clone, Debug)]
88
pub struct PrevOut {
@@ -63,7 +63,7 @@ impl Tx {
6363
},
6464
script_sig: vin.scriptsig,
6565
sequence: vin.sequence,
66-
witness: vin.witness,
66+
witness: Witness::from_vec(vin.witness),
6767
})
6868
.collect(),
6969
output: self

src/descriptor/derived.rs

+33-10
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ use std::hash::{Hash, Hasher};
5252
use std::ops::Deref;
5353

5454
use bitcoin::hashes::hash160;
55-
use bitcoin::PublicKey;
55+
use bitcoin::{PublicKey, XOnlyPublicKey};
5656

57-
use miniscript::{descriptor::Wildcard, Descriptor, DescriptorPublicKey};
58-
use miniscript::{MiniscriptKey, ToPublicKey, TranslatePk};
57+
use miniscript::descriptor::{DescriptorSinglePub, SinglePubKey, Wildcard};
58+
use miniscript::{Descriptor, DescriptorPublicKey, MiniscriptKey, ToPublicKey, TranslatePk};
5959

6060
use crate::wallet::utils::SecpCtx;
6161

@@ -128,21 +128,44 @@ impl<'s> MiniscriptKey for DerivedDescriptorKey<'s> {
128128
fn is_uncompressed(&self) -> bool {
129129
self.0.is_uncompressed()
130130
}
131-
fn serialized_len(&self) -> usize {
132-
self.0.serialized_len()
133-
}
134131
}
135132

136133
impl<'s> ToPublicKey for DerivedDescriptorKey<'s> {
137134
fn to_public_key(&self) -> PublicKey {
138135
match &self.0 {
139-
DescriptorPublicKey::SinglePub(ref spub) => spub.key.to_public_key(),
140-
DescriptorPublicKey::XPub(ref xpub) => {
136+
DescriptorPublicKey::SinglePub(DescriptorSinglePub {
137+
key: SinglePubKey::XOnly(_),
138+
..
139+
}) => panic!("Found x-only public key in non-tr descriptor"),
140+
DescriptorPublicKey::SinglePub(DescriptorSinglePub {
141+
key: SinglePubKey::FullKey(ref pk),
142+
..
143+
}) => *pk,
144+
DescriptorPublicKey::XPub(ref xpub) => PublicKey::new(
145+
xpub.xkey
146+
.derive_pub(self.1, &xpub.derivation_path)
147+
.expect("Shouldn't fail, only normal derivations")
148+
.public_key,
149+
),
150+
}
151+
}
152+
153+
fn to_x_only_pubkey(&self) -> XOnlyPublicKey {
154+
match &self.0 {
155+
DescriptorPublicKey::SinglePub(DescriptorSinglePub {
156+
key: SinglePubKey::XOnly(ref pk),
157+
..
158+
}) => *pk,
159+
DescriptorPublicKey::SinglePub(DescriptorSinglePub {
160+
key: SinglePubKey::FullKey(ref pk),
161+
..
162+
}) => XOnlyPublicKey::from(pk.inner),
163+
DescriptorPublicKey::XPub(ref xpub) => XOnlyPublicKey::from(
141164
xpub.xkey
142165
.derive_pub(self.1, &xpub.derivation_path)
143166
.expect("Shouldn't fail, only normal derivations")
144-
.public_key
145-
}
167+
.public_key,
168+
),
146169
}
147170
}
148171

src/descriptor/dsl.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,9 @@ mod test {
10541054
}
10551055

10561056
#[test]
1057-
#[should_panic(expected = "Miniscript(ContextError(CompressedOnly))")]
1057+
#[should_panic(
1058+
expected = "Miniscript(ContextError(CompressedOnly(\"04b4632d08485ff1df2db55b9dafd23347d1c47a457072a1e87be26896549a87378ec38ff91d43e8c2092ebda601780485263da089465619e0358a5c1be7ac91f4\")))"
1059+
)]
10581060
fn test_dsl_miniscript_checks() {
10591061
let mut uncompressed_pk =
10601062
PrivateKey::from_wif("L5EZftvrYaSudiozVRzTqLcHLNDoVn7H5HSfM9BAN6tMJX8oTWz6").unwrap();

src/descriptor/mod.rs

+22-13
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
use std::collections::{BTreeMap, HashMap, HashSet};
1818
use std::ops::Deref;
1919

20+
use bitcoin::secp256k1;
2021
use bitcoin::util::bip32::{ChildNumber, DerivationPath, ExtendedPubKey, Fingerprint, KeySource};
2122
use bitcoin::util::psbt;
22-
use bitcoin::{Network, PublicKey, Script, TxOut};
23+
use bitcoin::{Network, Script, TxOut};
2324

2425
use miniscript::descriptor::{DescriptorType, InnerXKey};
2526
pub use miniscript::{
@@ -58,7 +59,7 @@ pub type DerivedDescriptor<'s> = Descriptor<DerivedDescriptorKey<'s>>;
5859
///
5960
/// [`psbt::Input`]: bitcoin::util::psbt::Input
6061
/// [`psbt::Output`]: bitcoin::util::psbt::Output
61-
pub type HdKeyPaths = BTreeMap<PublicKey, KeySource>;
62+
pub type HdKeyPaths = BTreeMap<secp256k1::PublicKey, KeySource>;
6263

6364
/// Trait for types which can be converted into an [`ExtendedDescriptor`] and a [`KeyMap`] usable by a wallet in a specific [`Network`]
6465
pub trait IntoWalletDescriptor {
@@ -306,6 +307,7 @@ pub(crate) trait DerivedDescriptorMeta {
306307

307308
pub(crate) trait DescriptorMeta {
308309
fn is_witness(&self) -> bool;
310+
fn is_taproot(&self) -> bool;
309311
fn get_extended_keys(&self) -> Result<Vec<DescriptorXKey<ExtendedPubKey>>, DescriptorError>;
310312
fn derive_from_hd_keypaths<'s>(
311313
&self,
@@ -328,21 +330,21 @@ pub(crate) trait DescriptorScripts {
328330
impl<'s> DescriptorScripts for DerivedDescriptor<'s> {
329331
fn psbt_redeem_script(&self) -> Option<Script> {
330332
match self.desc_type() {
331-
DescriptorType::ShWpkh => Some(self.explicit_script()),
332-
DescriptorType::ShWsh => Some(self.explicit_script().to_v0_p2wsh()),
333-
DescriptorType::Sh => Some(self.explicit_script()),
334-
DescriptorType::Bare => Some(self.explicit_script()),
335-
DescriptorType::ShSortedMulti => Some(self.explicit_script()),
333+
DescriptorType::ShWpkh => Some(self.explicit_script().unwrap()),
334+
DescriptorType::ShWsh => Some(self.explicit_script().unwrap().to_v0_p2wsh()),
335+
DescriptorType::Sh => Some(self.explicit_script().unwrap()),
336+
DescriptorType::Bare => Some(self.explicit_script().unwrap()),
337+
DescriptorType::ShSortedMulti => Some(self.explicit_script().unwrap()),
336338
_ => None,
337339
}
338340
}
339341

340342
fn psbt_witness_script(&self) -> Option<Script> {
341343
match self.desc_type() {
342-
DescriptorType::Wsh => Some(self.explicit_script()),
343-
DescriptorType::ShWsh => Some(self.explicit_script()),
344+
DescriptorType::Wsh => Some(self.explicit_script().unwrap()),
345+
DescriptorType::ShWsh => Some(self.explicit_script().unwrap()),
344346
DescriptorType::WshSortedMulti | DescriptorType::ShWshSortedMulti => {
345-
Some(self.explicit_script())
347+
Some(self.explicit_script().unwrap())
346348
}
347349
_ => None,
348350
}
@@ -362,6 +364,10 @@ impl DescriptorMeta for ExtendedDescriptor {
362364
)
363365
}
364366

367+
fn is_taproot(&self) -> bool {
368+
self.desc_type() == DescriptorType::Tr
369+
}
370+
365371
fn get_extended_keys(&self) -> Result<Vec<DescriptorXKey<ExtendedPubKey>>, DescriptorError> {
366372
let mut answer = Vec::new();
367373

@@ -448,15 +454,18 @@ impl DescriptorMeta for ExtendedDescriptor {
448454
let descriptor = self.as_derived_fixed(secp);
449455
match descriptor.desc_type() {
450456
// TODO: add pk() here
451-
DescriptorType::Pkh | DescriptorType::Wpkh | DescriptorType::ShWpkh
457+
DescriptorType::Pkh
458+
| DescriptorType::Wpkh
459+
| DescriptorType::ShWpkh
460+
| DescriptorType::Tr
452461
if utxo.is_some()
453462
&& descriptor.script_pubkey() == utxo.as_ref().unwrap().script_pubkey =>
454463
{
455464
Some(descriptor)
456465
}
457466
DescriptorType::Bare | DescriptorType::Sh | DescriptorType::ShSortedMulti
458467
if psbt_input.redeem_script.is_some()
459-
&& &descriptor.explicit_script()
468+
&& &descriptor.explicit_script().unwrap()
460469
== psbt_input.redeem_script.as_ref().unwrap() =>
461470
{
462471
Some(descriptor)
@@ -466,7 +475,7 @@ impl DescriptorMeta for ExtendedDescriptor {
466475
| DescriptorType::ShWshSortedMulti
467476
| DescriptorType::WshSortedMulti
468477
if psbt_input.witness_script.is_some()
469-
&& &descriptor.explicit_script()
478+
&& &descriptor.explicit_script().unwrap()
470479
== psbt_input.witness_script.as_ref().unwrap() =>
471480
{
472481
Some(descriptor)

0 commit comments

Comments
 (0)