Skip to content

Commit

Permalink
RPC/Utils: add utility to parse UniValue arg as floating-point double
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Feb 15, 2022
1 parent 57eb2a4 commit 375b0dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/rpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ int ParseInt(const UniValue& o, std::string strKey)
return v.get_int();
}

double ParseDoubleV(const UniValue& v, const std::string &strName)
{
std::string strNum = v.getValStr();
double num;
if (!ParseDouble(strNum, &num))
throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be a be number (not '"+strNum+"')");
return num;
}

bool ParseBool(const UniValue& o, std::string strKey)
{
const UniValue& v = find_value(o, strKey);
Expand Down
1 change: 1 addition & 0 deletions src/rpc/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ extern std::vector<unsigned char> ParseHexV(const UniValue& v, std::string strNa
extern std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey);
extern int ParseInt(const UniValue& o, std::string strKey);
extern bool ParseBool(const UniValue& o, std::string strKey);
extern double ParseDoubleV(const UniValue& v, const std::string &strName);

extern CAmount AmountFromValue(const UniValue& value);
extern UniValue ValueFromAmount(const CAmount& amount);
Expand Down

0 comments on commit 375b0dc

Please sign in to comment.