Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rust bitcoin (BDK 0.28) #1071

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ jobs:
cargo update -p tempfile --precise "3.6.0"
cargo update -p hashlink --precise "0.8.1"
cargo update -p regex --precise "1.7.3"
cargo update -p zip --precise "0.6.3"
cargo update -p base64ct --precise "1.5.3"
cargo update -p zip:0.6.6 --precise "0.6.3"
cargo update -p rustix --precise "0.37.23"
cargo update -p tokio --precise "1.29.1"
cargo update -p cc --precise "1.0.81"
cargo update -p rustls:0.21.6 --precise "0.21.1"
cargo update -p flate2:1.0.27 --precise "1.0.26"
- name: Build
run: cargo build --features ${{ matrix.features }} --no-default-features
- name: Clippy
Expand Down Expand Up @@ -226,10 +227,11 @@ jobs:
cargo update -p tempfile --precise "3.6.0"
cargo update -p hashlink --precise "0.8.1"
cargo update -p regex --precise "1.7.3"
cargo update -p zip --precise "0.6.3"
cargo update -p base64ct --precise "1.5.3"
cargo update -p zip:0.6.6 --precise "0.6.3"
cargo update -p rustix --precise "0.37.23"
cargo update -p tokio --precise "1.29.1"
cargo update -p cc --precise "1.0.81"
cargo update -p rustls:0.21.6 --precise "0.21.1"
cargo update -p flate2:1.0.27 --precise "1.0.26"
- name: Test
run: cargo test --features test-hardware-signer
20 changes: 9 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ license = "MIT OR Apache-2.0"
[dependencies]
bdk-macros = "^0.6"
log = "0.4"
miniscript = { version = "9.0", default-features = false, features = ["serde"] }
bitcoin = { version = "0.29.2", default-features = false, features = ["serde", "base64", "rand"] }
miniscript = { version = "10.0", default-features = false, features = ["serde"] }
bitcoin = { version = "0.30", default-features = false, features = ["serde", "base64", "rand-std"] }
serde = { version = "^1.0", features = ["derive"] }
serde_json = { version = "^1.0" }
rand = "^0.8"

# Optional dependencies
sled = { version = "0.34", optional = true }
electrum-client = { version = "0.12", optional = true }
esplora-client = { version = "0.4", default-features = false, optional = true }
electrum-client = { version = "0.18", optional = true }
esplora-client = { version = "0.6", default-features = false, optional = true }
rusqlite = { version = "0.28.0", optional = true }
ahash = { version = "0.7.6", optional = true }
futures = { version = "0.3", optional = true }
async-trait = { version = "0.1", optional = true }
rocksdb = { version = "0.14", default-features = false, features = ["snappy"], optional = true }
cc = { version = ">=1.0.64", optional = true }
socks = { version = "0.3", optional = true }
hwi = { version = "0.5", optional = true, features = ["use-miniscript"] }
hwi = { version = "0.7", optional = true, features = ["miniscript"] }

bip39 = { version = "2.0.0", optional = true }
bitcoinconsensus = { version = "0.19.0-3", optional = true }

# Needed by bdk_blockchain_tests macro and the `rpc` feature
bitcoincore-rpc = { version = "0.16", optional = true }
bitcoincore-rpc = { package="core-rpc", version = "0.17", optional = true }

# Platform-specific dependencies
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand Down Expand Up @@ -107,13 +107,11 @@ test-hardware-signer = ["hardware-signer"]
dev-getrandom-wasm = ["getrandom/js"]

[dev-dependencies]
miniscript = { version = "9.0", features = ["std"] }
bitcoin = { version = "0.29.2", features = ["std"] }
miniscript = { version = "10.0", features = ["std"] }
bitcoin = { version = "0.30", features = ["std"] }
lazy_static = "1.4"
env_logger = { version = "0.7", default-features = false }
electrsd = "0.22"
# Remove after upgrade to rust-bitcoin ^0.30 where base64 is re-exported
base64 = "^0.13"
electrsd = "0.24"
assert_matches = "1.5.0"

[[example]]
Expand Down
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ use bdk::blockchain::ElectrumBlockchain;
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 All @@ -123,7 +123,7 @@ fn main() -> Result<(), bdk::Error> {
};

println!("Transaction details: {:#?}", details);
println!("Unsigned PSBT: {}", base64::encode(&serialize(&psbt)));
println!("Unsigned PSBT: {}", base64::encode(psbt.serialize()));

Ok(())
}
Expand All @@ -134,9 +134,9 @@ fn main() -> Result<(), bdk::Error> {
```rust,no_run
use bdk::{Wallet, SignOptions, database::MemoryDatabase};

use base64;
use bitcoin::base64;
use bdk::bitcoin::consensus::deserialize;
use bdk::bitcoin::Network;
use bdk::bitcoin::{psbt::Psbt, Network};

fn main() -> Result<(), bdk::Error> {
let wallet = Wallet::new(
Expand All @@ -147,7 +147,7 @@ fn main() -> Result<(), bdk::Error> {
)?;

let psbt = "...";
let mut psbt = deserialize(&base64::decode(psbt).unwrap())?;
let mut psbt = Psbt::deserialize(&base64::decode(psbt).unwrap())?;

let _finalized = wallet.sign(&mut psbt, SignOptions::default())?;

Expand Down Expand Up @@ -218,13 +218,15 @@ cargo update -p hashlink --precise "0.8.1"
# required for compact_filters feature, regex after 1.7.3 has MSRV 1.60.0
cargo update -p regex --precise "1.7.3"
# zip 0.6.3 has MSRV 1.59.0 but still works
cargo update -p zip --precise "0.6.3"
# base64ct 1.6.0 has MSRV 1.60.0
cargo update -p base64ct --precise "1.5.3"
cargo update -p zip:0.6.6 --precise "0.6.3"
# rustix 0.38.0 has MSRV 1.65.0
cargo update -p rustix --precise "0.37.23"
# tokio 0.30.0 has MSRV 1.63.0
cargo update -p tokio --precise "1.29.1"
# cc 1.0.82 is throwing error with rust 1.57.0, "error[E0599]: no method named `retain_mut`..."
cargo update -p cc --precise "1.0.81"
# rustls 0.21.2 has MSRV 1.60.0+
cargo update -p rustls:0.21.6 --precise "0.21.1"
# flate2 1.0.27 has MSRV 1.63.0+
cargo update -p flate2:1.0.27 --precise "1.0.26"
```
4 changes: 2 additions & 2 deletions examples/electrum_backend.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::str::FromStr;

use bdk::bitcoin::util::bip32::ExtendedPrivKey;
use bdk::bitcoin::bip32::ExtendedPrivKey;
use bdk::bitcoin::Network;
use bdk::blockchain::{Blockchain, ElectrumBlockchain};
use bdk::database::MemoryDatabase;
Expand All @@ -10,7 +10,7 @@ use bdk::{KeychainKind, SyncOptions, Wallet};

use bdk::electrum_client::Client;
use bdk::wallet::AddressIndex;
use bitcoin::util::bip32;
use bitcoin::bip32;

pub mod utils;

Expand Down
2 changes: 1 addition & 1 deletion examples/esplora_backend_asynchronous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use bdk::{
KeychainKind, SyncOptions, Wallet,
};
use bitcoin::{
util::bip32::{self, ExtendedPrivKey},
bip32::{self, ExtendedPrivKey},
Network,
};

Expand Down
2 changes: 1 addition & 1 deletion examples/esplora_backend_synchronous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use bdk::{
KeychainKind, SyncOptions, Wallet,
};
use bitcoin::{
util::bip32::{self, ExtendedPrivKey},
bip32::{self, ExtendedPrivKey},
Network,
};

Expand Down
9 changes: 5 additions & 4 deletions examples/hardware_signer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bdk::bitcoin::{Address, Network};
use bdk::blockchain::{Blockchain, ElectrumBlockchain};
use bdk::database::MemoryDatabase;
use bdk::hwi::{types::HWIChain, HWIClient};
use bdk::hwi::HWIClient;
use bdk::miniscript::{Descriptor, DescriptorPublicKey};
use bdk::signer::SignerOrdering;
use bdk::wallet::{hardwaresigner::HWISigner, AddressIndex};
Expand Down Expand Up @@ -30,7 +30,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
let first_device = devices.remove(0)?;
// ...and creating a client out of the first one
let client = HWIClient::get_client(&first_device, true, HWIChain::Test)?;
let client = HWIClient::get_client(&first_device, true, Network::Testnet.into())?;
println!("Look what I found, a {}!", first_device.model);

// Getting the HW's public descriptors
Expand All @@ -41,7 +41,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
);

// Creating a custom signer from the device
let custom_signer = HWISigner::from_device(&first_device, HWIChain::Test)?;
let custom_signer = HWISigner::from_device(&first_device, Network::Testnet.into())?;
let mut wallet = Wallet::new(
descriptors.receive[0].clone(),
Some(descriptors.internal[0].clone()),
Expand Down Expand Up @@ -77,7 +77,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
return Ok(());
}

let return_address = Address::from_str("tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt")?;
let return_address = Address::from_str("tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt")?
.require_network(Network::Testnet)?;
let (mut psbt, _details) = {
let mut builder = wallet.build_tx();
builder
Expand Down
2 changes: 1 addition & 1 deletion 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
3 changes: 2 additions & 1 deletion examples/psbt_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ fn main() -> Result<(), Box<dyn Error>> {
}
} else {
println!("Creating a PSBT sending 9800 SATs plus fee to the u01.net testnet faucet return address 'tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt'.");
let return_address = Address::from_str("tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt")?;
let return_address = Address::from_str("tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt")?
.require_network(Network::Testnet)?;
let mut builder = watch_only_wallet.build_tx();
builder
.add_recipient(return_address.script_pubkey(), 9_800)
Expand Down
5 changes: 4 additions & 1 deletion examples/rpcwallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ fn main() -> Result<(), Box<dyn Error>> {
};

// Get a new core address
let core_address = bitcoind.client.get_new_address(None, None)?;
let core_address = bitcoind
.client
.get_new_address(None, None)?
.require_network(Network::Regtest)?;

// Generate 101 blocks and use the above address as coinbase
bitcoind.client.generate_to_address(101, &core_address)?;
Expand Down
5 changes: 4 additions & 1 deletion examples/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ pub(crate) mod tx {
// Create a transaction builder
let mut tx_builder = wallet.build_tx();

let to_address = Address::from_str(recipient_address).unwrap();
let to_address = Address::from_str(recipient_address)
.unwrap()
.require_network(wallet.network())
.unwrap();

// Set recipient of the transaction
tx_builder.set_recipients(vec![(to_address.script_pubkey(), amount)]);
Expand Down
6 changes: 3 additions & 3 deletions src/blockchain/compact_filters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ impl WalletSync for CompactFiltersBlockchain {
peer,
|block_hash, filter| {
if !filter
.match_any(block_hash, &mut all_scripts.iter().map(AsRef::as_ref))?
.match_any(block_hash, all_scripts.iter().map(|s| s.as_slice()))?
{
return Ok(false);
}
Expand Down Expand Up @@ -570,7 +570,7 @@ pub enum CompactFiltersError {
/// Internal I/O error
Io(std::io::Error),
/// Invalid BIP158 filter
Bip158(bitcoin::util::bip158::Error),
Bip158(bitcoin::bip158::Error),
/// Internal system time error
Time(std::time::SystemTimeError),

Expand Down Expand Up @@ -608,7 +608,7 @@ impl std::error::Error for CompactFiltersError {}

impl_error!(rocksdb::Error, Db, CompactFiltersError);
impl_error!(std::io::Error, Io, CompactFiltersError);
impl_error!(bitcoin::util::bip158::Error, Bip158, CompactFiltersError);
impl_error!(bitcoin::bip158::Error, Bip158, CompactFiltersError);
impl_error!(std::time::SystemTimeError, Time, CompactFiltersError);

impl From<crate::error::Error> for CompactFiltersError {
Expand Down
4 changes: 2 additions & 2 deletions src/blockchain/compact_filters/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use bitcoin::network::message::{NetworkMessage, RawNetworkMessage};
use bitcoin::network::message_blockdata::*;
use bitcoin::network::message_filter::*;
use bitcoin::network::message_network::VersionMessage;
use bitcoin::network::Address;
use bitcoin::network::{Address, Magic};
use bitcoin::{Block, Network, Transaction, Txid, Wtxid};

use super::CompactFiltersError;
Expand Down Expand Up @@ -242,7 +242,7 @@ impl Peer {
/// Send a Bitcoin network message
fn _send(
writer: &mut TcpStream,
magic: u32,
magic: Magic,
payload: NetworkMessage,
) -> Result<(), CompactFiltersError> {
log::trace!("==> {:?}", payload);
Expand Down
Loading