@@ -2219,31 +2219,7 @@ impl Wallet {
2219
2219
///
2220
2220
/// After applying updates you should persist the staged wallet changes. For an example of how
2221
2221
/// to persist staged wallet changes see [`Wallet::reveal_next_address`].
2222
- #[ cfg( feature = "std" ) ]
2223
- #[ cfg_attr( docsrs, doc( cfg( feature = "std" ) ) ) ]
2224
2222
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 > {
2247
2223
let update = update. into ( ) ;
2248
2224
let mut changeset = match update. chain {
2249
2225
Some ( chain_update) => ChangeSet :: from ( self . chain . apply_update ( chain_update) ?) ,
@@ -2255,11 +2231,7 @@ impl Wallet {
2255
2231
. index
2256
2232
. reveal_to_target_multi ( & update. last_active_indices ) ;
2257
2233
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 ( ) ) ;
2263
2235
self . stage . merge ( changeset) ;
2264
2236
Ok ( ( ) )
2265
2237
}
@@ -2397,16 +2369,47 @@ impl Wallet {
2397
2369
2398
2370
/// Methods to construct sync/full-scan requests for spk-based chain sources.
2399
2371
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
+
2400
2391
/// Create a partial [`SyncRequest`] for this wallet for all revealed spks.
2401
2392
///
2402
2393
/// This is the first step when performing a spk-based wallet partial sync, the returned
2403
2394
/// [`SyncRequest`] collects all revealed script pubkeys from the wallet keychain needed to
2404
2395
/// 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" ) ]
2405
2403
pub fn start_sync_with_revealed_spks ( & self ) -> SyncRequestBuilder < ( KeychainKind , u32 ) > {
2406
2404
use bdk_chain:: keychain_txout:: SyncRequestBuilderExt ;
2407
2405
SyncRequest :: builder ( )
2408
2406
. chain_tip ( self . chain . tip ( ) )
2409
2407
. 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
+ ) )
2410
2413
}
2411
2414
2412
2415
/// Create a [`FullScanRequest] for this wallet.
@@ -2417,12 +2420,22 @@ impl Wallet {
2417
2420
///
2418
2421
/// This operation is generally only used when importing or restoring a previously used wallet
2419
2422
/// in which the list of used scripts is not known.
2423
+ #[ cfg_attr( docsrs, doc( cfg( feature = "std" ) ) ) ]
2424
+ #[ cfg( feature = "std" ) ]
2420
2425
pub fn start_full_scan ( & self ) -> FullScanRequestBuilder < KeychainKind > {
2421
2426
use bdk_chain:: keychain_txout:: FullScanRequestBuilderExt ;
2422
2427
FullScanRequest :: builder ( )
2423
2428
. chain_tip ( self . chain . tip ( ) )
2424
2429
. spks_from_indexer ( & self . indexed_graph . index )
2425
2430
}
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
+ }
2426
2439
}
2427
2440
2428
2441
impl AsRef < bdk_chain:: tx_graph:: TxGraph < ConfirmationBlockTime > > for Wallet {
0 commit comments