mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
rpc: Validate maxfeerate with AmountFromValue
This commit is contained in:
@@ -1090,15 +1090,13 @@ static UniValue sendrawtransaction(const JSONRPCRequest& request)
|
||||
// TODO: temporary migration code for old clients. Remove in v0.20
|
||||
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.");
|
||||
} else if (request.params[1].isNum()) {
|
||||
} else if (!request.params[1].isNull()) {
|
||||
size_t weight = GetTransactionWeight(*tx);
|
||||
CFeeRate fr(AmountFromValue(request.params[1]));
|
||||
// the +3/4 part rounds the value up, and is the same formula used when
|
||||
// calculating the fee for a transaction
|
||||
// (see GetVirtualTransactionSize)
|
||||
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;
|
||||
@@ -1172,15 +1170,13 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request)
|
||||
// TODO: temporary migration code for old clients. Remove in v0.20
|
||||
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.");
|
||||
} else if (request.params[1].isNum()) {
|
||||
} else if (!request.params[1].isNull()) {
|
||||
size_t weight = GetTransactionWeight(*tx);
|
||||
CFeeRate fr(AmountFromValue(request.params[1]));
|
||||
// the +3/4 part rounds the value up, and is the same formula used when
|
||||
// calculating the fee for a transaction
|
||||
// (see GetVirtualTransactionSize)
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user