Skip to content

Commit

Permalink
build!: Update bdk to rust-bitcoin 0.30.0
Browse files Browse the repository at this point in the history
  • Loading branch information
danielabrozzoni committed Aug 9, 2023
1 parent 7231039 commit 39ef147
Show file tree
Hide file tree
Showing 40 changed files with 718 additions and 486 deletions.
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.5", 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
10 changes: 5 additions & 5 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
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
4 changes: 3 additions & 1 deletion examples/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ 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()
.assume_checked();

// Set recipient of the transaction
tx_builder.set_recipients(vec![(to_address.script_pubkey(), amount)]);
Expand Down
4 changes: 2 additions & 2 deletions src/blockchain/compact_filters/mod.rs
Original file line number Diff line number Diff line change
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/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ use rand::{thread_rng, Rng};

use rocksdb::{Direction, IteratorMode, ReadOptions, WriteBatch, DB};

use bitcoin::bip158::BlockFilter;
use bitcoin::blockdata::constants::genesis_block;
use bitcoin::consensus::{deserialize, encode::VarInt, serialize, Decodable, Encodable};
use bitcoin::hash_types::{FilterHash, FilterHeader};
use bitcoin::hashes::Hash;
use bitcoin::util::bip158::BlockFilter;
use bitcoin::util::uint::Uint256;
use bitcoin::uint::Uint256;
use bitcoin::Block;
use bitcoin::BlockHash;
use bitcoin::BlockHeader;
Expand Down
2 changes: 1 addition & 1 deletion src/blockchain/compact_filters/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use std::collections::{BTreeMap, HashMap, VecDeque};
use std::sync::{Arc, Mutex};
use std::time::Duration;

use bitcoin::bip158::BlockFilter;
use bitcoin::hash_types::{BlockHash, FilterHeader};
use bitcoin::hashes::Hash;
use bitcoin::network::message::NetworkMessage;
use bitcoin::network::message_blockdata::GetHeadersMessage;
use bitcoin::util::bip158::BlockFilter;

use super::peer::*;
use super::store::*;
Expand Down
4 changes: 2 additions & 2 deletions src/blockchain/electrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ impl ConfigurableBlockchain for ElectrumBlockchain {
let socks5 = config.socks5.as_ref().map(Socks5Config::new);
let electrum_config = ConfigBuilder::new()
.retry(config.retry)
.timeout(config.timeout)?
.socks5(socks5)?
.timeout(config.timeout)
.socks5(socks5)
.validate_domain(config.validate_domain)
.build();

Expand Down
2 changes: 1 addition & 1 deletion src/blockchain/esplora/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl WalletSync for EsploraBlockchain {
let scripts = script_req
.request()
.take(self.concurrency as usize)
.cloned();
.map(|s| bitcoin::ScriptBuf::from(s));

let mut handles = vec![];
for script in scripts {
Expand Down
21 changes: 10 additions & 11 deletions src/blockchain/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,17 @@
//! let blockchain = RpcBlockchain::from_config(&config);
//! ```
use crate::bitcoin::hashes::hex::ToHex;
use crate::bitcoin::{Network, OutPoint, Transaction, TxOut, Txid};
use crate::blockchain::*;
use crate::database::{BatchDatabase, BatchOperations, DatabaseUtils};
use crate::descriptor::calc_checksum;
use crate::error::MissingCachedScripts;
use crate::{BlockTime, Error, FeeRate, KeychainKind, LocalUtxo, TransactionDetails};
use bitcoin::Script;
use bitcoin::{Script, ScriptBuf};
use bitcoincore_rpc::json::{
GetTransactionResultDetailCategory, ImportMultiOptions, ImportMultiRequest,
ImportMultiRequestScriptPubkey, ImportMultiRescanSince, ListTransactionResult,
ListUnspentResultEntry, ScanningDetails,
ImportMultiRequestScriptPubkey, ListTransactionResult, ListUnspentResultEntry, ScanningDetails,
Timestamp,
};
use bitcoincore_rpc::jsonrpc::serde_json::{json, Value};
use bitcoincore_rpc::Auth as RpcAuth;
Expand Down Expand Up @@ -302,8 +301,8 @@ struct DbState<'a, D> {
params: &'a RpcSyncParams,
prog: &'a dyn Progress,

ext_spks: Vec<Script>,
int_spks: Vec<Script>,
ext_spks: Vec<ScriptBuf>,
int_spks: Vec<ScriptBuf>,
txs: HashMap<Txid, TransactionDetails>,
utxos: HashSet<LocalUtxo>,
last_indexes: HashMap<KeychainKind, u32>,
Expand Down Expand Up @@ -668,7 +667,7 @@ fn import_descriptors<'a, S>(
scripts_iter: S,
) -> Result<(), Error>
where
S: Iterator<Item = &'a Script>,
S: Iterator<Item = &'a ScriptBuf>,
{
let requests = Value::Array(
scripts_iter
Expand Down Expand Up @@ -696,11 +695,11 @@ where

fn import_multi<'a, S>(client: &Client, start_epoch: u64, scripts_iter: S) -> Result<(), Error>
where
S: Iterator<Item = &'a Script>,
S: Iterator<Item = &'a ScriptBuf>,
{
let requests = scripts_iter
.map(|script| ImportMultiRequest {
timestamp: ImportMultiRescanSince::Timestamp(start_epoch),
timestamp: Timestamp::Time(start_epoch),
script_pubkey: Some(ImportMultiRequestScriptPubkey::Script(script)),
watchonly: Some(true),
..Default::default()
Expand Down Expand Up @@ -808,7 +807,7 @@ fn is_wallet_descriptor(client: &Client) -> Result<bool, Error> {
}

fn descriptor_from_script_pubkey(script: &Script) -> String {
let desc = format!("raw({})", script.to_hex());
let desc = format!("raw({})", script.to_hex_string());
format!("{}#{}", desc, calc_checksum(&desc).unwrap())
}

Expand Down Expand Up @@ -964,7 +963,7 @@ mod test {

// generate scripts (1 tx per script)
let scripts = (0..TX_COUNT)
.map(|index| desc.at_derivation_index(index).script_pubkey())
.map(|index| desc.at_derivation_index(index).unwrap().script_pubkey())
.collect::<Vec<_>>();

// import scripts and wait
Expand Down
6 changes: 3 additions & 3 deletions src/blockchain/script_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
wallet::time::Instant,
BlockTime, Error, KeychainKind, LocalUtxo, TransactionDetails,
};
use bitcoin::{OutPoint, Script, Transaction, TxOut, Txid};
use bitcoin::{OutPoint, Script, ScriptBuf, Transaction, TxOut, Txid};
use log::*;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};

Expand Down Expand Up @@ -53,7 +53,7 @@ pub struct ScriptReq<'a, D: BatchDatabase> {
state: State<'a, D>,
script_index: usize,
initial_scripts_needed: usize, // if this is 1, we assume the descriptor is not derivable
scripts_needed: VecDeque<Script>,
scripts_needed: VecDeque<ScriptBuf>,
stop_gap: usize,
keychain: KeychainKind,
next_keychains: Vec<KeychainKind>,
Expand All @@ -62,7 +62,7 @@ pub struct ScriptReq<'a, D: BatchDatabase> {
/// The sync starts by returning script pubkeys we are interested in.
impl<'a, D: BatchDatabase> ScriptReq<'a, D> {
pub fn request(&self) -> impl Iterator<Item = &Script> + Clone {
self.scripts_needed.iter()
self.scripts_needed.iter().map(|s| s.as_script())
}

pub fn satisfy(
Expand Down
8 changes: 4 additions & 4 deletions src/database/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl BatchOperations for AnyDatabase {
&mut self,
keychain: KeychainKind,
child: u32,
) -> Result<Option<Script>, Error> {
) -> Result<Option<ScriptBuf>, Error> {
impl_inner_method!(
AnyDatabase,
self,
Expand Down Expand Up @@ -204,7 +204,7 @@ impl Database for AnyDatabase {
)
}

fn iter_script_pubkeys(&self, keychain: Option<KeychainKind>) -> Result<Vec<Script>, Error> {
fn iter_script_pubkeys(&self, keychain: Option<KeychainKind>) -> Result<Vec<ScriptBuf>, Error> {
impl_inner_method!(AnyDatabase, self, iter_script_pubkeys, keychain)
}
fn iter_utxos(&self) -> Result<Vec<LocalUtxo>, Error> {
Expand All @@ -221,7 +221,7 @@ impl Database for AnyDatabase {
&self,
keychain: KeychainKind,
child: u32,
) -> Result<Option<Script>, Error> {
) -> Result<Option<ScriptBuf>, Error> {
impl_inner_method!(
AnyDatabase,
self,
Expand Down Expand Up @@ -286,7 +286,7 @@ impl BatchOperations for AnyBatch {
&mut self,
keychain: KeychainKind,
child: u32,
) -> Result<Option<Script>, Error> {
) -> Result<Option<ScriptBuf>, Error> {
impl_inner_method!(AnyBatch, self, del_script_pubkey_from_path, keychain, child)
}
fn del_path_from_script_pubkey(
Expand Down
Loading

0 comments on commit 39ef147

Please sign in to comment.