]> Untitled Git - bdk/commit
fix(wallet): only mark change address used if `create_tx` succeeds
authorvalued mammal <valuedmammal@protonmail.com>
Tue, 27 Aug 2024 15:54:25 +0000 (11:54 -0400)
committervalued mammal <valuedmammal@protonmail.com>
Mon, 9 Sep 2024 15:41:23 +0000 (11:41 -0400)
commitb60d1d29cb8908c354b43c49237acbea373c3dc7
tree4ebafd914cd401b1a4c16e1bc910637e3045073a
parent257c5f7f5ef2d2d333a553be5d15f1e5ce1ea709
fix(wallet): only mark change address used if `create_tx` succeeds

If no drain script is specified in tx params then we get it from
the change keychain by looking at the next unused address. We want
to mark the change address used so that other callers won't attempt
to use the same address between the time we create the tx and when
it appears on chain.

Before, we marked the index used regardless of whether a change
output is finally added. Then if creating a PSBT failed, we never
restored the unused status of the change address, so creating the
next tx would have revealed an extra one. Now we only mark the change
address used if we successfully create a PSBT and the drain script
is used in the change output.
crates/wallet/src/wallet/mod.rs