Skip to content

Commit 0742c78

Browse files
committed
rpc: enable passing decimals to AmountFromValue, add doxygen
1 parent 8ce3ef5 commit 0742c78

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/rpc/util.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ void RPCTypeCheckObj(const UniValue& o,
7474
}
7575
}
7676

77-
CAmount AmountFromValue(const UniValue& value)
77+
CAmount AmountFromValue(const UniValue& value, int decimals)
7878
{
7979
if (!value.isNum() && !value.isStr())
8080
throw JSONRPCError(RPC_TYPE_ERROR, "Amount is not a number or string");
8181
CAmount amount;
82-
if (!ParseFixedPoint(value.getValStr(), 8, &amount))
82+
if (!ParseFixedPoint(value.getValStr(), decimals, &amount))
8383
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount");
8484
if (!MoneyRange(amount))
8585
throw JSONRPCError(RPC_TYPE_ERROR, "Amount out of range");

src/rpc/util.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,14 @@ extern uint256 ParseHashO(const UniValue& o, std::string strKey);
7777
extern std::vector<unsigned char> ParseHexV(const UniValue& v, std::string strName);
7878
extern std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey);
7979

80-
extern CAmount AmountFromValue(const UniValue& value);
80+
/**
81+
* Validate and return a CAmount from a UniValue number or string.
82+
*
83+
* @param[in] value UniValue number or string to parse.
84+
* @param[in] decimals Number of significant digits (default: 8).
85+
* @returns a CAmount if the various checks pass.
86+
*/
87+
extern CAmount AmountFromValue(const UniValue& value, int decimals = 8);
8188

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

0 commit comments

Comments
 (0)