Skip to content
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

SP-943 Python SDK should handle scientific notation #111

Merged
merged 2 commits into from
May 20, 2024

Conversation

bobbrodie
Copy link
Contributor

@bobbrodie bobbrodie commented May 16, 2024

Overview

As reported by DorskFR on #110, we can sometimes have values for paymentTotals.* and paymentSubtotals.* can come back as scientific notation, for example:

...
"paymentSubtotals": {
  "BTC": 1394587,
  "BCH": 200349400,
  "ETH": 298189000000000000,
  "GUSD": 86000,
  "PAX": 860000000000000000000,
  "BUSD": 860000000000000000000,
  "USDC": 860000000,
  "DOGE": 586597875600,
  "LTC": 1089539700,
  "MATIC": 1.321044547e+21,
  "USDC_m": 860000000,
  "USDT": 860410000,
  "USDT_m": 860410000,
  "PYUSD": 860000000,
  "USDCn_m": 860000000
}
...

Scientific notation values such as 1.321044547e+21 while uncommon are valid in JSON per ECMA-404:

A number is a sequence of decimal digits with no superfluous leading zero. It may have a preceding minus
sign (U+002D). It may have a fractional part prefixed by a decimal point (U+002E). It may have an exponent,
prefixed by e (U+0065) or E (U+0045) and optionally + (U+002B) or – (U+002D). The digits are the code
points U+0030 through U+0039.

The number 1.321044547e+21 is valid Python as well, however it is too large for an int, so we need to define these fields as a Decimal type from the decimal library.

Changes

  • Import the decimal library
  • Use the Decimal type instead of int

Notes

Testing shows that this is not required for 5.0.x as these were being defined as None.

@bobbrodie bobbrodie linked an issue May 16, 2024 that may be closed by this pull request
@bobbrodie bobbrodie merged commit 3c798de into bitpay:6.0.x May 20, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

paymentSubtotals type / scientific notation in Invoice
2 participants