Skip to content

Commit 614601b

Browse files
committed
rpc: Accept strings in AmountFromValue
Accept strings containing decimal values, in addition to bare values. Useful from JSON-RPC implementations where it's not possible to have direct control over the text of numbers (e.g. where numbers are always doubles), and it's still desired to send an exact value. This would allow users to post JSON content with numbers encoded like `{"value": "0.00000001"}` instead of `{"value": 0.00000001}` which some php/python encoders wrap into 1e-8, or worse.
1 parent d43297c commit 614601b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/rpcserver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ void RPCTypeCheckObj(const UniValue& o,
120120

121121
CAmount AmountFromValue(const UniValue& value)
122122
{
123-
if (!value.isNum())
124-
throw JSONRPCError(RPC_TYPE_ERROR, "Amount is not a number");
123+
if (!value.isNum() && !value.isStr())
124+
throw JSONRPCError(RPC_TYPE_ERROR, "Amount is not a number or string");
125125
CAmount amount;
126126
if (!ParseFixedPoint(value.getValStr(), 8, &amount))
127127
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount");

0 commit comments

Comments
 (0)