Skip to content

Commit

Permalink
commands: update next deriv index for any spend output address
Browse files Browse the repository at this point in the history
It's basically free to do now, so we might as well do it.
  • Loading branch information
darosior committed Dec 8, 2023
1 parent 5d50155 commit 0523f00
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ impl DaemonControl {
};

// Create the PSBT. If there was no error in doing so make sure to update our next
// derivation index in case the change address which we generated or was provided to us was
// for a future derivation index.
// derivation index in case any address in the transaction outputs was ours and from the
// future.
let change_info = change_address.info;
let CreateSpendRes { psbt, has_change } = create_spend(
&self.config.main_descriptor,
Expand All @@ -492,6 +492,9 @@ impl DaemonControl {
0, // No min fee required.
change_address,
)?;
for (addr, _) in destinations_checked {
self.maybe_increase_next_deriv_index(&mut db_conn, &addr.info);
}
if has_change {
self.maybe_increase_next_deriv_index(&mut db_conn, &change_info);
}
Expand Down Expand Up @@ -840,8 +843,11 @@ impl DaemonControl {
if rbf_psbt.fee().expect("has already been sanity checked")
>= descendant_fees + bitcoin::Amount::from_sat(replacement_vsize)
{
// In case of success, make sure to update our next derivation index if the change
// address used was from the future.
// In case of success, make sure to update our next derivation index if any address
// used in the transaction outputs was from the future.
for (addr, _) in destinations {
self.maybe_increase_next_deriv_index(&mut db_conn, &addr.info);
}
if has_change {
self.maybe_increase_next_deriv_index(&mut db_conn, &change_address.info);
}
Expand Down

0 comments on commit 0523f00

Please sign in to comment.