From 84d1d5fd6f8f76fe52421ce97e581cac9f66765a Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Mon, 6 Jul 2015 11:43:56 +0200 Subject: [PATCH] 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. --- src/rpcserver.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index d10e14302..137a431fc 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -123,8 +123,8 @@ void RPCTypeCheckObj(const UniValue& o, CAmount AmountFromValue(const UniValue& value) { - if (!value.isNum()) - throw JSONRPCError(RPC_TYPE_ERROR, "Amount is not a number"); + if (!value.isNum() && !value.isStr()) + throw JSONRPCError(RPC_TYPE_ERROR, "Amount is not a number or string"); CAmount amount; if (!ParseFixedPoint(value.getValStr(), 8, &amount)) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount");