Skip to content

Commit

Permalink
Merge bitcoindevkit#1023: Update rust bitcoin
Browse files Browse the repository at this point in the history
1da3b30 ci: Pin rustls to keep the MSRV (Daniela Brozzoni)
792b39f Explicitly deny multipath keys (Daniela Brozzoni)
b73385d Update wallet_electrum to rust-bitcoin 0.30.0 (Daniela Brozzoni)
3dac3f9 Update example_electrum to rust-bitcoin 0.30.0 (Daniela Brozzoni)
2949bdc Update example_cli to rust-bitcoin 0.30.0 (Daniela Brozzoni)
468d2a0 Update tmp_plan to rust-bitcoin 0.30.0 (Daniela Brozzoni)
b8ac16d Update coin_select to rust-bitcoin 0.30.0 (Daniela Brozzoni)
6c29e53 Update wallet_esplora and wallet_esplora_async to... ...rust-bitcoin 0.30.0 (Daniela Brozzoni)
6eb0795 Update crates/esplora to rust-bitcoin 0.30.0 (Daniela Brozzoni)
91b0f0b Update crates/electrum to bitcoin 0.30.0 (Daniela Brozzoni)
f4e3ba3 Update bdk to bitcoin 0.30.0 (Daniela Brozzoni)
853d361 Update bdk_chain to bitcoin 0.30.0 (Daniela Brozzoni)

Pull request description:

  ### Description

  Updates to rust-bitcoin 0.30.0 and miniscript 0.10.0

  Not covered in this PR:
  - bitcoindevkit#1036. Although the latter is deprecated, I think it's better if I update it in a separate PR, as this one is pretty big already.
  - bitcoindevkit#1037
  - bitcoindevkit#1038

  Heads up, I'm explicitly denying multipath descriptors until we have better tests for them. See the commit message of 23fba7a

  ### Changelog notice

  - Update to `rust-bitcoin` 0.30.0 and `miniscript` 10.0.0

  ### 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

ACKs for top commit:
  evanlinjin:
    ACK 1da3b30

Tree-SHA512: ff1457ed711f9f8cdb446ea10aaf124632f539c02406da94317d8dc38013b321217d3bdcb2df4bd72b2ed92116b52e9c6b98ee91d4d508a579c67449a7caa549
  • Loading branch information
evanlinjin committed Aug 4, 2023
2 parents d73669e + 1da3b30 commit feafaac
Show file tree
Hide file tree
Showing 52 changed files with 800 additions and 552 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
uses: Swatinem/[email protected]
- name: Pin dependencies for MSRV
if: matrix.rust.version == '1.57.0'
run: cargo update -p log --precise "0.4.18" && cargo update -p tempfile --precise "3.6.0"
run: cargo update -p log --precise "0.4.18" && cargo update -p tempfile --precise "3.6.0" && cargo update -p rustls:0.21.6 --precise "0.21.1"
- name: Build
run: cargo build ${{ matrix.features }}
- name: Test
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ To build with the MSRV you will need to pin dependencies as follows:
```
# log 0.4.19 has MSRV 1.60.0+
cargo update -p log --precise "0.4.18"
# tempfile 3.7.0 has MSRV 1.63.0
# tempfile 3.7.0 has MSRV 1.63.0+
cargo update -p tempfile --precise "3.6.0"
# rustls 0.21.2 has MSRV 1.60.0+
cargo update -p rustls:0.21.6 --precise "0.21.1"
```
8 changes: 3 additions & 5 deletions crates/bdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ rust-version = "1.57"
[dependencies]
log = "0.4"
rand = "^0.8"
miniscript = { version = "9", features = ["serde"], default-features = false }
bitcoin = { version = "0.29", features = ["serde", "base64", "rand"], default-features = false }
miniscript = { version = "10.0.0", features = ["serde"], default-features = false }
bitcoin = { version = "0.30.0", features = ["serde", "base64", "rand-std"], default-features = false }
serde = { version = "^1.0", features = ["derive"] }
serde_json = { version = "^1.0" }
bdk_chain = { path = "../chain", version = "0.5.0", features = ["miniscript", "serde"], default-features = false }

# Optional dependencies
hwi = { version = "0.5", optional = true, features = [ "use-miniscript"] }
hwi = { version = "0.7.0", optional = true, features = [ "miniscript"] }
bip39 = { version = "1.0.1", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand All @@ -46,8 +46,6 @@ dev-getrandom-wasm = ["getrandom/js"]
[dev-dependencies]
lazy_static = "1.4"
env_logger = "0.7"
# Move back to importing from rust-bitcoin once https://github.com/rust-bitcoin/rust-bitcoin/pull/1342 is released
base64 = "^0.13"
assert_matches = "1.5.0"

[package.metadata.docs.rs]
Expand Down
4 changes: 2 additions & 2 deletions crates/bdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn main() {
<!-- use bdk::electrum_client::Client; -->
<!-- use bdk::wallet::AddressIndex::New; -->

<!-- use base64; -->
<!-- use bitcoin::base64; -->
<!-- use bdk::bitcoin::consensus::serialize; -->
<!-- use bdk::bitcoin::Network; -->

Expand Down Expand Up @@ -174,7 +174,7 @@ fn main() {
<!-- ```rust,no_run -->
<!-- use bdk::{Wallet, SignOptions}; -->

<!-- use base64; -->
<!-- use bitcoin::base64; -->
<!-- use bdk::bitcoin::consensus::deserialize; -->
<!-- use bdk::bitcoin::Network; -->

Expand Down
2 changes: 1 addition & 1 deletion crates/bdk/examples/mnemonic_to_descriptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use bdk::bitcoin::bip32::DerivationPath;
use bdk::bitcoin::secp256k1::Secp256k1;
use bdk::bitcoin::util::bip32::DerivationPath;
use bdk::bitcoin::Network;
use bdk::descriptor;
use bdk::descriptor::IntoWalletDescriptor;
Expand Down
25 changes: 10 additions & 15 deletions crates/bdk/src/descriptor/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,13 +516,14 @@ macro_rules! descriptor {
use $crate::miniscript::descriptor::{Descriptor, DescriptorPublicKey};

$crate::impl_top_level_pk!(Pkh, $crate::miniscript::Legacy, $key)
.and_then(|(a, b, c)| Ok((a.map_err(|e| miniscript::Error::from(e))?, b, c)))
.map(|(a, b, c)| (Descriptor::<DescriptorPublicKey>::Pkh(a), b, c))
});
( wpkh ( $key:expr ) ) => ({
use $crate::miniscript::descriptor::{Descriptor, DescriptorPublicKey};

$crate::impl_top_level_pk!(Wpkh, $crate::miniscript::Segwitv0, $key)
.and_then(|(a, b, c)| Ok((a?, b, c)))
.and_then(|(a, b, c)| Ok((a.map_err(|e| miniscript::Error::from(e))?, b, c)))
.map(|(a, b, c)| (Descriptor::<DescriptorPublicKey>::Wpkh(a), b, c))
});
( sh ( wpkh ( $key:expr ) ) ) => ({
Expand All @@ -532,7 +533,7 @@ macro_rules! descriptor {
use $crate::miniscript::descriptor::{Descriptor, DescriptorPublicKey, Sh};

$crate::impl_top_level_pk!(Wpkh, $crate::miniscript::Segwitv0, $key)
.and_then(|(a, b, c)| Ok((a?, b, c)))
.and_then(|(a, b, c)| Ok((a.map_err(|e| miniscript::Error::from(e))?, b, c)))
.and_then(|(a, b, c)| Ok((Descriptor::<DescriptorPublicKey>::Sh(Sh::new_wpkh(a.into_inner())?), b, c)))
});
( sh ( $( $minisc:tt )* ) ) => ({
Expand Down Expand Up @@ -702,7 +703,7 @@ macro_rules! fragment {
$crate::keys::make_pkh($key, &secp)
});
( after ( $value:expr ) ) => ({
$crate::impl_leaf_opcode_value!(After, $crate::bitcoin::PackedLockTime($value)) // TODO!! https://github.com/rust-bitcoin/rust-bitcoin/issues/1302
$crate::impl_leaf_opcode_value!(After, $crate::miniscript::AbsLockTime::from_consensus($value))
});
( older ( $value:expr ) ) => ({
$crate::impl_leaf_opcode_value!(Older, $crate::bitcoin::Sequence($value)) // TODO!!
Expand Down Expand Up @@ -796,7 +797,6 @@ macro_rules! fragment {
#[cfg(test)]
mod test {
use alloc::string::ToString;
use bitcoin::hashes::hex::ToHex;
use bitcoin::secp256k1::Secp256k1;
use miniscript::descriptor::{DescriptorPublicKey, KeyMap};
use miniscript::{Descriptor, Legacy, Segwitv0};
Expand All @@ -805,8 +805,8 @@ mod test {

use crate::descriptor::{DescriptorError, DescriptorMeta};
use crate::keys::{DescriptorKey, IntoDescriptorKey, ValidNetworks};
use bitcoin::bip32;
use bitcoin::network::constants::Network::{Bitcoin, Regtest, Signet, Testnet};
use bitcoin::util::bip32;
use bitcoin::PrivateKey;

// test the descriptor!() macro
Expand All @@ -822,18 +822,15 @@ mod test {
assert_eq!(desc.is_witness(), is_witness);
assert_eq!(!desc.has_wildcard(), is_fixed);
for i in 0..expected.len() {
let index = i as u32;
let child_desc = if !desc.has_wildcard() {
desc.at_derivation_index(0)
} else {
desc.at_derivation_index(index)
};
let child_desc = desc
.at_derivation_index(i as u32)
.expect("i is not hardened");
let address = child_desc.address(Regtest);
if let Ok(address) = address {
assert_eq!(address.to_string(), *expected.get(i).unwrap());
} else {
let script = child_desc.script_pubkey();
assert_eq!(script.to_hex().as_str(), *expected.get(i).unwrap());
assert_eq!(script.to_hex_string(), *expected.get(i).unwrap());
}
}
}
Expand Down Expand Up @@ -1178,9 +1175,7 @@ mod test {
}

#[test]
#[should_panic(
expected = "Miniscript(ContextError(CompressedOnly(\"04b4632d08485ff1df2db55b9dafd23347d1c47a457072a1e87be26896549a87378ec38ff91d43e8c2092ebda601780485263da089465619e0358a5c1be7ac91f4\")))"
)]
#[should_panic(expected = "Miniscript(ContextError(UncompressedKeysNotAllowed))")]
fn test_dsl_miniscript_checks() {
let mut uncompressed_pk =
PrivateKey::from_wif("L5EZftvrYaSudiozVRzTqLcHLNDoVn7H5HSfM9BAN6tMJX8oTWz6").unwrap();
Expand Down
18 changes: 12 additions & 6 deletions crates/bdk/src/descriptor/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub enum Error {
InvalidDescriptorChecksum,
/// The descriptor contains hardened derivation steps on public extended keys
HardenedDerivationXpub,
/// The descriptor contains multipath keys
MultiPath,

/// Error thrown while working with [`keys`](crate::keys)
Key(crate::keys::KeyError),
Expand All @@ -32,11 +34,11 @@ pub enum Error {
InvalidDescriptorCharacter(u8),

/// BIP32 error
Bip32(bitcoin::util::bip32::Error),
Bip32(bitcoin::bip32::Error),
/// Error during base58 decoding
Base58(bitcoin::util::base58::Error),
Base58(bitcoin::base58::Error),
/// Key-related error
Pk(bitcoin::util::key::Error),
Pk(bitcoin::key::Error),
/// Miniscript error
Miniscript(miniscript::Error),
/// Hex decoding error
Expand Down Expand Up @@ -64,6 +66,10 @@ impl fmt::Display for Error {
f,
"The descriptor contains hardened derivation steps on public extended keys"
),
Self::MultiPath => write!(
f,
"The descriptor contains multipath keys, which are not supported yet"
),
Self::Key(err) => write!(f, "Key error: {}", err),
Self::Policy(err) => write!(f, "Policy error: {}", err),
Self::InvalidDescriptorCharacter(char) => {
Expand All @@ -81,9 +87,9 @@ impl fmt::Display for Error {
#[cfg(feature = "std")]
impl std::error::Error for Error {}

impl_error!(bitcoin::util::bip32::Error, Bip32);
impl_error!(bitcoin::util::base58::Error, Base58);
impl_error!(bitcoin::util::key::Error, Pk);
impl_error!(bitcoin::bip32::Error, Bip32);
impl_error!(bitcoin::base58::Error, Base58);
impl_error!(bitcoin::key::Error, Pk);
impl_error!(miniscript::Error, Miniscript);
impl_error!(bitcoin::hashes::hex::Error, Hex);
impl_error!(crate::descriptor::policy::PolicyError, Policy);
Loading

0 comments on commit feafaac

Please sign in to comment.