From: 志宇 Date: Wed, 9 Oct 2024 14:36:27 +0000 (+0000) Subject: feat(wallet)!: make `seen_at` mandatory for `Wallet::apply_update_at` X-Git-Tag: v1.0.0-beta.6~22^2 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/struct.EncoderStringWriter.html?a=commitdiff_plain;h=b0dc3ddd3a5f2ff8e5b2fc5654fc2519bc7e728e;p=bdk feat(wallet)!: make `seen_at` mandatory for `Wallet::apply_update_at` Not including a `seen_at` alongside the update means the unconfirmed txs of the update will not be considered to be part of the canonical history. Therefore, transactions created with this wallet may replace the update's unconfirmed txs (which is unintuitive behavior). Also updated the docs. --- diff --git a/crates/wallet/src/wallet/mod.rs b/crates/wallet/src/wallet/mod.rs index 7df48f07..68d5e6be 100644 --- a/crates/wallet/src/wallet/mod.rs +++ b/crates/wallet/src/wallet/mod.rs @@ -2254,10 +2254,10 @@ impl Wallet { let now = SystemTime::now() .duration_since(UNIX_EPOCH) .expect("time now must surpass epoch anchor"); - self.apply_update_at(update, Some(now.as_secs())) + self.apply_update_at(update, now.as_secs()) } - /// Applies an `update` alongside an optional `seen_at` timestamp and stages the changes. + /// Applies an `update` alongside a `seen_at` timestamp and stages the changes. /// /// `seen_at` represents when the update is seen (in unix seconds). It is used to determine the /// `last_seen`s for all transactions in the update which have no corresponding anchor(s). The @@ -2265,15 +2265,12 @@ impl Wallet { /// transactions (where the transaction with the lower `last_seen` value is omitted from the /// canonical history). /// - /// Not setting a `seen_at` value means unconfirmed transactions introduced by this update will - /// not be part of the canonical history of transactions. - /// /// Use [`apply_update`](Wallet::apply_update) to have the `seen_at` value automatically set to /// the current time. pub fn apply_update_at( &mut self, update: impl Into, - seen_at: Option, + seen_at: u64, ) -> Result<(), CannotConnectError> { let update = update.into(); let mut changeset = match update.chain { @@ -2288,7 +2285,7 @@ impl Wallet { changeset.merge(index_changeset.into()); changeset.merge( self.indexed_graph - .apply_update_at(update.tx_update, seen_at) + .apply_update_at(update.tx_update, Some(seen_at)) .into(), ); self.stage.merge(changeset);