cosmos-sdk
cosmos-sdk copied to clipboard
Put `sdk.Coins` functions into core
Latest update
- [ ] As a 1st step, let's only move the format and parse functions into core. https://github.com/cosmos/cosmos-sdk/issues/13155#issuecomment-1238157132. #13306
Original issue below
Summary
Carve sdk.Coin and sdk.Coins out of cosmos/cosmos-sdk, put them in core/coins.
Problem Definition
With ADR-053, we are removing core SDK components out of the root cosmos/cosmos-sdk go module, and putting them into standalone go modules: error, math, store, core etc.
Textual would like to use sdk.Coins in #12708, but because the tx module is standalone, it cannot import sdk.Coins.
Proposal
Carve sdk.Coin and sdk.Coins out of cosmos/cosmos-sdk, put them in core/coins. Add an alias in types/coins.go to point to the carved out coins.
Question: should we add Legacy prefix (similar to #12634)? as they depend on gogoproto
Further Improvements
Maybe in the future, we would migrate to pulsar coins, and use functions instead of methods:
package cossmossdk.io/core/coins
- func (coins Coins) Find(denom string) (bool, Coin) { // gogoproto coins
+ func Find(coins Coins, denom string) (bool, Coin) { // pulsar coins
but let's create another issue for that.
My preference would be to just add the google.golang.org/protobuf Coin functionality into core when we are ready to do that.
I see the need for some coin methods for SIGN_MODE_TEXTUAL, but just using the existing functionality in types I think is actually not correct for textual. In particular, ParseDecCoin depends on the global denom regex which I think is not right for SIGN_MODE_TEXTUAL. This denom regex is a mutable global which to begin with we should get rid of in the same way that we should get rid of the global bech32 config. Secondly, the default denom regex is actually way too restrictive for generic zero-configuration coin parsing. Also, we'll need to allocate sdk.Coins in addition to the proto v2 coins which is just unnecessary overhead for this functionality.
So I actually think we will get a more correct implementation if we just have something custom for SIGN_MODE_TEXTUAL and potentially start using that as the basis for the google.golang.org/protobuf Coin support which we'll need anyway.
This might be a good time to incorporate the fixes contemplated in #11223.
This might be a good time to incorporate the fixes contemplated in #11223.
Yes, please let's get rid of panicking when checking if two coins of different denoms are equal!