Closed bofeng closed 2 years ago
Hi @bofeng
I will be working on improving the SDK to support bigint
rather then num
in the coming weeks.
In the meantime, if you need the feature urgently, feel free to fork the repo and make the changes locally. The SDK uses json_serializable
, so in theory it should be easy to just change int
to bigint
and rebuild using dart run build_runner build --delete-conflicting-outputs
.
I will try to add support asap.
Thanks for opening this issue.
I see, sounds great, thank you very much 👍
I am glad you opened this issue @bofeng
To give my two cents I got around this quickly by changing the asset_parameters_model.dart and asset_parameters_model.g.dart and using num
for the total (this is pretty hack but I just needed a quick fix). BigInt
continued to throw errors unfortunately.
As a continuous effort to keep the sdk up to date, the 2.0.0-dev
prereleases will be used to update the sdk to add better support for big integers and might result into small breaking changes.
2.0.0-dev1
contains a fix for this issue.
When the asset has a big number in its
total
field (like USDC, 2^64-1):And after dart parse this json with
jsonDecode
, the "total" field will be treated as "double" not int, because "int" is not big enough to save this number. ((and the value weirdly become "18446744073709552000.0"). Then this json will be passed to theAssetParametersFromJson
constructor here:https://github.com/RootSoft/algorand-dart/blob/75833b3275686f4531c4aeac0db4c81a78ef1515/lib/src/models/assets/asset_parameters_model.g.dart#L13
this line
total: json['total'] as int
will throw an exception:To solve it, I think could either change the type of total in
AssetParameters
class from "int" to "num", or maybe "BigInt" (probably better) , sototal
could be initialized asBigInt.from(json['total'])
(this will actually change the double 18446744073709552000.0 to 18446744073709551616, so to make it accurate, may need something liketotal > 18446744073709551615 ? 18446744073709551615 : total
).Also kudos to this repo, I really like it, thank you! great work!!! 👍