Skip to content

Commit a60d70d

Browse files
committed
deps: update bdk_chain to 4fe121e7
1 parent 3e61d2a commit a60d70d

File tree

13 files changed

+102
-75
lines changed

13 files changed

+102
-75
lines changed

examples/example_wallet_electrum/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ edition = "2021"
55

66
[dependencies]
77
bdk_wallet = { path = "../../wallet", features = ["file_store"] }
8-
bdk_electrum = { version = "0.21" }
8+
# bdk_electrum = { version = "0.21" }
9+
bdk_electrum = { git = "https://github.com/bitcoindevkit/bdk", rev = "4fe121e7167cf93a8abf26c87d35b26a682f6cbc" }
910
anyhow = "1"

examples/example_wallet_electrum/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const ELECTRUM_URL: &str = "ssl://electrum.blockstream.info:60002";
2222
fn main() -> Result<(), anyhow::Error> {
2323
let db_path = "bdk-electrum-example.db";
2424

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

2727
let wallet_opt = Wallet::load()
2828
.descriptor(KeychainKind::External, Some(EXTERNAL_DESC))

examples/example_wallet_esplora_async/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = "2021"
77

88
[dependencies]
99
bdk_wallet = { path = "../../wallet", features = ["rusqlite"] }
10-
bdk_esplora = { version = "0.20", features = ["async-https", "tokio"] }
10+
# bdk_esplora = { version = "0.20", features = ["async-https", "tokio"] }
11+
bdk_esplora = { git = "https://github.com/bitcoindevkit/bdk", rev = "4fe121e7167cf93a8abf26c87d35b26a682f6cbc", features = ["async-https", "tokio"] }
1112
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] }
1213
anyhow = "1"

examples/example_wallet_esplora_blocking/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ publish = false
88

99
[dependencies]
1010
bdk_wallet = { path = "../../wallet", features = ["file_store"] }
11-
bdk_esplora = { version = "0.20", features = ["blocking"] }
11+
# bdk_esplora = { version = "0.20", features = ["blocking"] }
12+
bdk_esplora = { git = "https://github.com/bitcoindevkit/bdk", rev = "4fe121e7167cf93a8abf26c87d35b26a682f6cbc", features = ["blocking"] }
1213
anyhow = "1"

examples/example_wallet_esplora_blocking/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const INTERNAL_DESC: &str = "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7
1919
const ESPLORA_URL: &str = "http://signet.bitcoindevkit.net";
2020

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

2424
let wallet_opt = Wallet::load()
2525
.descriptor(KeychainKind::External, Some(EXTERNAL_DESC))

examples/example_wallet_rpc/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ edition = "2021"
77

88
[dependencies]
99
bdk_wallet = { path = "../../wallet", features = ["file_store"] }
10-
bdk_bitcoind_rpc = { version = "0.18" }
10+
# bdk_bitcoind_rpc = { version = "0.18" }
11+
bdk_bitcoind_rpc = { git = "https://github.com/bitcoindevkit/bdk", rev = "4fe121e7167cf93a8abf26c87d35b26a682f6cbc" }
1112

1213
anyhow = "1"
1314
clap = { version = "4.5.17", features = ["derive", "env"] }

examples/example_wallet_rpc/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ fn main() -> anyhow::Result<()> {
8686
);
8787

8888
let start_load_wallet = Instant::now();
89-
let mut db =
90-
Store::<bdk_wallet::ChangeSet>::open_or_create_new(DB_MAGIC.as_bytes(), args.db_path)?;
89+
let (mut db, _) =
90+
Store::<bdk_wallet::ChangeSet>::load_or_create(DB_MAGIC.as_bytes(), args.db_path)?;
9191
let wallet_opt = Wallet::load()
9292
.descriptor(KeychainKind::External, Some(args.descriptor.clone()))
9393
.descriptor(KeychainKind::Internal, args.change_descriptor.clone())

wallet/Cargo.toml

+19-4
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,22 @@ miniscript = { version = "12.3.1", features = [ "serde" ], default-features = fa
2121
bitcoin = { version = "0.32.4", features = [ "serde", "base64" ], default-features = false }
2222
serde = { version = "^1.0", features = ["derive"] }
2323
serde_json = { version = "^1.0" }
24-
bdk_chain = { version = "0.21.1", features = [ "miniscript", "serde" ], default-features = false }
25-
bdk_file_store = { version = "0.18.1", optional = true }
24+
# bdk_chain = { version = "0.22.0", features = [ "miniscript", "serde" ], default-features = false }
2625

2726
# Optional dependencies
2827
bip39 = { version = "2.0", optional = true }
28+
# bdk_file_store = { version = "0.20.0", optional = true }
29+
30+
[dependencies.bdk_chain]
31+
git = "https://github.com/bitcoindevkit/bdk"
32+
rev = "4fe121e7167cf93a8abf26c87d35b26a682f6cbc"
33+
default-features = false
34+
features = ["miniscript", "serde"]
35+
36+
[dependencies.bdk_file_store]
37+
git = "https://github.com/bitcoindevkit/bdk"
38+
rev = "4fe121e7167cf93a8abf26c87d35b26a682f6cbc"
39+
optional = true
2940

3041
[features]
3142
default = ["std"]
@@ -41,12 +52,16 @@ test-utils = ["std"]
4152
lazy_static = "1.4"
4253
assert_matches = "1.5.0"
4354
tempfile = "3"
44-
bdk_chain = { version = "0.21.1", features = ["rusqlite"] }
55+
# bdk_chain = { version = "0.22.0", features = ["rusqlite"] }
4556
bdk_wallet = { path = ".", features = ["rusqlite", "file_store", "test-utils"] }
46-
bdk_file_store = { version = "0.18.1" }
4757
anyhow = "1"
4858
rand = "^0.8"
4959

60+
[dev-dependencies.bdk_chain]
61+
git = "https://github.com/bitcoindevkit/bdk"
62+
rev = "4fe121e7167cf93a8abf26c87d35b26a682f6cbc"
63+
features = ["rusqlite"]
64+
5065
[package.metadata.docs.rs]
5166
all-features = true
5267
rustdoc-args = ["--cfg", "docsrs"]

wallet/README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,12 @@ To persist `Wallet` state data use a data store crate that reads and writes [`Ch
6565

6666
**Example**
6767

68-
<!-- compile_fail because outpoint and txout are fake variables -->
6968
```rust,no_run
7069
use bdk_wallet::{bitcoin::Network, KeychainKind, ChangeSet, Wallet};
7170
7271
// Open or create a new file store for wallet data.
73-
let mut db =
74-
bdk_file_store::Store::<ChangeSet>::open_or_create_new(b"magic_bytes", "/tmp/my_wallet.db")
72+
let (mut db, _changeset) =
73+
bdk_file_store::Store::<ChangeSet>::load_or_create(b"magic_bytes", "/tmp/my_wallet.db")
7574
.expect("create store");
7675
7776
// Create a wallet with initial wallet data read from the file store.

wallet/src/test_utils.rs

+20-18
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use alloc::string::ToString;
44
use alloc::sync::Arc;
55
use core::str::FromStr;
66

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

315-
/// Insert transaction
315+
/// Inserts a transaction into the local view, assuming it is currently present in the mempool.
316+
///
317+
/// This can be used, for example, to track a transaction immediately after it is broadcast.
316318
pub fn insert_tx(wallet: &mut Wallet, tx: Transaction) {
319+
let txid = tx.compute_txid();
320+
let seen_at = std::time::UNIX_EPOCH.elapsed().unwrap().as_secs();
321+
let mut tx_update = TxUpdate::default();
322+
tx_update.txs = vec![Arc::new(tx)];
323+
tx_update.seen_ats = [(txid, seen_at)].into();
317324
wallet
318325
.apply_update(Update {
319-
tx_update: bdk_chain::TxUpdate {
320-
txs: vec![Arc::new(tx)],
321-
..Default::default()
322-
},
326+
tx_update,
323327
..Default::default()
324328
})
325-
.unwrap();
329+
.expect("failed to apply update");
326330
}
327331

328332
/// Simulates confirming a tx with `txid` by applying an update to the wallet containing
329333
/// the given `anchor`. Note: to be considered confirmed the anchor block must exist in
330334
/// the current active chain.
331335
pub fn insert_anchor(wallet: &mut Wallet, txid: Txid, anchor: ConfirmationBlockTime) {
336+
let mut tx_update = TxUpdate::default();
337+
tx_update.anchors = [(anchor, txid)].into();
332338
wallet
333339
.apply_update(Update {
334-
tx_update: tx_graph::TxUpdate {
335-
anchors: [(anchor, txid)].into(),
336-
..Default::default()
337-
},
340+
tx_update,
338341
..Default::default()
339342
})
340-
.unwrap();
343+
.expect("failed to apply update");
341344
}
342345

343346
/// Marks the given `txid` seen as unconfirmed at `seen_at`
344347
pub fn insert_seen_at(wallet: &mut Wallet, txid: Txid, seen_at: u64) {
348+
let mut tx_update = TxUpdate::default();
349+
tx_update.seen_ats = [(txid, seen_at)].into();
345350
wallet
346-
.apply_update(crate::Update {
347-
tx_update: tx_graph::TxUpdate {
348-
seen_ats: [(txid, seen_at)].into_iter().collect(),
349-
..Default::default()
350-
},
351+
.apply_update(Update {
352+
tx_update,
351353
..Default::default()
352354
})
353-
.unwrap();
355+
.expect("failed to apply update");
354356
}

wallet/src/wallet/mod.rs

+42-29
Original file line numberDiff line numberDiff line change
@@ -2219,31 +2219,7 @@ impl Wallet {
22192219
///
22202220
/// After applying updates you should persist the staged wallet changes. For an example of how
22212221
/// to persist staged wallet changes see [`Wallet::reveal_next_address`].
2222-
#[cfg(feature = "std")]
2223-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
22242222
pub fn apply_update(&mut self, update: impl Into<Update>) -> Result<(), CannotConnectError> {
2225-
use std::time::*;
2226-
let now = SystemTime::now()
2227-
.duration_since(UNIX_EPOCH)
2228-
.expect("time now must surpass epoch anchor");
2229-
self.apply_update_at(update, now.as_secs())
2230-
}
2231-
2232-
/// Applies an `update` alongside a `seen_at` timestamp and stages the changes.
2233-
///
2234-
/// `seen_at` represents when the update is seen (in unix seconds). It is used to determine the
2235-
/// `last_seen`s for all transactions in the update which have no corresponding anchor(s). The
2236-
/// `last_seen` value is used internally to determine precedence of conflicting unconfirmed
2237-
/// transactions (where the transaction with the lower `last_seen` value is omitted from the
2238-
/// canonical history).
2239-
///
2240-
/// Use [`apply_update`](Wallet::apply_update) to have the `seen_at` value automatically set to
2241-
/// the current time.
2242-
pub fn apply_update_at(
2243-
&mut self,
2244-
update: impl Into<Update>,
2245-
seen_at: u64,
2246-
) -> Result<(), CannotConnectError> {
22472223
let update = update.into();
22482224
let mut changeset = match update.chain {
22492225
Some(chain_update) => ChangeSet::from(self.chain.apply_update(chain_update)?),
@@ -2255,11 +2231,7 @@ impl Wallet {
22552231
.index
22562232
.reveal_to_target_multi(&update.last_active_indices);
22572233
changeset.merge(index_changeset.into());
2258-
changeset.merge(
2259-
self.indexed_graph
2260-
.apply_update_at(update.tx_update, Some(seen_at))
2261-
.into(),
2262-
);
2234+
changeset.merge(self.indexed_graph.apply_update(update.tx_update).into());
22632235
self.stage.merge(changeset);
22642236
Ok(())
22652237
}
@@ -2397,16 +2369,47 @@ impl Wallet {
23972369

23982370
/// Methods to construct sync/full-scan requests for spk-based chain sources.
23992371
impl Wallet {
2372+
/// Create a partial [`SyncRequest`] for all revealed spks at `start_time`.
2373+
///
2374+
/// The `start_time` is used to record the time that a mempool transaction was last seen
2375+
/// (or evicted). See [`Wallet::start_sync_with_revealed_spks`] for more.
2376+
pub fn start_sync_with_revealed_spks_at(
2377+
&self,
2378+
start_time: u64,
2379+
) -> SyncRequestBuilder<(KeychainKind, u32)> {
2380+
use bdk_chain::keychain_txout::SyncRequestBuilderExt;
2381+
SyncRequest::builder_at(start_time)
2382+
.chain_tip(self.chain.tip())
2383+
.revealed_spks_from_indexer(&self.indexed_graph.index, ..)
2384+
.expected_spk_txids(self.indexed_graph.list_expected_spk_txids(
2385+
&self.chain,
2386+
self.chain.tip().block_id(),
2387+
..,
2388+
))
2389+
}
2390+
24002391
/// Create a partial [`SyncRequest`] for this wallet for all revealed spks.
24012392
///
24022393
/// This is the first step when performing a spk-based wallet partial sync, the returned
24032394
/// [`SyncRequest`] collects all revealed script pubkeys from the wallet keychain needed to
24042395
/// start a blockchain sync with a spk based blockchain client.
2396+
///
2397+
/// The time of the sync is the current system time and is used to record the
2398+
/// tx last-seen for mempool transactions. Or if an expected transaction is missing
2399+
/// or evicted, it is the time of the eviction. Note that timestamps may only increase
2400+
/// to be counted by the tx graph. To supply your own start time see [`Wallet::start_sync_at`].
2401+
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
2402+
#[cfg(feature = "std")]
24052403
pub fn start_sync_with_revealed_spks(&self) -> SyncRequestBuilder<(KeychainKind, u32)> {
24062404
use bdk_chain::keychain_txout::SyncRequestBuilderExt;
24072405
SyncRequest::builder()
24082406
.chain_tip(self.chain.tip())
24092407
.revealed_spks_from_indexer(&self.indexed_graph.index, ..)
2408+
.expected_spk_txids(self.indexed_graph.list_expected_spk_txids(
2409+
&self.chain,
2410+
self.chain.tip().block_id(),
2411+
..,
2412+
))
24102413
}
24112414

24122415
/// Create a [`FullScanRequest] for this wallet.
@@ -2417,12 +2420,22 @@ impl Wallet {
24172420
///
24182421
/// This operation is generally only used when importing or restoring a previously used wallet
24192422
/// in which the list of used scripts is not known.
2423+
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
2424+
#[cfg(feature = "std")]
24202425
pub fn start_full_scan(&self) -> FullScanRequestBuilder<KeychainKind> {
24212426
use bdk_chain::keychain_txout::FullScanRequestBuilderExt;
24222427
FullScanRequest::builder()
24232428
.chain_tip(self.chain.tip())
24242429
.spks_from_indexer(&self.indexed_graph.index)
24252430
}
2431+
2432+
/// Create a [`FullScanRequest`] builder at `start_time`.
2433+
pub fn start_full_scan_at(&self, start_time: u64) -> FullScanRequestBuilder<KeychainKind> {
2434+
use bdk_chain::keychain_txout::FullScanRequestBuilderExt;
2435+
FullScanRequest::builder_at(start_time)
2436+
.chain_tip(self.chain.tip())
2437+
.spks_from_indexer(&self.indexed_graph.index)
2438+
}
24262439
}
24272440

24282441
impl AsRef<bdk_chain::tx_graph::TxGraph<ConfirmationBlockTime>> for Wallet {

wallet/src/wallet/persisted.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl WalletPersister for bdk_chain::rusqlite::Connection {
291291
#[derive(Debug)]
292292
pub enum FileStoreError {
293293
/// Error when loading from the store.
294-
Load(bdk_file_store::AggregateChangesetsError<ChangeSet>),
294+
Load(bdk_file_store::StoreErrorWithDump<ChangeSet>),
295295
/// Error when writing to the store.
296296
Write(std::io::Error),
297297
}
@@ -316,15 +316,13 @@ impl WalletPersister for bdk_file_store::Store<ChangeSet> {
316316

317317
fn initialize(persister: &mut Self) -> Result<ChangeSet, Self::Error> {
318318
persister
319-
.aggregate_changesets()
319+
.dump()
320320
.map(Option::unwrap_or_default)
321321
.map_err(FileStoreError::Load)
322322
}
323323

324324
fn persist(persister: &mut Self, changeset: &ChangeSet) -> Result<(), Self::Error> {
325-
persister
326-
.append_changeset(changeset)
327-
.map_err(FileStoreError::Write)
325+
persister.append(changeset).map_err(FileStoreError::Write)
328326
}
329327
}
330328

wallet/tests/wallet.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ fn wallet_is_persisted() -> anyhow::Result<()> {
117117

118118
run(
119119
"store.db",
120-
|path| Ok(bdk_file_store::Store::create_new(DB_MAGIC, path)?),
121-
|path| Ok(bdk_file_store::Store::open(DB_MAGIC, path)?),
120+
|path| Ok(bdk_file_store::Store::create(DB_MAGIC, path)?),
121+
|path| Ok(bdk_file_store::Store::load(DB_MAGIC, path)?.0),
122122
)?;
123123
run::<bdk_chain::rusqlite::Connection, _, _>(
124124
"store.sqlite",
@@ -209,12 +209,8 @@ fn wallet_load_checks() -> anyhow::Result<()> {
209209

210210
run(
211211
"store.db",
212-
|path| {
213-
Ok(bdk_file_store::Store::<ChangeSet>::create_new(
214-
DB_MAGIC, path,
215-
)?)
216-
},
217-
|path| Ok(bdk_file_store::Store::<ChangeSet>::open(DB_MAGIC, path)?),
212+
|path| Ok(bdk_file_store::Store::<ChangeSet>::create(DB_MAGIC, path)?),
213+
|path| Ok(bdk_file_store::Store::<ChangeSet>::load(DB_MAGIC, path)?.0),
218214
)?;
219215
run(
220216
"store.sqlite",

0 commit comments

Comments
 (0)