jgarzik / jgarzik/python-bitcoinrpc

decimal.InvalidOperation exception

Offen
#92 1 Kommentar 10 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
663
Forks
300
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

I'm regularly calling `getnetworkhashps(-1)` to keep track of the network's estimated hash power for the current difficulty adjustment period. At the latest difficulty adjustment, around block 566,496 it temporarily peeked at "3.385206289794399E+20". Function `EncodeDecimal` couldn't handle numbers this big, and raised an exception:
```
Traceback (most recent call last):
File "my_btc_test.py", line 19, in
networkhashps = rpc_connection.getnetworkhashps(-1)
File "bitcoinrpc/authproxy.py", line 139, in __call__
response = self._get_response()
File "bitcoinrpc/authproxy.py", line 197, in _get_response
log.debug("<-%s- %s"%(response["id"], json.dumps(response["result"], default=EncodeDecimal)))
File "/usr/lib/python3.5/json/__init__.py", line 237, in dumps
**kw).encode(obj)
File "/usr/lib/python3.5/json/encoder.py", line 198, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python3.5/json/encoder.py", line 256, in iterencode
return _iterencode(o, 0)
File "bitcoinrpc/authproxy.py", line 77, in EncodeDecimal
return float(round(o, 8))
decimal.InvalidOperation: []
```
I've reproduced the error with a simple example. The following code throws the same exception demonstrating the problem:
```
#!/usr/bin/python3
import decimal
o = decimal.Decimal("3.385206289794399E+20")
print(float(round(o, 8)))
```
### A possible solution
Please consider merging @luke-jr's #63, that solves the issue.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Beginne mit bitcoinrpc/authproxy.py und reproduziere das bereitgestellte Decimal-Beispiel über EncodeDecimal. Vergleiche sein Verhalten mit dem Ansatz im referenzierten Issue oder Pull Request #63; als erledigt gilt es, wenn der große Netzwerk-Hash-Wert ohne decimal.InvalidOperation serialisiert werden kann.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
api
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.