-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: use cosmos sdk Int type for balances/token amounts #679
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Looks good.
A few nits on the zero int, but that's it!
Also, thinking we should probably backport this. |
I agree, we will definitely want to port this across the supported versions that we maintain. This is going to break things for anyone using |
That's a good call out. FWIW, I made |
* refactor: use csdk Int type for balances/token amounts * chore: use ZeroInt func (cherry picked from commit 8e02aef) # Conflicts: # chain/cosmos/cosmos_chain.go # chain/polkadot/parachain_node.go # chain/polkadot/polkadot_chain.go # chain/polkadot/query.go # chain/polkadot/relay_chain_node.go # chain/polkadot/tx.go # conformance/flush.go # conformance/test.go # examples/cosmos/light_client_test.go # examples/hyperspace/hyperspace_test.go # examples/ibc/interchain_accounts_test.go # examples/ibc/learn_ibc_test.go # examples/ibc/packet_forward_test.go # examples/ibc/wasm/wasm_ibc_test.go # examples/ibc/wasm/wasm_icq_test.go # examples/polkadot/polkadot_chain_test.go # examples/polkadot/push_wasm_client_code_test.go # go.mod # ibc/types.go # interchain_test.go # internal/blockdb/messages_view_test.go # test_user.go
* refactor: use csdk Int type for balances/token amounts * chore: use ZeroInt func (cherry picked from commit 8e02aef) # Conflicts: # chain/cosmos/cosmos_chain.go # chain/polkadot/parachain_node.go # chain/polkadot/polkadot_chain.go # chain/polkadot/query.go # chain/polkadot/relay_chain_node.go # chain/polkadot/tx.go # conformance/flush.go # conformance/test.go # examples/cosmos/light_client_test.go # examples/hyperspace/hyperspace_test.go # examples/ibc/interchain_accounts_test.go # examples/ibc/learn_ibc_test.go # examples/ibc/packet_forward_test.go # examples/ibc/wasm/wasm_ibc_test.go # examples/ibc/wasm/wasm_icq_test.go # examples/polkadot/polkadot_chain_test.go # examples/polkadot/push_wasm_client_code_test.go # go.mod # ibc/types.go # interchain_test.go # internal/blockdb/messages_view_test.go # test_user.go
* refactor: use csdk Int type for balances/token amounts * chore: use ZeroInt func (cherry picked from commit 8e02aef) # Conflicts: # chain/polkadot/query.go # conformance/flush.go # conformance/test.go # examples/cosmos/light_client_test.go # examples/hyperspace/hyperspace_test.go # examples/ibc/interchain_accounts_test.go # examples/ibc/learn_ibc_test.go # examples/ibc/packet_forward_test.go # examples/ibc/wasm/wasm_ibc_test.go # examples/ibc/wasm/wasm_icq_test.go # examples/polkadot/polkadot_chain_test.go # examples/polkadot/push_wasm_client_code_test.go # go.mod # ibc/types.go # interchain_test.go # internal/blockdb/messages_view_test.go # test_user.go
* refactor: use csdk Int type for balances/token amounts * chore: use ZeroInt func (cherry picked from commit 8e02aef) # Conflicts: # chain/polkadot/query.go # conformance/flush.go # conformance/test.go # examples/cosmos/light_client_test.go # examples/hyperspace/hyperspace_test.go # examples/ibc/interchain_accounts_test.go # examples/ibc/learn_ibc_test.go # examples/ibc/packet_forward_test.go # examples/ibc/wasm/wasm_ibc_test.go # examples/ibc/wasm/wasm_icq_test.go # examples/polkadot/polkadot_chain_test.go # examples/polkadot/push_wasm_client_code_test.go # go.mod # ibc/types.go # interchain_test.go # internal/blockdb/messages_view_test.go # test_user.go
Previously we were using
int64
to represent token amounts for things like transfers and balance checks. This becomes problematic when dealing with the EVM or chains like Penumbra where we may need to handleint128
orint256
.Since Go does not have native support for integer values larger than 64-bits we would need to use the stdlib's big package. The Cosmos SDK's math package contains its own Int type that is a wrapper around Go's
big.Int
and offers useful helper methods and enforces a 257 bit range by checking overflow, underflow and division by zero.