aboutsummaryrefslogtreecommitdiff
path: root/src/utilstrencodings.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2015-07-06 10:49:24 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2015-07-10 15:43:26 +0200
commit9cc91523dbec6441e327e1e4c83ba751a4680bec (patch)
treef7ad53eeb2e34d7773e067acf2a268076b1078ca /src/utilstrencodings.h
parentd0a10c1959176eb40c0ec47a56de00820c59066d (diff)
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.
Diffstat (limited to 'src/utilstrencodings.h')
-rw-r--r--src/utilstrencodings.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/utilstrencodings.h b/src/utilstrencodings.h
index 58329b51bb..dcd56751f2 100644
--- a/src/utilstrencodings.h
+++ b/src/utilstrencodings.h
@@ -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