mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-02 09:15:04 +02:00
wallet: reuse change dest when recreating TX with avoidpartialspends
This commit is contained in:
@@ -1092,6 +1092,13 @@ util::Result<CreatedTransactionResult> CreateTransaction(
|
||||
TRACE1(coin_selection, attempting_aps_create_tx, wallet.GetName().c_str());
|
||||
CCoinControl tmp_cc = coin_control;
|
||||
tmp_cc.m_avoid_partial_spends = true;
|
||||
|
||||
// Re-use the change destination from the first creation attempt to avoid skipping BIP44 indexes
|
||||
const int ungrouped_change_pos = txr_ungrouped.change_pos;
|
||||
if (ungrouped_change_pos != -1) {
|
||||
ExtractDestination(txr_ungrouped.tx->vout[ungrouped_change_pos].scriptPubKey, tmp_cc.destChange);
|
||||
}
|
||||
|
||||
auto txr_grouped = CreateTransactionInternal(wallet, vecSend, change_pos, tmp_cc, sign);
|
||||
// if fee of this alternative one is within the range of the max fee, we use this one
|
||||
const bool use_aps{txr_grouped.has_value() ? (txr_grouped->fee <= txr_ungrouped.fee + wallet.m_max_aps_fee) : false};
|
||||
|
||||
Reference in New Issue
Block a user