@@ -2379,6 +2379,78 @@ impl Wallet {
2379
2379
/// After applying updates you should process the events in your app before persisting the
2380
2380
/// staged wallet changes. For an example of how to persist staged wallet changes see
2381
2381
/// [`Wallet::reveal_next_address`].
2382
+ ///
2383
+ /// ```rust,no_run
2384
+ /// # use bitcoin::*;
2385
+ /// # use bdk_wallet::*;
2386
+ /// use bdk_wallet::event::WalletEvent;
2387
+ /// # let wallet_update = Update::default();
2388
+ /// # let mut wallet = doctest_wallet!();
2389
+ /// let events = wallet.apply_update_events(wallet_update)?;
2390
+ /// // Handle wallet relevant events from this update.
2391
+ /// events.iter().for_each(|event| {
2392
+ /// match event {
2393
+ /// // The chain tip changed.
2394
+ /// WalletEvent::ChainTipChanged { old_tip, new_tip } => {
2395
+ /// todo!() // handle event
2396
+ /// }
2397
+ /// // An unconfirmed tx is now confirmed in a block.
2398
+ /// WalletEvent::TxConfirmed {
2399
+ /// txid,
2400
+ /// tx,
2401
+ /// block_time,
2402
+ /// old_block_time: None,
2403
+ /// } => {
2404
+ /// todo!() // handle event
2405
+ /// }
2406
+ /// // A confirmed tx is now confirmed in a new block (reorg).
2407
+ /// WalletEvent::TxConfirmed {
2408
+ /// txid,
2409
+ /// tx,
2410
+ /// block_time,
2411
+ /// old_block_time: Some(old_block_time),
2412
+ /// } => {
2413
+ /// todo!() // handle event
2414
+ /// }
2415
+ /// // A new unconfirmed tx was seen in the mempool.
2416
+ /// WalletEvent::TxUnconfirmed {
2417
+ /// txid,
2418
+ /// tx,
2419
+ /// old_block_time: None,
2420
+ /// } => {
2421
+ /// todo!() // handle event
2422
+ /// }
2423
+ /// // A previously confirmed tx in now unconfirmed in the mempool (reorg).
2424
+ /// WalletEvent::TxUnconfirmed {
2425
+ /// txid,
2426
+ /// tx,
2427
+ /// old_block_time: Some(old_block_time),
2428
+ /// } => {
2429
+ /// todo!() // handle event
2430
+ /// }
2431
+ /// // An unconfirmed tx was replaced in the mempool (RBF or double spent input).
2432
+ /// WalletEvent::TxReplaced {
2433
+ /// txid,
2434
+ /// tx,
2435
+ /// conflicts,
2436
+ /// } => {
2437
+ /// todo!() // handle event
2438
+ /// }
2439
+ /// // An unconfirmed tx was dropped from the mempool (fee too low).
2440
+ /// WalletEvent::TxDropped { txid, tx } => {
2441
+ /// todo!() // handle event
2442
+ /// }
2443
+ /// _ => {
2444
+ /// // unexpected event, do nothing
2445
+ /// }
2446
+ /// }
2447
+ /// // take staged wallet changes
2448
+ /// let staged = wallet.take_staged();
2449
+ /// // persist staged changes
2450
+ /// });
2451
+ /// # Ok::<(), anyhow::Error>(())
2452
+ /// ```
2453
+ /// [`TxBuilder`]: crate::TxBuilder
2382
2454
pub fn apply_update_events (
2383
2455
& mut self ,
2384
2456
update : impl Into < Update > ,
0 commit comments