jgarzik / jgarzik/python-bitcoinrpc

decimal.InvalidOperation exception

Aperta
#92 1 commento 10 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
663
Fork
300
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Start with bitcoinrpc/authproxy.py and reproduce the provided Decimal example through EncodeDecimal. Compare its behavior with the approach in referenced issue or pull request #63; done means the large network-hash value can be serialized without decimal.InvalidOperation.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
api
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.