Skip to content
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
9 changes: 0 additions & 9 deletions ci/pin-msrv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,4 @@ set -euo pipefail
# cargo clean
# rustup override set 1.63.0

cargo update -p home --precise "0.5.5"
cargo update -p url --precise "2.5.0"
cargo update -p tokio --precise "1.38.1"
cargo update -p tokio-util --precise "0.7.11"
cargo update -p indexmap --precise "2.5.0"
cargo update -p security-framework-sys --precise "2.11.1"
cargo update -p ring --precise "0.17.12"
cargo update -p once_cell --precise "1.20.3"
cargo update -p minreq --precise "2.13.2"
cargo update -p native-tls --precise "0.2.13"
2 changes: 1 addition & 1 deletion examples/example_wallet_electrum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ edition = "2021"

[dependencies]
bdk_wallet = { path = "../../wallet", features = ["file_store"] }
bdk_electrum = { version = "0.21" }
bdk_electrum = { version = "0.22.0" }
anyhow = "1"
2 changes: 1 addition & 1 deletion examples/example_wallet_electrum/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const ELECTRUM_URL: &str = "ssl://electrum.blockstream.info:60002";
fn main() -> Result<(), anyhow::Error> {
let db_path = "bdk-electrum-example.db";

let mut db = Store::<bdk_wallet::ChangeSet>::open_or_create_new(DB_MAGIC.as_bytes(), db_path)?;
let (mut db, _) = Store::<bdk_wallet::ChangeSet>::load_or_create(DB_MAGIC.as_bytes(), db_path)?;

let wallet_opt = Wallet::load()
.descriptor(KeychainKind::External, Some(EXTERNAL_DESC))
Expand Down
2 changes: 1 addition & 1 deletion examples/example_wallet_esplora_async/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ edition = "2021"

[dependencies]
bdk_wallet = { path = "../../wallet", features = ["rusqlite"] }
bdk_esplora = { version = "0.20", features = ["async-https", "tokio"] }
bdk_esplora = { version = "0.21.0", features = ["async-https", "tokio"] }
tokio = { version = "1.38.1", features = ["rt", "rt-multi-thread", "macros"] }
anyhow = "1"
2 changes: 1 addition & 1 deletion examples/example_wallet_esplora_blocking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ publish = false

[dependencies]
bdk_wallet = { path = "../../wallet", features = ["file_store"] }
bdk_esplora = { version = "0.20", features = ["blocking"] }
bdk_esplora = { version = "0.21.0", features = ["blocking"] }
anyhow = "1"
2 changes: 1 addition & 1 deletion examples/example_wallet_esplora_blocking/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const INTERNAL_DESC: &str = "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7
const ESPLORA_URL: &str = "http://signet.bitcoindevkit.net";

fn main() -> Result<(), anyhow::Error> {
let mut db = Store::<bdk_wallet::ChangeSet>::open_or_create_new(DB_MAGIC.as_bytes(), DB_PATH)?;
let (mut db, _) = Store::<bdk_wallet::ChangeSet>::load_or_create(DB_MAGIC.as_bytes(), DB_PATH)?;

let wallet_opt = Wallet::load()
.descriptor(KeychainKind::External, Some(EXTERNAL_DESC))
Expand Down
2 changes: 1 addition & 1 deletion examples/example_wallet_rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"

[dependencies]
bdk_wallet = { path = "../../wallet", features = ["file_store"] }
bdk_bitcoind_rpc = { version = "0.18" }
bdk_bitcoind_rpc = { version = "0.19.0" }

anyhow = "1"
clap = { version = "4.5.17", features = ["derive", "env"] }
Expand Down
34 changes: 23 additions & 11 deletions examples/example_wallet_rpc/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
use bdk_bitcoind_rpc::{
bitcoincore_rpc::{Auth, Client, RpcApi},
Emitter,
Emitter, MempoolEvent,
};
use bdk_wallet::{
bitcoin::{Block, Network, Transaction},
bitcoin::{Block, Network},
file_store::Store,
KeychainKind, Wallet,
};
use clap::{self, Parser};
use std::{path::PathBuf, sync::mpsc::sync_channel, thread::spawn, time::Instant};
use std::{
path::PathBuf,
sync::{mpsc::sync_channel, Arc},
thread::spawn,
time::Instant,
};

const DB_MAGIC: &str = "bdk-rpc-wallet-example";

Expand Down Expand Up @@ -73,21 +78,21 @@ impl Args {
enum Emission {
SigTerm,
Block(bdk_bitcoind_rpc::BlockEvent<Block>),
Mempool(Vec<(Transaction, u64)>),
Mempool(MempoolEvent),
}

fn main() -> anyhow::Result<()> {
let args = Args::parse();

let rpc_client = args.client()?;
let rpc_client = Arc::new(args.client()?);
println!(
"Connected to Bitcoin Core RPC at {:?}",
rpc_client.get_blockchain_info().unwrap()
);

let start_load_wallet = Instant::now();
let mut db =
Store::<bdk_wallet::ChangeSet>::open_or_create_new(DB_MAGIC.as_bytes(), args.db_path)?;
let (mut db, _) =
Store::<bdk_wallet::ChangeSet>::load_or_create(DB_MAGIC.as_bytes(), args.db_path)?;
let wallet_opt = Wallet::load()
.descriptor(KeychainKind::External, Some(args.descriptor.clone()))
.descriptor(KeychainKind::Internal, args.change_descriptor.clone())
Expand Down Expand Up @@ -129,9 +134,15 @@ fn main() -> anyhow::Result<()> {
.expect("failed to send sigterm")
});

let emitter_tip = wallet_tip.clone();
let mut emitter = Emitter::new(
rpc_client,
wallet_tip,
args.start_height,
wallet
.transactions()
.filter(|tx| tx.chain_position.is_unconfirmed()),
);
spawn(move || -> Result<(), anyhow::Error> {
let mut emitter = Emitter::new(&rpc_client, emitter_tip, args.start_height);
while let Some(emission) = emitter.next_block()? {
sender.send(Emission::Block(emission))?;
}
Expand Down Expand Up @@ -160,9 +171,10 @@ fn main() -> anyhow::Result<()> {
hash, height, elapsed
);
}
Emission::Mempool(mempool_emission) => {
Emission::Mempool(event) => {
let start_apply_mempool = Instant::now();
wallet.apply_unconfirmed_txs(mempool_emission);
wallet.apply_evicted_txs(event.evicted_ats());
wallet.apply_unconfirmed_txs(event.new_txs);
wallet.persist(&mut db)?;
println!(
"Applied unconfirmed transactions in {}s",
Expand Down
7 changes: 3 additions & 4 deletions wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ miniscript = { version = "12.3.1", features = [ "serde" ], default-features = fa
bitcoin = { version = "0.32.4", features = [ "serde", "base64" ], default-features = false }
serde = { version = "^1.0", features = ["derive"] }
serde_json = { version = "^1.0" }
bdk_chain = { version = "0.21.1", features = [ "miniscript", "serde" ], default-features = false }
bdk_file_store = { version = "0.18.1", optional = true }
bdk_chain = { version = "0.22.0", features = [ "miniscript", "serde" ], default-features = false }

# Optional dependencies
bip39 = { version = "2.0", optional = true }
bdk_file_store = { version = "0.20.0", optional = true }

[features]
default = ["std"]
Expand All @@ -40,9 +40,8 @@ test-utils = ["std"]
[dev-dependencies]
assert_matches = "1.5.0"
tempfile = "3"
bdk_chain = { version = "0.21.1", features = ["rusqlite"] }
bdk_chain = { version = "0.22.0", features = ["rusqlite"] }
bdk_wallet = { path = ".", features = ["rusqlite", "file_store", "test-utils"] }
bdk_file_store = { version = "0.18.1" }
anyhow = "1"
rand = "^0.8"

Expand Down
5 changes: 2 additions & 3 deletions wallet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,12 @@ To persist `Wallet` state data use a data store crate that reads and writes [`Ch

**Example**

<!-- compile_fail because outpoint and txout are fake variables -->
```rust,no_run
use bdk_wallet::{bitcoin::Network, KeychainKind, ChangeSet, Wallet};

// Open or create a new file store for wallet data.
let mut db =
bdk_file_store::Store::<ChangeSet>::open_or_create_new(b"magic_bytes", "/tmp/my_wallet.db")
let (mut db, _changeset) =
bdk_file_store::Store::<ChangeSet>::load_or_create(b"magic_bytes", "/tmp/my_wallet.db")
.expect("create store");

// Create a wallet with initial wallet data read from the file store.
Expand Down
38 changes: 20 additions & 18 deletions wallet/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloc::string::ToString;
use alloc::sync::Arc;
use core::str::FromStr;

use bdk_chain::{tx_graph, BlockId, ConfirmationBlockTime};
use bdk_chain::{BlockId, ConfirmationBlockTime, TxUpdate};
use bitcoin::{
absolute, hashes::Hash, transaction, Address, Amount, BlockHash, FeeRate, Network, OutPoint,
Transaction, TxIn, TxOut, Txid,
Expand Down Expand Up @@ -312,43 +312,45 @@ pub fn insert_checkpoint(wallet: &mut Wallet, block: BlockId) {
.unwrap();
}

/// Insert transaction
/// Inserts a transaction into the local view, assuming it is currently present in the mempool.
///
/// This can be used, for example, to track a transaction immediately after it is broadcast.
pub fn insert_tx(wallet: &mut Wallet, tx: Transaction) {
let txid = tx.compute_txid();
let seen_at = std::time::UNIX_EPOCH.elapsed().unwrap().as_secs();
let mut tx_update = TxUpdate::default();
tx_update.txs = vec![Arc::new(tx)];
tx_update.seen_ats = [(txid, seen_at)].into();
wallet
.apply_update(Update {
tx_update: bdk_chain::TxUpdate {
txs: vec![Arc::new(tx)],
..Default::default()
},
tx_update,
..Default::default()
})
.unwrap();
.expect("failed to apply update");
}

/// Simulates confirming a tx with `txid` by applying an update to the wallet containing
/// the given `anchor`. Note: to be considered confirmed the anchor block must exist in
/// the current active chain.
pub fn insert_anchor(wallet: &mut Wallet, txid: Txid, anchor: ConfirmationBlockTime) {
let mut tx_update = TxUpdate::default();
tx_update.anchors = [(anchor, txid)].into();
wallet
.apply_update(Update {
tx_update: tx_graph::TxUpdate {
anchors: [(anchor, txid)].into(),
..Default::default()
},
tx_update,
..Default::default()
})
.unwrap();
.expect("failed to apply update");
}

/// Marks the given `txid` seen as unconfirmed at `seen_at`
pub fn insert_seen_at(wallet: &mut Wallet, txid: Txid, seen_at: u64) {
let mut tx_update = TxUpdate::default();
tx_update.seen_ats = [(txid, seen_at)].into();
wallet
.apply_update(crate::Update {
tx_update: tx_graph::TxUpdate {
seen_ats: [(txid, seen_at)].into_iter().collect(),
..Default::default()
},
.apply_update(Update {
tx_update,
..Default::default()
})
.unwrap();
.expect("failed to apply update");
}
Loading
Loading