BCHSVExplorer broken on one address for balance call
opened this issue · comments
Got another one. I'm looking into it.
File "/usr/local/lib/python3.5/dist-packages/bitsv/network/rates.py", line 639, in satoshi_to_currency_cached
num / Decimal(currency_to_satoshi_cached(1, currency))
TypeError: unsupported operand type(s) for /: 'float' and 'Decimal'
Ok, more complicated than that.
I have one address that gives a float for balance.
https://bchsvexplorer.com/api/addr/1kiawHJA9ewNWwsi4i9WVEmQpcGKZDG6v/balance
64090124.00000001
Do you know a contact for BCHSVExplorer that can take a look at this? Output is supposed to be an integer of Satoshis.
One thing we should maybe do is change:
https://github.com/AustEcon/bitsv/blob/master/bitsv/network/services/bchsvexplorer.py#L47-L50
def get_balance(cls, address):
r = requests.get(cls.MAIN_BALANCE_API.format(address), timeout=DEFAULT_TIMEOUT)
r.raise_for_status() # pragma: no cover
return r.json()
To:
def get_balance(cls, address):
r = requests.get(cls.MAIN_BALANCE_API.format(address), timeout=DEFAULT_TIMEOUT)
r.raise_for_status() # pragma: no cover
return int(r.text)
Makes the error much more intuitive.
Or a workaround for this bug: int(float(r.text)) (ugly, and maybe we shouldn't do it).
Weird...
I don't know... I went to that url just now and it is not showing a float anymore. So they must have a glitch that rarely spits out a float for the balance... ??
If I were force casting to int (your option 2 above) I'd probably go with:
r.json(parse_float=float_str_to_int)
and have a utility function like:
def float_str_to_int(str):
return int(float(str))
I don't have strong opinions on this. Happy if you want to add in either of your above two options to get it to suit your own needs.
I sent another transaction from the wallet and it went away. I heard back from email and they said they'd look into it.
I don't like doing .json() on non-Json objects. Maybe that's a mistake. I do like doing int() because it makes the error much more intuitive. And type restricting upstream APIs seems like a good idea.
This is just such a fluke of a bug that hopefully they will fix it.