Browse Source
util: assert that Decimal precision is sufficient
Just for sanity... e.g. when importing electrum as a python library,
the calling code could have changed the precision.
related: #5223
patch-4
SomberNight
4 years ago
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
1 changed files with
7 additions and
0 deletions
-
electrum/util.py
|
@ -630,6 +630,13 @@ def format_satoshis_plain(x, *, decimal_point=8) -> str: |
|
|
return "{:.8f}".format(Decimal(x) / scale_factor).rstrip('0').rstrip('.') |
|
|
return "{:.8f}".format(Decimal(x) / scale_factor).rstrip('0').rstrip('.') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Check that Decimal precision is sufficient. |
|
|
|
|
|
# We need at the very least ~20, as we deal with msat amounts, and |
|
|
|
|
|
# log10(21_000_000 * 10**8 * 1000) ~= 18.3 |
|
|
|
|
|
# decimal.DefaultContext.prec == 28 by default, but it is mutable. |
|
|
|
|
|
# We enforce that we have at least that available. |
|
|
|
|
|
assert decimal.getcontext().prec >= 28, f"PyDecimal precision too low: {decimal.getcontext().prec}" |
|
|
|
|
|
|
|
|
DECIMAL_POINT = localeconv()['decimal_point'] # type: str |
|
|
DECIMAL_POINT = localeconv()['decimal_point'] # type: str |
|
|
|
|
|
|
|
|
|
|
|
|
|
|