Skip to content

Commit aa410c2

Browse files
committed
rpc: Validate maxfeerate with AmountFromValue
1 parent 327d274 commit aa410c2

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,15 +1090,13 @@ static UniValue sendrawtransaction(const JSONRPCRequest& request)
10901090
// TODO: temporary migration code for old clients. Remove in v0.20
10911091
if (request.params[1].isBool()) {
10921092
throw JSONRPCError(RPC_INVALID_PARAMETER, "Second argument must be numeric (maxfeerate) and no longer supports a boolean. To allow a transaction with high fees, set maxfeerate to 0.");
1093-
} else if (request.params[1].isNum()) {
1093+
} else if (!request.params[1].isNull()) {
10941094
size_t weight = GetTransactionWeight(*tx);
10951095
CFeeRate fr(AmountFromValue(request.params[1]));
10961096
// the +3/4 part rounds the value up, and is the same formula used when
10971097
// calculating the fee for a transaction
10981098
// (see GetVirtualTransactionSize)
10991099
max_raw_tx_fee = fr.GetFee((weight+3)/4);
1100-
} else if (!request.params[1].isNull()) {
1101-
throw JSONRPCError(RPC_INVALID_PARAMETER, "second argument (maxfeerate) must be numeric");
11021100
}
11031101

11041102
uint256 txid;
@@ -1172,15 +1170,13 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request)
11721170
// TODO: temporary migration code for old clients. Remove in v0.20
11731171
if (request.params[1].isBool()) {
11741172
throw JSONRPCError(RPC_INVALID_PARAMETER, "Second argument must be numeric (maxfeerate) and no longer supports a boolean. To allow a transaction with high fees, set maxfeerate to 0.");
1175-
} else if (request.params[1].isNum()) {
1173+
} else if (!request.params[1].isNull()) {
11761174
size_t weight = GetTransactionWeight(*tx);
11771175
CFeeRate fr(AmountFromValue(request.params[1]));
11781176
// the +3/4 part rounds the value up, and is the same formula used when
11791177
// calculating the fee for a transaction
11801178
// (see GetVirtualTransactionSize)
11811179
max_raw_tx_fee = fr.GetFee((weight+3)/4);
1182-
} else if (!request.params[1].isNull()) {
1183-
throw JSONRPCError(RPC_INVALID_PARAMETER, "second argument (maxfeerate) must be numeric");
11841180
}
11851181

11861182
UniValue result(UniValue::VARR);

test/functional/rpc_rawtransaction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,9 @@ def run_test(self):
446446
# and sendrawtransaction should throw
447447
assert_raises_rpc_error(-26, "absurdly-high-fee", self.nodes[2].sendrawtransaction, rawTxSigned['hex'], 0.00001000)
448448
# And below calls should both succeed
449-
testres = self.nodes[2].testmempoolaccept(rawtxs=[rawTxSigned['hex']], maxfeerate=0.00007000)[0]
449+
testres = self.nodes[2].testmempoolaccept(rawtxs=[rawTxSigned['hex']], maxfeerate='0.00007000')[0]
450450
assert_equal(testres['allowed'], True)
451-
self.nodes[2].sendrawtransaction(hexstring=rawTxSigned['hex'], maxfeerate=0.00007000)
451+
self.nodes[2].sendrawtransaction(hexstring=rawTxSigned['hex'], maxfeerate='0.00007000')
452452

453453

454454
if __name__ == '__main__':

0 commit comments

Comments
 (0)