Skip to content

Commit fade94d

Browse files
author
MarcoFalke
committed
rpc: Add ParseFeeRate helper
1 parent fa0ff66 commit fade94d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/rpc/util.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ CAmount AmountFromValue(const UniValue& value, int decimals)
7575
return amount;
7676
}
7777

78+
CFeeRate ParseFeeRate(const UniValue& json)
79+
{
80+
CAmount val{AmountFromValue(json)};
81+
if (val >= COIN) throw JSONRPCError(RPC_INVALID_PARAMETER, "Fee rates larger than or equal to 1BTC/kvB are not accepted");
82+
return CFeeRate{val};
83+
}
84+
7885
uint256 ParseHashV(const UniValue& v, std::string_view name)
7986
{
8087
const std::string& strHex(v.get_str());

src/rpc/util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ std::vector<unsigned char> ParseHexO(const UniValue& o, std::string_view strKey)
103103
* @returns a CAmount if the various checks pass.
104104
*/
105105
CAmount AmountFromValue(const UniValue& value, int decimals = 8);
106+
/**
107+
* Parse a json number or string, denoting BTC/kvB, into a CFeeRate (sat/kvB).
108+
* Reject negative values or rates larger than 1BTC/kvB.
109+
*/
110+
CFeeRate ParseFeeRate(const UniValue& json);
106111

107112
using RPCArgList = std::vector<std::pair<std::string, UniValue>>;
108113
std::string HelpExampleCli(const std::string& methodname, const std::string& args);

0 commit comments

Comments
 (0)