]> Untitled Git - bdk/commitdiff
feat(wallet)!: make `seen_at` mandatory for `Wallet::apply_update_at`
author志宇 <hello@evanlinjin.me>
Wed, 9 Oct 2024 14:36:27 +0000 (14:36 +0000)
committervalued mammal <valuedmammal@protonmail.com>
Tue, 5 Nov 2024 19:14:36 +0000 (14:14 -0500)
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.

crates/wallet/src/wallet/mod.rs

index 7df48f0716cd57c42e2d8132012e7e44e1c91a15..68d5e6bec28cc44ec6cb0f35d68d2c68e8877552 100644 (file)
@@ -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<Update>,
-        seen_at: Option<u64>,
+        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);