-
Notifications
You must be signed in to change notification settings - Fork 36.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rpc: Accept scientific notation for monetary amounts in JSON #6379
Conversation
Tested ACK (reviewed code/tests, ran tests, successfully ran
|
BOOST_CHECK_EQUAL(AmountFromValue(ValueFromString("0.01e-6")), COIN/100000000); | ||
BOOST_CHECK_EQUAL(AmountFromValue(ValueFromString("0.0000000000000000000000000000000000000000000000000000000000000000000000000001e+68")), COIN/100000000); | ||
BOOST_CHECK_EQUAL(AmountFromValue(ValueFromString("10000000000000000000000000000000000000000000000000000000000000000e-64")), COIN); | ||
BOOST_CHECK_EQUAL(AmountFromValue(ValueFromString("10000000000000000000000000000000000000000000000000000000000000000e-64")), COIN); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this a duplicate of the above line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, will remove (or if you have another test to suggest, please do :-).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add some zeroes after the decimal point. you have an excessive number before and and excessive number after, try a test with an excessive number of zeroes both before and after....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done
ut ACK |
ACK (code review and tested, but not exhaustively) |
fa5c962
to
768516e
Compare
@@ -538,3 +538,118 @@ int atoi(const std::string& str) | |||
{ | |||
return atoi(str.c_str()); | |||
} | |||
|
|||
/** Upper bound for mantissa. | |||
* 10^18-1, largest arbitrary decimal that will fit in 64 bit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hypernit: this comment seems inaccurate. There are definitely larger integers that fit in 64 bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's worded somewhat ackwardly: my point is that larger 64-bit signed integers cannot consist of arbitrary combinations of 0-9:
999999999999999999 1^18-1
9223372036854775807 (1<<63)-1 (max)
9999999999999999999 would not fit
Wouldn't be impossible to handle it, but I it would complicate bounds checking and don't see the point in our case.
I'll update the comment.
ACK. Carefully reviewed the code, but didn't test. The included test cases are convincing. |
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 bitcoin#6297.
768516e
to
9cc9152
Compare
9cc9152 rpc: Accept scientific notation for monetary amounts in JSON (Wladimir J. van der Laan)
Add UniValue as subtree Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#6637 - bitcoin/bitcoin#6239 - bitcoin/bitcoin#6379 - bitcoin/bitcoin#6456 - bitcoin/bitcoin#6788
830eadf Solving rpc_fundrawtransaction.py amount rounding issue. (furszy) 6cf9778 ATMP: Do not try to get the inputs in zc tx. (furszy) 38efbb9 sync_blocks: Increase debugging to hunt down mempool_reorg intermittent failure (furszy) dd7855c sync_blocks: check that peer is connected when calling sync_*. (furszy) bc7d542 functional tests, sync_blocks only cleanup. (furszy) 1ae04e7 Fix mempool package tracking edge case (Suhas Daftuar) f4052aa Add test showing bug in mempool packages (furszy) 691749f rpc: Accept scientific notation for monetary amounts in JSON (furszy) b0f9051 Fix removeForReorg to use MedianTimePast (Suhas Daftuar) 92583c6 Don't call removeForReorg if DisconnectTip fails (Suhas Daftuar) bb77808 Track coinbase spends in CTxMemPoolEntry (furszy) f607f18 Change GetPriority calculation. (furszy) ac3c0f1 Remove default arguments for CTxMemPoolEntry() (furszy) 07eae9f Modify variable names for entry height and priority (furszy) 4356b31 Fix bug in mempool_tests unit test (Alex Morcos) f35ebe3 removeForReorg calls once-per-disconnect-> once-per-reorg (furszy) 7f5737f Fix comment in removeForReorg (furszy) 8ad82ca Fix removal of time-locked transactions during reorg (furszy) de74ab3 Move ProcessBlockFound reserveKey to optional. (furszy) Pull request description: More back ports and adaptations over the RPC values parsing and mempool. We need to get closer in this area :) . * bitcoin#6379 * bitcoin#6715 * bitcoin#6915 * bitcoin#7007 * bitcoin#7008 * bitcoin#12643 * bitcoin#18474 * bitcoin#18704 ACKs for top commit: Fuzzbawls: ACK 830eadf random-zebra: ACK 830eadf and merging... Tree-SHA512: 014b31008aaf09ebf838e21da59379a45565df440a77d66a0cd53e824a6d69673d6975d08243a43fb5a7ebd1a35c07d1d07412a87216b42e9d6f17a1c0bc5708
d1d15c8 Fix missing sigverion in main_test.cpp CreateDummyScriptSigWithKey. (furszy) a034daf Rename to PrecomputedTransactionData (furszy) b4b181b Unit test for sighash caching (furszy) 2ef3872 Report non-mandatory script failures correctly. (furszy) 446d340 Precompute sighashes (furszy) dfd24eb Update wallet_txn_close.py test: (furszy) a5170f0 BIP143: Signing logic. (furszy) d2dd547 BIP143: Verification logic. (furszy) dccc3c6 Refactor script validation to observe amounts (furszy) daf044a Reduce unnecessary hashing in signrawtransaction (furszy) Pull request description: Base work for the new transaction digest algorithm for signature verification on PIVX Sapling transactions. Essentially, an implementation of BIP143 + few more good commits that found down the rabbit hole. Back ports: * bitcoin#7276 * bitcoin#7976 * bitcoin#8118 * bitcoin#8149 (only amount validation and SignatureHash commits). * bitcoin#6088 (only the dummy signature one - will be removed once #1663 get merged -). * bitcoin#6379 * bitcoin#8524 Next step over this area (need 1553 merged to be able to push it) is the further specialization of BIP143 into our custom implementation of ZIP143 (with a different digest algorithm definition using our tx data and hash personalization). ACKs for top commit: Fuzzbawls: utACK d1d15c8 random-zebra: ACK d1d15c8 and merging... Tree-SHA512: 7665cccf095c5bce0b18ef7ab8fcf7bede9304993b48f1af9c352c568861dec728d1d68671aab857b73d46567678492c4b97c24644a15f3f29fc4d723b183522
Add a function
ParseFixedPoint
that parses numbers according to the JSON number specification and returns a 64-bit integer.Then use this in
AmountFromValue
, rather thanParseMoney
.Also add lots of tests (thanks to @jonasschnelli for some of them).
Fixes issue #6297.