pybitcash/bitcash

get_balance() returns string

Closed this issue · 4 comments

PrivateKey().get_balance('bch') returns string '0', instead of float (like key.balance), could be relevant for other APIs.

Or do we expect non float content?

I thought it was supposed to return an int() of Satoshis, but it's been a while.

Float is a bad idea because the precision won't match up correctly.

k.get_balance('satoshi')
'0'
k.get_balance()
'0'

Eg. for non-native currencies like 'usd' behind the scene json returns '0.000122', casting it to float doesn't change the precision 0.000122
There always will be rounding errors for non native currencies, that's expected.
Yeah, float is a bit wasteful for satoshi. We shouldn't mix the return types, either string or float, your call.

I don't think I would mess with it. I think string is okay because you want to handle it in some kind of BCH type anyway. It's not the cleanest approach, maybe passing it as a BCH type would be ideal but I think this has been working okay for some time.

Rounding errors are something I want to avoid because this stuff code is almost entirely used by payment handling. Being off by a Satoshi could make or break a payment, so I would rather be quite strict/literal.

What do you think?

Sounds alright.