Skip to content

Commit

Permalink
Amount Fix
Browse files Browse the repository at this point in the history
Parse 8 decimals and roundint64 without losing value
  • Loading branch information
Oliver Ziegler authored and Oliver Ziegler committed Jan 22, 2019
1 parent 9f1e9a5 commit ca0c7de
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/bitcoin-tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,10 @@ static CAmount AmountFromValue(const UniValue& value)
{
if (!value.isNum() && !value.isStr())
throw runtime_error("Amount is not a number or string");
double dAmount = value.get_real();
if (dAmount <= 0.0 || dAmount > MAX_MONEY)
CAmount amount;
if (!ParseFixedPoint(value.getValStr(), 8, &amount))
throw runtime_error("Invalid amount");
CAmount amount = roundint64(dAmount * COIN);
amount = roundint64(amount * COIN);
if (!MoneyRange(amount))
throw runtime_error("Amount out of range");
return amount;
Expand Down
6 changes: 3 additions & 3 deletions src/rpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ CAmount AmountFromValue(const UniValue& value)
{
if (!value.isNum() && !value.isStr())
throw JSONRPCError(RPC_TYPE_ERROR, "Amount is not a number or string");
double dAmount = value.get_real();
if (dAmount <= 0.0 || dAmount > MAX_MONEY)
CAmount amount;
if (!ParseFixedPoint(value.getValStr(), 8, &amount))
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount");
CAmount amount = roundint64(dAmount * COIN);
amount = roundint64(amount * COIN);
if (!MoneyRange(amount))
throw JSONRPCError(RPC_TYPE_ERROR, "Amount out of range");
return amount;
Expand Down

0 comments on commit ca0c7de

Please sign in to comment.