Amount parser is too strict #7331

issue luke-jr opened this issue on January 12, 2016
  1. luke-jr commented at 10:13 PM on January 12, 2016: member

    {"mvjWntqo6nos9XuskZPyvnWUqR69SqAJsh": 5.4750000000000005, "mugHAcC484RLgqNS8hr1aBk7fhMMaFxuUY": 5.495}

    JSONRPC error: Invalid amount

    Many JSON serialisers do not give people the freedom to choose exact precision of Numbers.

  2. pstratem commented at 10:19 PM on January 12, 2016: contributor

    Disagree, this is dealing with money.

    Precision is important.

  3. MarcoFalke commented at 10:41 PM on January 12, 2016: member

    There seems to be some disagreement within the code:

  4. MarcoFalke commented at 10:43 PM on January 12, 2016: member

    I think we already had this and the workaround was to use strings. Still, something needs to be done to solve this issue.

  5. jonasschnelli commented at 8:12 AM on January 13, 2016: contributor

    I agree with @pstratem.

    The parser is not affected IMO. You probably mean the client side JSON encoder. Because bitcoind RPCs input structures are relatively simple, you could - in case of problematic rounding/percicions - easily write your one JSON encoding.

    A solution to this "problem" would be to change every monetary amount to int32 satoshis. But to do this, it would require a v2/ RPC API, which is a overkill IMO.

  6. MarcoFalke commented at 8:34 AM on January 13, 2016: member

    @jonasschnelli You can represent every valid amount of bitcoins as a double. In case the exact representation is not possible, you can get back the original amount by rounding. There will never be an issue up to 21e6. I think the first off-by-one satoshi rounding error is somewhere in the order of 60e6.

    I see no reason to drop support for floating point. Especially given that the documentation indicates that rounding was intended and probably working in earlier versions of core. Can someone test this with 0.9, etc?

  7. laanwj commented at 9:51 AM on January 13, 2016: member

    We've explicitly decided not to use rounding in the parser. Amounts that cannot be represented in our number format (.8 decimal fixed point) are rejected. So 0.12000000000000000000 is ok, but 0.12000000000000000001 is rejected. See the

    tests:https://github.com/bitcoin/bitcoin/blob/master/src/test/util_tests.cpp#L424

    (and yes, you can pass strings if your JSON formatter refuses to generate decimals of the correct precision - see #6380). Possibly the documentation needs to be updated, but IMO rounding is not acceptable when dealing with money.

  8. MarcoFalke commented at 10:31 AM on January 13, 2016: member

    @laanwj So the documentation needs an update?

  9. laanwj commented at 10:32 AM on January 13, 2016: member

    Yes

  10. laanwj closed this on Jan 13, 2016

  11. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me