mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
Merge #15770: rpc: Validate maxfeerate with AmountFromValue
aa410c2b17rpc: 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: utACKaa410c2b17MarcoFalke: utACKaa410c2b17Good catch Tree-SHA512: f3bfea91dc7daa943729e270585dbf333055aeda805fbd01eaab20a7e0e6147382647c11525334382d198df0d3d45da6102b541efda5a1361f96271c98d5d89d
This commit is contained in:
@@ -818,15 +818,13 @@ static UniValue sendrawtransaction(const JSONRPCRequest& request)
|
|||||||
// TODO: temporary migration code for old clients. Remove in v0.20
|
// TODO: temporary migration code for old clients. Remove in v0.20
|
||||||
if (request.params[1].isBool()) {
|
if (request.params[1].isBool()) {
|
||||||
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.");
|
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.");
|
||||||
} else if (request.params[1].isNum()) {
|
} else if (!request.params[1].isNull()) {
|
||||||
size_t weight = GetTransactionWeight(*tx);
|
size_t weight = GetTransactionWeight(*tx);
|
||||||
CFeeRate fr(AmountFromValue(request.params[1]));
|
CFeeRate fr(AmountFromValue(request.params[1]));
|
||||||
// the +3/4 part rounds the value up, and is the same formula used when
|
// the +3/4 part rounds the value up, and is the same formula used when
|
||||||
// calculating the fee for a transaction
|
// calculating the fee for a transaction
|
||||||
// (see GetVirtualTransactionSize)
|
// (see GetVirtualTransactionSize)
|
||||||
max_raw_tx_fee = fr.GetFee((weight+3)/4);
|
max_raw_tx_fee = fr.GetFee((weight+3)/4);
|
||||||
} else if (!request.params[1].isNull()) {
|
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "second argument (maxfeerate) must be numeric");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 txid;
|
uint256 txid;
|
||||||
@@ -900,15 +898,13 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request)
|
|||||||
// TODO: temporary migration code for old clients. Remove in v0.20
|
// TODO: temporary migration code for old clients. Remove in v0.20
|
||||||
if (request.params[1].isBool()) {
|
if (request.params[1].isBool()) {
|
||||||
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.");
|
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.");
|
||||||
} else if (request.params[1].isNum()) {
|
} else if (!request.params[1].isNull()) {
|
||||||
size_t weight = GetTransactionWeight(*tx);
|
size_t weight = GetTransactionWeight(*tx);
|
||||||
CFeeRate fr(AmountFromValue(request.params[1]));
|
CFeeRate fr(AmountFromValue(request.params[1]));
|
||||||
// the +3/4 part rounds the value up, and is the same formula used when
|
// the +3/4 part rounds the value up, and is the same formula used when
|
||||||
// calculating the fee for a transaction
|
// calculating the fee for a transaction
|
||||||
// (see GetVirtualTransactionSize)
|
// (see GetVirtualTransactionSize)
|
||||||
max_raw_tx_fee = fr.GetFee((weight+3)/4);
|
max_raw_tx_fee = fr.GetFee((weight+3)/4);
|
||||||
} else if (!request.params[1].isNull()) {
|
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "second argument (maxfeerate) must be numeric");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue result(UniValue::VARR);
|
UniValue result(UniValue::VARR);
|
||||||
|
|||||||
@@ -446,9 +446,9 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||||||
# and sendrawtransaction should throw
|
# and sendrawtransaction should throw
|
||||||
assert_raises_rpc_error(-26, "absurdly-high-fee", self.nodes[2].sendrawtransaction, rawTxSigned['hex'], 0.00001000)
|
assert_raises_rpc_error(-26, "absurdly-high-fee", self.nodes[2].sendrawtransaction, rawTxSigned['hex'], 0.00001000)
|
||||||
# And below calls should both succeed
|
# And below calls should both succeed
|
||||||
testres = self.nodes[2].testmempoolaccept(rawtxs=[rawTxSigned['hex']], maxfeerate=0.00007000)[0]
|
testres = self.nodes[2].testmempoolaccept(rawtxs=[rawTxSigned['hex']], maxfeerate='0.00007000')[0]
|
||||||
assert_equal(testres['allowed'], True)
|
assert_equal(testres['allowed'], True)
|
||||||
self.nodes[2].sendrawtransaction(hexstring=rawTxSigned['hex'], maxfeerate=0.00007000)
|
self.nodes[2].sendrawtransaction(hexstring=rawTxSigned['hex'], maxfeerate='0.00007000')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user