aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Chow <github@achow101.com>2023-05-01 08:32:36 -0400
committerAndrew Chow <github@achow101.com>2023-05-01 08:38:50 -0400
commit3497df4c759afcdf32dff1680c4e8bc48f9e7caa (patch)
treee26d34da75205d8a3eeab295d630f80c4271c4c6 /src
parent071308860a857cc7897b7d0d50c69d0326fd5710 (diff)
parentbe72663a1521bc6cdf16d43a4feae7c5b57735c0 (diff)
Merge bitcoin/bitcoin#27195: bumpfee: allow send coins back to yourself
be72663a1521bc6cdf16d43a4feae7c5b57735c0 test: bumpfee, add coverage for "send coins back to yourself" (furszy) 7bffec6715a75bb2c8631177d39f984aabc656ba bumpfee: enable send coins back to yourself (furszy) Pull request description: Simple example: 1) User_1 sends 0.1 btc to user_2 on a low fee transaction. 2) After few hours, the tx is still in the mempool, user_2 is not interested anymore, so user_1 decides to cancel it by sending coins back to himself. 3) User_1 has the bright idea of opening the explorer and copy the change output address of the transaction. Then call bumpfee providing such output (in the "outputs" arg). Currently, this is not possible. The wallet fails with "Unable to create transaction. Transaction must have at least one recipient" error. The error reason is because we discard the provided output from the recipients list and set it inside the coin control so the process adds it later (when the change is calculated). But.. there is no later if the tx has no outputs. ACKs for top commit: ishaanam: reACK be72663a1521bc6cdf16d43a4feae7c5b57735c0 achow101: ACK be72663a1521bc6cdf16d43a4feae7c5b57735c0 Tree-SHA512: c2c38290a998f9b426a830d9624c7feb730158980ac186f8fb0138d5e200935d6538307bc60a2c3d0b7b6ee2b4ffb77a1e98baf8feb1d20a7d825f6055ac377f
Diffstat (limited to 'src')
-rw-r--r--src/wallet/feebumper.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/wallet/feebumper.cpp b/src/wallet/feebumper.cpp
index d127c41c43..b6b1fa1d3e 100644
--- a/src/wallet/feebumper.cpp
+++ b/src/wallet/feebumper.cpp
@@ -231,6 +231,7 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
// is one). If outputs vector is non-empty, replace original
// outputs with its contents, otherwise use original outputs.
std::vector<CRecipient> recipients;
+ CAmount new_outputs_value = 0;
const auto& txouts = outputs.empty() ? wtx.tx->vout : outputs;
for (const auto& output : txouts) {
if (!OutputIsChange(wallet, output)) {
@@ -241,6 +242,21 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
ExtractDestination(output.scriptPubKey, change_dest);
new_coin_control.destChange = change_dest;
}
+ new_outputs_value += output.nValue;
+ }
+
+ // If no recipients, means that we are sending coins to a change address
+ if (recipients.empty()) {
+ // Just as a sanity check, ensure that the change address exist
+ if (std::get_if<CNoDestination>(&new_coin_control.destChange)) {
+ errors.emplace_back(Untranslated("Unable to create transaction. Transaction must have at least one recipient"));
+ return Result::INVALID_PARAMETER;
+ }
+
+ // Add change as recipient with SFFO flag enabled, so fees are deduced from it.
+ // If the output differs from the original tx output (because the user customized it) a new change output will be created.
+ recipients.emplace_back(CRecipient{GetScriptForDestination(new_coin_control.destChange), new_outputs_value, /*fSubtractFeeFromAmount=*/true});
+ new_coin_control.destChange = CNoDestination();
}
if (coin_control.m_feerate) {