Skip to content

Commit 6467969

Browse files
feat(wallet): Introduce WalletEvent
Co-authored-by: valued mammal <valuedmammal@protonmail.com>
1 parent 132d4b6 commit 6467969

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

src/wallet/event.rs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//! User facing wallet events.
2+
3+
use alloc::sync::Arc;
4+
use alloc::vec::Vec;
5+
use bitcoin::{Transaction, Txid};
6+
use chain::{BlockId, ConfirmationBlockTime};
7+
8+
/// Events representing changes to wallet transactions.
9+
///
10+
/// Returned after calling
11+
/// [`Wallet::apply_update_events`](crate::wallet::Wallet::apply_update_events).
12+
#[derive(Debug, Clone, PartialEq, Eq)]
13+
#[non_exhaustive]
14+
pub enum WalletEvent {
15+
/// The latest chain tip known to the wallet changed.
16+
ChainTipChanged {
17+
/// Previous chain tip.
18+
old_tip: BlockId,
19+
/// New chain tip.
20+
new_tip: BlockId,
21+
},
22+
/// A transaction is now confirmed.
23+
///
24+
/// If the transaction was previously unconfirmed `old_block_time` will be `None`.
25+
///
26+
/// If a confirmed transaction is now re-confirmed in a new block `old_block_time` will contain
27+
/// the block id and the time it was previously confirmed. This can happen after a chain
28+
/// reorg.
29+
TxConfirmed {
30+
/// Transaction id.
31+
txid: Txid,
32+
/// Transaction.
33+
tx: Arc<Transaction>,
34+
/// Confirmation block time.
35+
block_time: ConfirmationBlockTime,
36+
/// Old confirmation block and time if previously confirmed in a different block.
37+
old_block_time: Option<ConfirmationBlockTime>,
38+
},
39+
/// A transaction is now unconfirmed.
40+
///
41+
/// If the transaction is first seen in the mempool `old_block_time` will be `None`.
42+
///
43+
/// If a previously confirmed transaction is now seen in the mempool `old_block_time` will
44+
/// contain the block id and the time it was previously confirmed. This can happen after a
45+
/// chain reorg.
46+
TxUnconfirmed {
47+
/// Transaction id.
48+
txid: Txid,
49+
/// Transaction.
50+
tx: Arc<Transaction>,
51+
/// Old confirmation block and time, if previously confirmed.
52+
old_block_time: Option<ConfirmationBlockTime>,
53+
},
54+
/// An unconfirmed transaction was replaced.
55+
///
56+
/// This can happen after an RBF is broadcast or if a third party double spends an input of
57+
/// a received payment transaction before it is confirmed.
58+
///
59+
/// The conflicts field contains the txid and vin (in which it conflicts) of the conflicting
60+
/// transactions.
61+
TxReplaced {
62+
/// Transaction id.
63+
txid: Txid,
64+
/// Transaction.
65+
tx: Arc<Transaction>,
66+
/// Conflicting transaction ids.
67+
conflicts: Vec<(usize, Txid)>,
68+
},
69+
/// Unconfirmed transaction dropped.
70+
///
71+
/// The transaction was dropped from the local mempool. This is generally due to the fee rate
72+
/// being too low. The transaction can still reappear in the mempool in the future resulting in
73+
/// a [`WalletEvent::TxUnconfirmed`] event.
74+
TxDropped {
75+
/// Transaction id.
76+
txid: Txid,
77+
/// Transaction.
78+
tx: Arc<Transaction>,
79+
},
80+
}

src/wallet/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ use rand_core::RngCore;
5252
mod changeset;
5353
pub mod coin_selection;
5454
pub mod error;
55+
mod event;
5556
pub mod export;
5657
pub mod locked_outpoints;
5758
mod params;
@@ -79,6 +80,7 @@ use crate::wallet::{
7980
// re-exports
8081
pub use bdk_chain::Balance;
8182
pub use changeset::ChangeSet;
83+
pub use event::*;
8284
pub use params::*;
8385
pub use persisted::*;
8486
pub use utils::IsDust;

0 commit comments

Comments
 (0)