|
11 | 11 | #include "sync.h"
|
12 | 12 | #include "ui_interface.h"
|
13 | 13 | #include "util.h"
|
| 14 | +#include "utilmoneystr.h" |
14 | 15 | #include "utilstrencodings.h"
|
15 | 16 | #ifdef ENABLE_WALLET
|
16 | 17 | #include "wallet/wallet.h"
|
@@ -118,25 +119,21 @@ void RPCTypeCheckObj(const UniValue& o,
|
118 | 119 | }
|
119 | 120 | }
|
120 | 121 |
|
121 |
| -static inline int64_t roundint64(double d) |
122 |
| -{ |
123 |
| - return (int64_t)(d > 0 ? d + 0.5 : d - 0.5); |
124 |
| -} |
125 |
| - |
126 | 122 | CAmount AmountFromValue(const UniValue& value)
|
127 | 123 | {
|
128 |
| - double dAmount = value.get_real(); |
129 |
| - if (dAmount <= 0.0 || dAmount > 21000000.0) |
130 |
| - throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount"); |
131 |
| - CAmount nAmount = roundint64(dAmount * COIN); |
132 |
| - if (!MoneyRange(nAmount)) |
| 124 | + if (!value.isReal() && !value.isNum()) |
| 125 | + throw JSONRPCError(RPC_TYPE_ERROR, "Amount is not a number"); |
| 126 | + CAmount amount; |
| 127 | + if (!ParseMoney(value.getValStr(), amount)) |
133 | 128 | throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount");
|
134 |
| - return nAmount; |
| 129 | + if (!MoneyRange(amount)) |
| 130 | + throw JSONRPCError(RPC_TYPE_ERROR, "Amount out of range"); |
| 131 | + return amount; |
135 | 132 | }
|
136 | 133 |
|
137 | 134 | UniValue ValueFromAmount(const CAmount& amount)
|
138 | 135 | {
|
139 |
| - return (double)amount / (double)COIN; |
| 136 | + return UniValue(UniValue::VREAL, FormatMoney(amount, false)); |
140 | 137 | }
|
141 | 138 |
|
142 | 139 | uint256 ParseHashV(const UniValue& v, string strName)
|
|
0 commit comments