|
| 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 | +} |
0 commit comments