rpc: Accept scientific notation for monetary amounts in JSON

Add a function `ParseFixedPoint` that parses numbers according
to the JSON number specification and returns a 64-bit integer.

Then this in `AmountFromValue`, rather than `ParseMoney`.

Also add lots of tests (thanks to @jonasschnelli for some of them).

Fixes issue #6297.
This commit is contained in:
Wladimir J. van der Laan
2015-07-06 10:49:24 +02:00
parent d0a10c1959
commit 9cc91523db
5 changed files with 215 additions and 1 deletions

View File

@@ -109,4 +109,11 @@ bool TimingResistantEqual(const T& a, const T& b)
return accumulator == 0;
}
/** Parse number as fixed point according to JSON number syntax.
* See http://json.org/number.gif
* @returns true on success, false on error.
* @note The result must be in the range (-10^18,10^18), otherwise an overflow error will trigger.
*/
bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out);
#endif // BITCOIN_UTILSTRENCODINGS_H