Skip to content

Commit 5983239

Browse files
author
MarcoFalke
committed
Merge bitcoin#15770: rpc: Validate maxfeerate with AmountFromValue
aa410c2 rpc: Validate maxfeerate with AmountFromValue (João Barbosa) Pull request description: With this change `maxfeerate` can also be set as a string, accordingly to the help test: ``` maxfeerate (numeric or string, ``` Beside, there are no tests for the removed errors. ACKs for commit aa410c: meshcollider: utACK bitcoin@aa410c2 MarcoFalke: utACK aa410c2 Good catch Tree-SHA512: f3bfea91dc7daa943729e270585dbf333055aeda805fbd01eaab20a7e0e6147382647c11525334382d198df0d3d45da6102b541efda5a1361f96271c98d5d89d
2 parents 78295e9 + aa410c2 commit 5983239

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
@@ -818,15 +818,13 @@ static UniValue sendrawtransaction(const JSONRPCRequest& request)
818818
// TODO: temporary migration code for old clients. Remove in v0.20
819819
if (request.params[1].isBool()) {
820820
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.");
821-
} else if (request.params[1].isNum()) {
821+
} else if (!request.params[1].isNull()) {
822822
size_t weight = GetTransactionWeight(*tx);
823823
CFeeRate fr(AmountFromValue(request.params[1]));
824824
// the +3/4 part rounds the value up, and is the same formula used when
825825
// calculating the fee for a transaction
826826
// (see GetVirtualTransactionSize)
827827
max_raw_tx_fee = fr.GetFee((weight+3)/4);
828-
} else if (!request.params[1].isNull()) {
829-
throw JSONRPCError(RPC_INVALID_PARAMETER, "second argument (maxfeerate) must be numeric");
830828
}
831829

832830
uint256 txid;
@@ -900,15 +898,13 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request)
900898
// TODO: temporary migration code for old clients. Remove in v0.20
901899
if (request.params[1].isBool()) {
902900
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.");
903-
} else if (request.params[1].isNum()) {
901+
} else if (!request.params[1].isNull()) {
904902
size_t weight = GetTransactionWeight(*tx);
905903
CFeeRate fr(AmountFromValue(request.params[1]));
906904
// the +3/4 part rounds the value up, and is the same formula used when
907905
// calculating the fee for a transaction
908906
// (see GetVirtualTransactionSize)
909907
max_raw_tx_fee = fr.GetFee((weight+3)/4);
910-
} else if (!request.params[1].isNull()) {
911-
throw JSONRPCError(RPC_INVALID_PARAMETER, "second argument (maxfeerate) must be numeric");
912908
}
913909

914910
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)