aboutsummaryrefslogtreecommitdiff
path: root/src/rpcserver.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <[email protected]>2015-06-09 18:26:56 +0200
committerWladimir J. van der Laan <[email protected]>2015-06-09 18:38:33 +0200
commit643114f53995c9a662466784953999f073c878ad (patch)
tree8a404dbcf8fa6199b810079be9c9463ca1055b81 /src/rpcserver.cpp
parentMerge pull request #6246 (diff)
parentChanges necessary now that zero values accepted in AmountFromValue (diff)
downloaddiscoin-643114f53995c9a662466784953999f073c878ad.tar.xz
discoin-643114f53995c9a662466784953999f073c878ad.zip
Merge pull request #6239
7d8ffac Changes necessary now that zero values accepted in AmountFromValue (Wladimir J. van der Laan) a04bdef Get rid of fPlus argument to FormatMoney (Wladimir J. van der Laan) 4b4b9a8 Don't go through double in AmountFromValue and ValueFromAmount (Wladimir J. van der Laan)
Diffstat (limited to 'src/rpcserver.cpp')
-rw-r--r--src/rpcserver.cpp21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp
index e6bf00861..3894dd08b 100644
--- a/src/rpcserver.cpp
+++ b/src/rpcserver.cpp
@@ -11,6 +11,7 @@
#include "sync.h"
#include "ui_interface.h"
#include "util.h"
+#include "utilmoneystr.h"
#include "utilstrencodings.h"
#ifdef ENABLE_WALLET
#include "wallet/wallet.h"
@@ -118,25 +119,21 @@ void RPCTypeCheckObj(const UniValue& o,
}
}
-static inline int64_t roundint64(double d)
-{
- return (int64_t)(d > 0 ? d + 0.5 : d - 0.5);
-}
-
CAmount AmountFromValue(const UniValue& value)
{
- double dAmount = value.get_real();
- if (dAmount <= 0.0 || dAmount > 21000000.0)
- throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount");
- CAmount nAmount = roundint64(dAmount * COIN);
- if (!MoneyRange(nAmount))
+ if (!value.isReal() && !value.isNum())
+ throw JSONRPCError(RPC_TYPE_ERROR, "Amount is not a number");
+ CAmount amount;
+ if (!ParseMoney(value.getValStr(), amount))
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount");
- return nAmount;
+ if (!MoneyRange(amount))
+ throw JSONRPCError(RPC_TYPE_ERROR, "Amount out of range");
+ return amount;
}
UniValue ValueFromAmount(const CAmount& amount)
{
- return (double)amount / (double)COIN;
+ return UniValue(UniValue::VREAL, FormatMoney(amount));
}
uint256 ParseHashV(const UniValue& v, string strName)