@@ -247,16 +247,17 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
247
247
248
248
old_fee = input_value - output_value;
249
249
250
+ // We need to make a temporary transaction with no input witnesses as the dummy signer expects them to be empty for external inputs
251
+ CMutableTransaction temp_mtx{*wtx.tx };
252
+ for (auto & txin : temp_mtx.vin ) {
253
+ txin.scriptSig .clear ();
254
+ txin.scriptWitness .SetNull ();
255
+ }
256
+ const int64_t maxTxSize{CalculateMaximumSignedTxSize (CTransaction (temp_mtx), &wallet, &new_coin_control).vsize };
257
+
250
258
if (coin_control.m_feerate ) {
251
259
// The user provided a feeRate argument.
252
260
// We calculate this here to avoid compiler warning on the cs_wallet lock
253
- // We need to make a temporary transaction with no input witnesses as the dummy signer expects them to be empty for external inputs
254
- CMutableTransaction mtx{*wtx.tx };
255
- for (auto & txin : mtx.vin ) {
256
- txin.scriptSig .clear ();
257
- txin.scriptWitness .SetNull ();
258
- }
259
- const int64_t maxTxSize{CalculateMaximumSignedTxSize (CTransaction (mtx), &wallet, &new_coin_control).vsize };
260
261
Result res = CheckFeeRate (wallet, wtx, *new_coin_control.m_feerate , maxTxSize, old_fee, errors);
261
262
if (res != Result::OK) {
262
263
return res;
@@ -281,21 +282,35 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
281
282
// We cannot source new unconfirmed inputs(bip125 rule 2)
282
283
new_coin_control.m_min_depth = 1 ;
283
284
284
- constexpr int RANDOM_CHANGE_POSITION = -1 ;
285
- auto res = CreateTransaction (wallet, recipients, RANDOM_CHANGE_POSITION, new_coin_control, false );
286
- if (!res) {
287
- errors.push_back (Untranslated (" Unable to create transaction." ) + Untranslated (" " ) + util::ErrorString (res));
288
- return Result::WALLET_ERROR;
289
- }
285
+ if (recipients.size () > 0 ) {
286
+ constexpr int RANDOM_CHANGE_POSITION = -1 ;
287
+ auto res = CreateTransaction (wallet, recipients, RANDOM_CHANGE_POSITION, new_coin_control, false );
288
+ if (!res) {
289
+ errors.push_back (Untranslated (" Unable to create transaction." ) + Untranslated (" " ) + util::ErrorString (res));
290
+ return Result::WALLET_ERROR;
291
+ }
290
292
291
- const auto & txr = *res;
292
- // Write back new fee if successful
293
- new_fee = txr.fee ;
293
+ const auto & txr = *res;
294
+ // Write back new fee if successful
295
+ new_fee = txr.fee ;
294
296
295
- // Write back transaction
296
- mtx = CMutableTransaction (*txr.tx );
297
+ // Write back transaction
298
+ mtx = CMutableTransaction (*txr.tx );
297
299
298
- return Result::OK;
300
+ return Result::OK;
301
+ } else {
302
+ // The transaction only has one output, and it is either detected as change,
303
+ // or selected as the one to take the fee from.
304
+ // In that case, just reduce its value to meet the new feerate.
305
+ new_fee = new_coin_control.m_feerate ->GetFee (maxTxSize);
306
+ temp_mtx.vout [0 ].nValue += old_fee - new_fee;
307
+ if (IsDust (temp_mtx.vout [0 ], wallet.chain ().relayDustFee ())) {
308
+ errors.push_back (Untranslated (" Single output amount too small" ));
309
+ return Result::MISC_ERROR;
310
+ }
311
+ mtx = temp_mtx;
312
+ return Result::OK;
313
+ }
299
314
}
300
315
301
316
bool SignTransaction (CWallet& wallet, CMutableTransaction& mtx) {
0 commit comments