Skip to content

Commit

Permalink
feat(wallet)!: make seen_at mandatory for Wallet::apply_update_at
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
evanlinjin authored and ValuedMammal committed Nov 5, 2024
1 parent 00c568d commit b0dc3dd
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions crates/wallet/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2254,26 +2254,23 @@ 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
/// `last_seen` value is used internally to determine precedence of conflicting unconfirmed
/// 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 {
Expand All @@ -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);
Expand Down

0 comments on commit b0dc3dd

Please sign in to comment.