-
Notifications
You must be signed in to change notification settings - Fork 38.7k
rpc: Accept strings in AmountFromValue #6380
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
Conversation
|
Context? Zero explanation of "why" |
|
Useful from JSON-RPC implementations where it's not possible to have direct control over the text of numbers (e.g. where numbers are always doubles), and it's still desired to send an exact value. |
|
See also #3759 for previous discussion - I hadn't thought any more context was necessary here. |
|
@laanwj Someone looking at the git commit will have no idea about any of that background context... Commit messages should answer "why?" not just "what?" |
|
Ok, don't feel like this discussion, closing... |
|
Hmm.. i think this is useful. This would allow users to post JSON content with encoded numbers like |
|
@jonasschnelli Yes, that's exactly the idea. |
70aba6f to
5a63648
Compare
|
As a reminder, the conclusion from #3759 was to use satoshi/integer Numbers, not to stringify... |
|
@luke-jr But that would be a major API change, while this could be used today and does not introduce any 1 satoshi versus 1 BTC magnitude risk. |
|
I think using Nevertheless this PR would also be a slightly API change. In the current releases (before UniValue) and in the current master, numbers encapsulated in string did made bitcoind throwing an exception. UniValue internally stores everything as a string, that's why i think this PR makes sense and can be seen as a save solution. The only risk i see is that it could be possible that API users/apps expect that sending a string where a btc value is required should throw an error. |
|
I like this pull as well. We fixed the JSON parsing in #6379 , but what's to say somebody won't be dealing with a broken JSON composer on their end. This provides a nice safe alternative. ACK |
|
ACK. Thanks for updating the commit. |
|
ACK. We shouldn't forget to mention this in release notes if it gets merged. |
|
Yes, and needs to be exercised at least once in the RPC tests as well. |
|
Tested ACK. |
|
Cherry-picked @jonasschnelli 's test. Thanks! |
Accept strings containing decimal values, in addition to bare values.
Useful from JSON-RPC implementations where it's not possible to have
direct control over the text of numbers (e.g. where numbers are always
doubles), and it's still desired to send an exact value.
This would allow users to post JSON content with numbers encoded like
`{"value": "0.00000001"}` instead of `{"value": 0.00000001}` which some
php/python encoders wrap into 1e-8, or worse.
Add a section "low level RPC API changes" so that the changes with regard to error codes can be added later.
145f12e to
9127e97
Compare
|
Added small mention in release notes. |
|
reACK |
Avoid an infinite loop in encoding, by ensuring EncodeDecimal returns a string. round(Decimal) used to convert it to float, but it no longer does in python 3.x. Strings are supported since bitcoin#6380, so just use that.
Bitcoin 0.12 RPC PRs 1 Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#6266 - bitcoin/bitcoin#6257 - bitcoin/bitcoin#6271 - bitcoin/bitcoin#6158 - bitcoin/bitcoin#6307 - bitcoin/bitcoin#6290 - bitcoin/bitcoin#6262 - bitcoin/bitcoin#6088 - bitcoin/bitcoin#6339 - bitcoin/bitcoin#6299 (partial, remainder in #2099) - bitcoin/bitcoin#6350 - bitcoin/bitcoin#6247 - bitcoin/bitcoin#6362 - bitcoin/bitcoin#5486 - bitcoin/bitcoin#6417 - bitcoin/bitcoin#6398 (partial, remainder was included in #1950) - bitcoin/bitcoin#6444 - bitcoin/bitcoin#6456 (partial, remainder was included in #2082) - bitcoin/bitcoin#6380 - bitcoin/bitcoin#6970 Part of #2074.
Accept strings containing decimal values, in addition to bare values.
note: untested