diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3165,10 +3165,6 @@ if (nChangePosInOut != -1) { tx.vout.insert(tx.vout.begin() + nChangePosInOut, tx_new->vout[nChangePosInOut]); - // We don't have the normal Create/Commit cycle, and don't want to - // risk reusing change, so just remove the key from the keypool - // here. - reservedest.KeepDestination(); } // Copy output sizes from new transaction; they may have had the fee @@ -3588,11 +3584,6 @@ continue; } - if (nChangePosInOut == -1) { - // Return any reserved address if we don't have change - reservedest.ReturnDestination(); - } - // Shuffle selected coins and fill in final vin txNew.vin.clear(); std::vector selected_coins(setCoins.begin(), @@ -3656,6 +3647,10 @@ } } + // Before we return success, we assume any change key will be used to + // prevent accidental re-use. + reservedest.KeepDestination(); + return true; }