janezpodhostnik / flow-py-sdk

Unofficial flow blockchain python sdk
MIT License
35 stars 26 forks source link

UFix64 does not use Decimal #28

Open uhbif19 opened 2 years ago

uhbif19 commented 2 years ago

UFix64 works like this:

In [7]: cadence.UFix64(1).encode()
Out[7]: {'type': 'UFix64', 'value': '0.00000001'}

This is binding library API to details of Flow (that UFix64 uses 8 decimals ) and is error-prone (thats why JSON-Cadence stores UFix64 as strings: https://docs.onflow.org/cadence/json-cadence-spec/#fixed-point-numbers).

If propose this API:

In [17]: UFix64(Decimal('123.4')).encode()
Out[17]: {'type': 'UFix64', 'value': '123.4'}```

If that change is okay, I can make a PR.

janezpodhostnik commented 2 years ago

That is a good point. I did not notice.

A PR would be wonderful, thank you very much!