Skip to content

Commit d1a95e8

Browse files
committed
Bumpfee move request parameter interaction to the top
1 parent fbf36ca commit d1a95e8

File tree

1 file changed

+37
-38
lines changed

1 file changed

+37
-38
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2859,6 +2859,38 @@ UniValue bumpfee(const JSONRPCRequest& request)
28592859
uint256 hash;
28602860
hash.SetHex(request.params[0].get_str());
28612861

2862+
// optional parameters
2863+
bool specifiedConfirmTarget = false;
2864+
int newConfirmTarget = nTxConfirmTarget;
2865+
CAmount totalFee = 0;
2866+
bool replaceable = true;
2867+
if (request.params.size() > 1) {
2868+
UniValue options = request.params[1];
2869+
RPCTypeCheckObj(options,
2870+
{
2871+
{"confTarget", UniValueType(UniValue::VNUM)},
2872+
{"totalFee", UniValueType(UniValue::VNUM)},
2873+
{"replaceable", UniValueType(UniValue::VBOOL)},
2874+
},
2875+
true, true);
2876+
2877+
if (options.exists("confTarget") && options.exists("totalFee")) {
2878+
throw JSONRPCError(RPC_INVALID_PARAMETER, "confTarget and totalFee options should not both be set. Please provide either a confirmation target for fee estimation or an explicit total fee for the transaction.");
2879+
} else if (options.exists("confTarget")) {
2880+
specifiedConfirmTarget = true;
2881+
newConfirmTarget = options["confTarget"].get_int();
2882+
if (newConfirmTarget <= 0) { // upper-bound will be checked by estimatefee/smartfee
2883+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid confTarget (cannot be <= 0)");
2884+
}
2885+
} else if (options.exists("totalFee")) {
2886+
totalFee = options["totalFee"].get_int64();
2887+
}
2888+
2889+
if (options.exists("replaceable")) {
2890+
replaceable = options["replaceable"].get_bool();
2891+
}
2892+
}
2893+
28622894
// retrieve the original tx from the wallet
28632895
LOCK2(cs_main, pwallet->cs_wallet);
28642896
EnsureWalletIsUnlocked(pwallet);
@@ -2916,44 +2948,6 @@ UniValue bumpfee(const JSONRPCRequest& request)
29162948
int64_t txSize = GetVirtualTransactionSize(*(wtx.tx));
29172949
const int64_t maxNewTxSize = CalculateMaximumSignedTxSize(*wtx.tx, *pwallet);
29182950

2919-
// optional parameters
2920-
bool specifiedConfirmTarget = false;
2921-
int newConfirmTarget = nTxConfirmTarget;
2922-
CAmount totalFee = 0;
2923-
bool replaceable = true;
2924-
if (request.params.size() > 1) {
2925-
UniValue options = request.params[1];
2926-
RPCTypeCheckObj(options,
2927-
{
2928-
{"confTarget", UniValueType(UniValue::VNUM)},
2929-
{"totalFee", UniValueType(UniValue::VNUM)},
2930-
{"replaceable", UniValueType(UniValue::VBOOL)},
2931-
},
2932-
true, true);
2933-
2934-
if (options.exists("confTarget") && options.exists("totalFee")) {
2935-
throw JSONRPCError(RPC_INVALID_PARAMETER, "confTarget and totalFee options should not both be set. Please provide either a confirmation target for fee estimation or an explicit total fee for the transaction.");
2936-
} else if (options.exists("confTarget")) {
2937-
specifiedConfirmTarget = true;
2938-
newConfirmTarget = options["confTarget"].get_int();
2939-
if (newConfirmTarget <= 0) { // upper-bound will be checked by estimatefee/smartfee
2940-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid confTarget (cannot be <= 0)");
2941-
}
2942-
} else if (options.exists("totalFee")) {
2943-
totalFee = options["totalFee"].get_int64();
2944-
CAmount requiredFee = CWallet::GetRequiredFee(maxNewTxSize);
2945-
if (totalFee < requiredFee ) {
2946-
throw JSONRPCError(RPC_INVALID_PARAMETER,
2947-
strprintf("Insufficient totalFee (cannot be less than required fee %s)",
2948-
FormatMoney(requiredFee)));
2949-
}
2950-
}
2951-
2952-
if (options.exists("replaceable")) {
2953-
replaceable = options["replaceable"].get_bool();
2954-
}
2955-
}
2956-
29572951
// calculate the old fee and fee-rate
29582952
CAmount nOldFee = wtx.GetDebit(ISMINE_SPENDABLE) - wtx.tx->GetValueOut();
29592953
CFeeRate nOldFeeRate(nOldFee, txSize);
@@ -2973,6 +2967,11 @@ UniValue bumpfee(const JSONRPCRequest& request)
29732967
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Insufficient totalFee, must be at least %s (oldFee %s + incrementalFee %s)",
29742968
FormatMoney(minTotalFee), FormatMoney(nOldFeeRate.GetFee(maxNewTxSize)), FormatMoney(::incrementalRelayFee.GetFee(maxNewTxSize))));
29752969
}
2970+
CAmount requiredFee = CWallet::GetRequiredFee(maxNewTxSize);
2971+
if (totalFee < requiredFee ) {
2972+
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Insufficient totalFee (cannot be less than required fee %s)",
2973+
FormatMoney(requiredFee)));
2974+
}
29762975
nNewFee = totalFee;
29772976
nNewFeeRate = CFeeRate(totalFee, maxNewTxSize);
29782977
} else {

0 commit comments

Comments
 (0)