univalue: Avoid unnecessary roundtrip through double for numbers
JSON makes no distinction between numbers and reals, and our code doesn't need to do so either. This removes VREAL, as well as its specific post-processing in `UniValue::write`. Non-monetary amounts do not need to be forcibly formatted with 8 decimals, so the extra roundtrip was unnecessary (and potentially loses precision). Zcash: cherry-picked from commit 7650449a6777710cf818d41862626164da0cd412 Dropped changes to qa/rpc-tests/rest.py pending addition of /rest/headers/
This commit is contained in:
parent
d5bf1afae9
commit
2aee461930
|
@ -123,7 +123,7 @@ void RPCTypeCheckObj(const UniValue& o,
|
|||
|
||||
CAmount AmountFromValue(const UniValue& value)
|
||||
{
|
||||
if (!value.isReal() && !value.isNum())
|
||||
if (!value.isNum())
|
||||
throw JSONRPCError(RPC_TYPE_ERROR, "Amount is not a number");
|
||||
CAmount amount;
|
||||
if (!ParseFixedPoint(value.getValStr(), 8, &amount))
|
||||
|
|
|
@ -49,7 +49,7 @@ BOOST_AUTO_TEST_CASE(univalue_constructor)
|
|||
|
||||
double vd = -7.21;
|
||||
UniValue v7(vd);
|
||||
BOOST_CHECK(v7.isReal());
|
||||
BOOST_CHECK(v7.isNum());
|
||||
BOOST_CHECK_EQUAL(v7.getValStr(), "-7.21");
|
||||
|
||||
string vs("yawn");
|
||||
|
@ -127,7 +127,7 @@ BOOST_AUTO_TEST_CASE(univalue_set)
|
|||
BOOST_CHECK_EQUAL(v.getValStr(), "zum");
|
||||
|
||||
BOOST_CHECK(v.setFloat(-1.01));
|
||||
BOOST_CHECK(v.isReal());
|
||||
BOOST_CHECK(v.isNum());
|
||||
BOOST_CHECK_EQUAL(v.getValStr(), "-1.01");
|
||||
|
||||
BOOST_CHECK(v.setInt((int)1023));
|
||||
|
@ -272,7 +272,7 @@ BOOST_AUTO_TEST_CASE(univalue_object)
|
|||
objTypes["distance"] = UniValue::VNUM;
|
||||
objTypes["time"] = UniValue::VNUM;
|
||||
objTypes["calories"] = UniValue::VNUM;
|
||||
objTypes["temperature"] = UniValue::VREAL;
|
||||
objTypes["temperature"] = UniValue::VNUM;
|
||||
objTypes["cat1"] = UniValue::VNUM;
|
||||
objTypes["cat2"] = UniValue::VNUM;
|
||||
BOOST_CHECK(obj.checkObject(objTypes));
|
||||
|
|
Loading…
Reference in New Issue