Compare commits
18 Commits
release/0.
...
v0.11.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa786fbb21 | ||
|
|
8c570ae7eb | ||
|
|
56a7bc9874 | ||
|
|
cf1815a1c0 | ||
|
|
721748e98f | ||
|
|
976e641ba6 | ||
|
|
7117557dea | ||
|
|
fa013aeb83 | ||
|
|
38d1d0b0e2 | ||
|
|
0e10952b80 | ||
|
|
19d74955e2 | ||
|
|
73a7faf144 | ||
|
|
ea56a87b4b | ||
|
|
67f5f45e07 | ||
|
|
e80be49d1e | ||
|
|
fe30716fa2 | ||
|
|
e52550cfec | ||
|
|
f57c0ca98e |
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [v0.11.0] - [v0.10.0]
|
||||||
|
|
||||||
|
- Added `flush` method to the `Database` trait to explicitly flush to disk latest changes on the db.
|
||||||
|
|
||||||
## [v0.10.0] - [v0.9.0]
|
## [v0.10.0] - [v0.9.0]
|
||||||
|
|
||||||
- Added `RpcBlockchain` in the `AnyBlockchain` struct to allow using Rpc backend where `AnyBlockchain` is used (eg `bdk-cli`)
|
- Added `RpcBlockchain` in the `AnyBlockchain` struct to allow using Rpc backend where `AnyBlockchain` is used (eg `bdk-cli`)
|
||||||
@@ -360,7 +364,7 @@ final transaction is created by calling `finish` on the builder.
|
|||||||
- Use `MemoryDatabase` in the compiler example
|
- Use `MemoryDatabase` in the compiler example
|
||||||
- Make the REPL return JSON
|
- Make the REPL return JSON
|
||||||
|
|
||||||
[unreleased]: https://github.com/bitcoindevkit/bdk/compare/v0.9.0...HEAD
|
[unreleased]: https://github.com/bitcoindevkit/bdk/compare/v0.11.0...HEAD
|
||||||
[0.1.0-beta.1]: https://github.com/bitcoindevkit/bdk/compare/96c87ea5...0.1.0-beta.1
|
[0.1.0-beta.1]: https://github.com/bitcoindevkit/bdk/compare/96c87ea5...0.1.0-beta.1
|
||||||
[v0.2.0]: https://github.com/bitcoindevkit/bdk/compare/0.1.0-beta.1...v0.2.0
|
[v0.2.0]: https://github.com/bitcoindevkit/bdk/compare/0.1.0-beta.1...v0.2.0
|
||||||
[v0.3.0]: https://github.com/bitcoindevkit/bdk/compare/v0.2.0...v0.3.0
|
[v0.3.0]: https://github.com/bitcoindevkit/bdk/compare/v0.2.0...v0.3.0
|
||||||
@@ -372,3 +376,4 @@ final transaction is created by calling `finish` on the builder.
|
|||||||
[v0.8.0]: https://github.com/bitcoindevkit/bdk/compare/v0.7.0...v0.8.0
|
[v0.8.0]: https://github.com/bitcoindevkit/bdk/compare/v0.7.0...v0.8.0
|
||||||
[v0.9.0]: https://github.com/bitcoindevkit/bdk/compare/v0.8.0...v0.9.0
|
[v0.9.0]: https://github.com/bitcoindevkit/bdk/compare/v0.8.0...v0.9.0
|
||||||
[v0.10.0]: https://github.com/bitcoindevkit/bdk/compare/v0.9.0...v0.10.0
|
[v0.10.0]: https://github.com/bitcoindevkit/bdk/compare/v0.9.0...v0.10.0
|
||||||
|
[v0.11.0]: https://github.com/bitcoindevkit/bdk/compare/v0.10.0...v0.11.0
|
||||||
@@ -57,6 +57,21 @@ comment suggesting that you're working on it. If someone is already assigned,
|
|||||||
don't hesitate to ask if the assigned party or previous commenters are still
|
don't hesitate to ask if the assigned party or previous commenters are still
|
||||||
working on it if it has been awhile.
|
working on it if it has been awhile.
|
||||||
|
|
||||||
|
Deprecation policy
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Where possible, breaking existing APIs should be avoided. Instead, add new APIs and
|
||||||
|
use [`#[deprecated]`](https://github.com/rust-lang/rfcs/blob/master/text/1270-deprecation.md)
|
||||||
|
to discourage use of the old one.
|
||||||
|
|
||||||
|
Deprecated APIs are typically maintained for one release cycle. In other words, an
|
||||||
|
API that has been deprecated with the 0.10 release can be expected to be removed in the
|
||||||
|
0.11 release. This allows for smoother upgrades without incurring too much technical
|
||||||
|
debt inside this library.
|
||||||
|
|
||||||
|
If you deprecated an API as part of a contribution, we encourage you to "own" that API
|
||||||
|
and send a follow-up to remove it as part of the next release cycle.
|
||||||
|
|
||||||
Peer review
|
Peer review
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "bdk"
|
name = "bdk"
|
||||||
version = "0.10.1-dev"
|
version = "0.11.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
authors = ["Alekos Filini <alekos.filini@gmail.com>", "Riccardo Casatta <riccardo@casatta.it>"]
|
authors = ["Alekos Filini <alekos.filini@gmail.com>", "Riccardo Casatta <riccardo@casatta.it>"]
|
||||||
homepage = "https://bitcoindevkit.org"
|
homepage = "https://bitcoindevkit.org"
|
||||||
|
|||||||
@@ -233,6 +233,10 @@ impl Database for AnyDatabase {
|
|||||||
fn increment_last_index(&mut self, keychain: KeychainKind) -> Result<u32, Error> {
|
fn increment_last_index(&mut self, keychain: KeychainKind) -> Result<u32, Error> {
|
||||||
impl_inner_method!(AnyDatabase, self, increment_last_index, keychain)
|
impl_inner_method!(AnyDatabase, self, increment_last_index, keychain)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn flush(&mut self) -> Result<(), Error> {
|
||||||
|
impl_inner_method!(AnyDatabase, self, flush)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BatchOperations for AnyBatch {
|
impl BatchOperations for AnyBatch {
|
||||||
|
|||||||
@@ -367,6 +367,10 @@ impl Database for Tree {
|
|||||||
Ok(val)
|
Ok(val)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn flush(&mut self) -> Result<(), Error> {
|
||||||
|
Ok(Tree::flush(self).map(|_| ())?)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BatchDatabase for Tree {
|
impl BatchDatabase for Tree {
|
||||||
|
|||||||
@@ -419,6 +419,10 @@ impl Database for MemoryDatabase {
|
|||||||
|
|
||||||
Ok(*value)
|
Ok(*value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn flush(&mut self) -> Result<(), Error> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BatchDatabase for MemoryDatabase {
|
impl BatchDatabase for MemoryDatabase {
|
||||||
|
|||||||
@@ -134,6 +134,9 @@ pub trait Database: BatchOperations {
|
|||||||
///
|
///
|
||||||
/// It should insert and return `0` if not present in the database
|
/// It should insert and return `0` if not present in the database
|
||||||
fn increment_last_index(&mut self, keychain: KeychainKind) -> Result<u32, Error>;
|
fn increment_last_index(&mut self, keychain: KeychainKind) -> Result<u32, Error>;
|
||||||
|
|
||||||
|
/// Force changes to be written to disk
|
||||||
|
fn flush(&mut self) -> Result<(), Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait for a database that supports batch operations
|
/// Trait for a database that supports batch operations
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
//! interact with the bitcoin P2P network.
|
//! interact with the bitcoin P2P network.
|
||||||
//!
|
//!
|
||||||
//! ```toml
|
//! ```toml
|
||||||
//! bdk = "0.10.0"
|
//! bdk = "0.11.0"
|
||||||
//! ```
|
//! ```
|
||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
feature = "electrum",
|
feature = "electrum",
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ impl PsbtUtils for Psbt {
|
|||||||
mod test {
|
mod test {
|
||||||
use crate::bitcoin::TxIn;
|
use crate::bitcoin::TxIn;
|
||||||
use crate::psbt::Psbt;
|
use crate::psbt::Psbt;
|
||||||
use crate::wallet::test::{get_funded_wallet, get_test_wpkh};
|
|
||||||
use crate::wallet::AddressIndex;
|
use crate::wallet::AddressIndex;
|
||||||
|
use crate::wallet::{get_funded_wallet, test::get_test_wpkh};
|
||||||
use crate::SignOptions;
|
use crate::SignOptions;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use electrsd::bitcoind::BitcoinD;
|
|||||||
use electrsd::{bitcoind, Conf, ElectrsD};
|
use electrsd::{bitcoind, Conf, ElectrsD};
|
||||||
pub use electrum_client::{Client as ElectrumClient, ElectrumApi};
|
pub use electrum_client::{Client as ElectrumClient, ElectrumApi};
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use log::{debug, error, info, trace};
|
use log::{debug, error, info, log_enabled, trace, Level};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
@@ -24,12 +24,17 @@ pub struct TestClient {
|
|||||||
impl TestClient {
|
impl TestClient {
|
||||||
pub fn new(bitcoind_exe: String, electrs_exe: String) -> Self {
|
pub fn new(bitcoind_exe: String, electrs_exe: String) -> Self {
|
||||||
debug!("launching {} and {}", &bitcoind_exe, &electrs_exe);
|
debug!("launching {} and {}", &bitcoind_exe, &electrs_exe);
|
||||||
let bitcoind = BitcoinD::new(bitcoind_exe).unwrap();
|
let conf = bitcoind::Conf {
|
||||||
|
view_stdout: log_enabled!(Level::Debug),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let bitcoind = BitcoinD::with_conf(bitcoind_exe, &conf).unwrap();
|
||||||
|
|
||||||
let http_enabled = cfg!(feature = "test-esplora");
|
let http_enabled = cfg!(feature = "test-esplora");
|
||||||
|
|
||||||
let conf = Conf {
|
let conf = Conf {
|
||||||
http_enabled,
|
http_enabled,
|
||||||
|
view_stderr: log_enabled!(Level::Debug),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let electrsd = ElectrsD::with_conf(electrs_exe, &bitcoind, &conf).unwrap();
|
let electrsd = ElectrsD::with_conf(electrs_exe, &bitcoind, &conf).unwrap();
|
||||||
|
|||||||
@@ -115,8 +115,8 @@ mod test {
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::wallet::test::{get_funded_wallet, get_test_wpkh};
|
|
||||||
use crate::wallet::AddressIndex::New;
|
use crate::wallet::AddressIndex::New;
|
||||||
|
use crate::wallet::{get_funded_wallet, test::get_test_wpkh};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct TestValidator;
|
struct TestValidator;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ use std::collections::HashMap;
|
|||||||
use std::collections::{BTreeMap, HashSet};
|
use std::collections::{BTreeMap, HashSet};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use bitcoin::secp256k1::Secp256k1;
|
use bitcoin::secp256k1::Secp256k1;
|
||||||
@@ -55,6 +56,7 @@ use tx_builder::{BumpFee, CreateTx, FeePolicy, TxBuilder, TxParams};
|
|||||||
use utils::{check_nlocktime, check_nsequence_rbf, After, Older, SecpCtx, DUST_LIMIT_SATOSHI};
|
use utils::{check_nlocktime, check_nsequence_rbf, After, Older, SecpCtx, DUST_LIMIT_SATOSHI};
|
||||||
|
|
||||||
use crate::blockchain::{Blockchain, Progress};
|
use crate::blockchain::{Blockchain, Progress};
|
||||||
|
use crate::database::memory::MemoryDatabase;
|
||||||
use crate::database::{BatchDatabase, BatchOperations, DatabaseUtils};
|
use crate::database::{BatchDatabase, BatchOperations, DatabaseUtils};
|
||||||
use crate::descriptor::derived::AsDerived;
|
use crate::descriptor::derived::AsDerived;
|
||||||
use crate::descriptor::policy::BuildSatisfaction;
|
use crate::descriptor::policy::BuildSatisfaction;
|
||||||
@@ -66,6 +68,7 @@ use crate::descriptor::{
|
|||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::psbt::PsbtUtils;
|
use crate::psbt::PsbtUtils;
|
||||||
use crate::signer::SignerError;
|
use crate::signer::SignerError;
|
||||||
|
use crate::testutils;
|
||||||
use crate::types::*;
|
use crate::types::*;
|
||||||
|
|
||||||
const CACHE_ADDR_BATCH_SIZE: u32 = 100;
|
const CACHE_ADDR_BATCH_SIZE: u32 = 100;
|
||||||
@@ -167,6 +170,11 @@ where
|
|||||||
secp,
|
secp,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the Bitcoin network the wallet is using.
|
||||||
|
pub fn network(&self) -> Network {
|
||||||
|
self.network
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The address index selection strategy to use to derived an address from the wallet's external
|
/// The address index selection strategy to use to derived an address from the wallet's external
|
||||||
@@ -1534,11 +1542,6 @@ where
|
|||||||
&self.client
|
&self.client
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the Bitcoin network the wallet is using.
|
|
||||||
pub fn network(&self) -> Network {
|
|
||||||
self.network
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Broadcast a transaction to the network
|
/// Broadcast a transaction to the network
|
||||||
#[maybe_async]
|
#[maybe_async]
|
||||||
pub fn broadcast(&self, tx: Transaction) -> Result<Txid, Error> {
|
pub fn broadcast(&self, tx: Transaction) -> Result<Txid, Error> {
|
||||||
@@ -1548,19 +1551,60 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return a fake wallet that appears to be funded for testing.
|
||||||
|
pub fn get_funded_wallet(
|
||||||
|
descriptor: &str,
|
||||||
|
) -> (
|
||||||
|
Wallet<(), MemoryDatabase>,
|
||||||
|
(String, Option<String>),
|
||||||
|
bitcoin::Txid,
|
||||||
|
) {
|
||||||
|
let descriptors = testutils!(@descriptors (descriptor));
|
||||||
|
let wallet = Wallet::new_offline(
|
||||||
|
&descriptors.0,
|
||||||
|
None,
|
||||||
|
Network::Regtest,
|
||||||
|
MemoryDatabase::new(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let funding_address_kix = 0;
|
||||||
|
|
||||||
|
let tx_meta = testutils! {
|
||||||
|
@tx ( (@external descriptors, funding_address_kix) => 50_000 ) (@confirmations 1)
|
||||||
|
};
|
||||||
|
|
||||||
|
wallet
|
||||||
|
.database
|
||||||
|
.borrow_mut()
|
||||||
|
.set_script_pubkey(
|
||||||
|
&bitcoin::Address::from_str(&tx_meta.output.get(0).unwrap().to_address)
|
||||||
|
.unwrap()
|
||||||
|
.script_pubkey(),
|
||||||
|
KeychainKind::External,
|
||||||
|
funding_address_kix,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
wallet
|
||||||
|
.database
|
||||||
|
.borrow_mut()
|
||||||
|
.set_last_index(KeychainKind::External, funding_address_kix)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let txid = crate::populate_test_db!(wallet.database.borrow_mut(), tx_meta, Some(100));
|
||||||
|
|
||||||
|
(wallet, descriptors, txid)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) mod test {
|
pub(crate) mod test {
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
use bitcoin::{util::psbt, Network};
|
use bitcoin::{util::psbt, Network};
|
||||||
|
|
||||||
use crate::database::memory::MemoryDatabase;
|
|
||||||
use crate::database::Database;
|
use crate::database::Database;
|
||||||
use crate::types::KeychainKind;
|
use crate::types::KeychainKind;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::signer::{SignOptions, SignerError};
|
use crate::signer::{SignOptions, SignerError};
|
||||||
use crate::testutils;
|
|
||||||
use crate::wallet::AddressIndex::{LastUnused, New, Peek, Reset};
|
use crate::wallet::AddressIndex::{LastUnused, New, Peek, Reset};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -1672,50 +1716,6 @@ pub(crate) mod test {
|
|||||||
"wsh(and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),after(100000)))"
|
"wsh(and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),after(100000)))"
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_funded_wallet(
|
|
||||||
descriptor: &str,
|
|
||||||
) -> (
|
|
||||||
Wallet<(), MemoryDatabase>,
|
|
||||||
(String, Option<String>),
|
|
||||||
bitcoin::Txid,
|
|
||||||
) {
|
|
||||||
let descriptors = testutils!(@descriptors (descriptor));
|
|
||||||
let wallet = Wallet::new_offline(
|
|
||||||
&descriptors.0,
|
|
||||||
None,
|
|
||||||
Network::Regtest,
|
|
||||||
MemoryDatabase::new(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let funding_address_kix = 0;
|
|
||||||
|
|
||||||
let tx_meta = testutils! {
|
|
||||||
@tx ( (@external descriptors, funding_address_kix) => 50_000 ) (@confirmations 1)
|
|
||||||
};
|
|
||||||
|
|
||||||
wallet
|
|
||||||
.database
|
|
||||||
.borrow_mut()
|
|
||||||
.set_script_pubkey(
|
|
||||||
&bitcoin::Address::from_str(&tx_meta.output.get(0).unwrap().to_address)
|
|
||||||
.unwrap()
|
|
||||||
.script_pubkey(),
|
|
||||||
KeychainKind::External,
|
|
||||||
funding_address_kix,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
wallet
|
|
||||||
.database
|
|
||||||
.borrow_mut()
|
|
||||||
.set_last_index(KeychainKind::External, funding_address_kix)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let txid = crate::populate_test_db!(wallet.database.borrow_mut(), tx_meta, Some(100));
|
|
||||||
|
|
||||||
(wallet, descriptors, txid)
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! assert_fee_rate {
|
macro_rules! assert_fee_rate {
|
||||||
($tx:expr, $fees:expr, $fee_rate:expr $( ,@dust_change $( $dust_change:expr )* )* $( ,@add_signature $( $add_signature:expr )* )* ) => ({
|
($tx:expr, $fees:expr, $fee_rate:expr $( ,@dust_change $( $dust_change:expr )* )* $( ,@add_signature $( $add_signature:expr )* )* ) => ({
|
||||||
let mut tx = $tx.clone();
|
let mut tx = $tx.clone();
|
||||||
|
|||||||
Reference in New Issue
Block a user