Skip to content
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

bank: name and symbol metadata fields #8677

Merged
merged 7 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* (x/bank) [\#8614](https://github.com/cosmos/cosmos-sdk/issues/8614) Add `Name` and `Symbol` fields to denom metadata
* (x/auth) [\#8522](https://github.com/cosmos/cosmos-sdk/pull/8522) Allow to query all stored accounts
* (crypto/types) [\#8600](https://github.com/cosmos/cosmos-sdk/pull/8600) `CompactBitArray`: optimize the `NumTrueBitsBefore` method and add an `Equal` method.

Expand Down
2 changes: 2 additions & 0 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,8 @@ a basic token.
| `denom_units` | [DenomUnit](#cosmos.bank.v1beta1.DenomUnit) | repeated | denom_units represents the list of DenomUnit's for a given coin |
| `base` | [string](#string) | | base represents the base denom (should be the DenomUnit with exponent = 0). |
| `display` | [string](#string) | | display indicates the suggested denom that should be displayed in clients. |
| `name` | [string](#string) | | name defines the name of the token (eg: Cosmos Atom) |
| `symbol` | [string](#string) | | symbol is the token symbol usually shown on exchanges (eg: ATOM). This can be the same as the display. |



Expand Down
5 changes: 5 additions & 0 deletions proto/cosmos/bank/v1beta1/bank.proto
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,9 @@ message Metadata {
// display indicates the suggested denom that should be
// displayed in clients.
string display = 4;
// name defines the name of the token (eg: Cosmos Atom)
string name = 5;
// symbol is the token symbol usually shown on exchanges (eg: ATOM). This can
// be the same as the display.
string symbol = 6;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need symbol? Can you give an example where symbol is not display upper/lower-cased?

Copy link
Collaborator Author

@fedekunze fedekunze Feb 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jtremback thoughts here? I'm fine with either tbh

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTC vs Bitcoin, ETH vs Ether, etc.

}
10 changes: 10 additions & 0 deletions x/bank/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func (s *IntegrationTestSuite) SetupSuite() {

bankGenesis.DenomMetadata = []types.Metadata{
{
Name: "Cosmos Hub Atom",
Symbol: "ATOM",
Description: "The native staking token of the Cosmos Hub.",
DenomUnits: []*types.DenomUnit{
{
Expand All @@ -57,6 +59,8 @@ func (s *IntegrationTestSuite) SetupSuite() {
Display: "atom",
},
{
Name: "Ethereum",
Symbol: "ETH",
Description: "Ethereum mainnet token",
DenomUnits: []*types.DenomUnit{
{
Expand Down Expand Up @@ -246,6 +250,8 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDenomsMetadata() {
expected: &types.QueryDenomsMetadataResponse{
Metadatas: []types.Metadata{
{
Name: "Cosmos Hub Atom",
Symbol: "ATOM",
Description: "The native staking token of the Cosmos Hub.",
DenomUnits: []*types.DenomUnit{
{
Expand All @@ -263,6 +269,8 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDenomsMetadata() {
Display: "atom",
},
{
Name: "Ethereum",
Symbol: "ETH",
Description: "Ethereum mainnet token",
DenomUnits: []*types.DenomUnit{
{
Expand Down Expand Up @@ -293,6 +301,8 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDenomsMetadata() {
respType: &types.QueryDenomMetadataResponse{},
expected: &types.QueryDenomMetadataResponse{
Metadata: types.Metadata{
Name: "Cosmos Hub Atom",
Symbol: "ATOM",
Description: "The native staking token of the Cosmos Hub.",
DenomUnits: []*types.DenomUnit{
{
Expand Down
4 changes: 4 additions & 0 deletions x/bank/client/rest/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ func (s *IntegrationTestSuite) TestDenomMetadataGRPCHandler() {
&types.QueryDenomsMetadataResponse{
Metadatas: []types.Metadata{
{
Name: "Cosmos Hub Atom",
Symbol: "ATOM",
Description: "The native staking token of the Cosmos Hub.",
DenomUnits: []*types.DenomUnit{
{
Expand Down Expand Up @@ -151,6 +153,8 @@ func (s *IntegrationTestSuite) TestDenomMetadataGRPCHandler() {
&types.QueryDenomMetadataResponse{},
&types.QueryDenomMetadataResponse{
Metadata: types.Metadata{
Name: "Cosmos Hub Atom",
Symbol: "ATOM",
Description: "The native staking token of the Cosmos Hub.",
DenomUnits: []*types.DenomUnit{
{
Expand Down
2 changes: 2 additions & 0 deletions x/bank/client/rest/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func (s *IntegrationTestSuite) SetupSuite() {

bankGenesis.DenomMetadata = []types.Metadata{
{
Name: "Cosmos Hub Atom",
Symbol: "ATOM",
Description: "The native staking token of the Cosmos Hub.",
DenomUnits: []*types.DenomUnit{
{
Expand Down
4 changes: 4 additions & 0 deletions x/bank/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,8 @@ func (suite *IntegrationTestSuite) TestIterateAllDenomMetaData() {

func (suite *IntegrationTestSuite) getTestMetadata() []types.Metadata {
return []types.Metadata{{
Name: "Cosmos Hub Atom",
Symbol: "ATOM",
Description: "The native staking token of the Cosmos Hub.",
DenomUnits: []*types.DenomUnit{
{"uatom", uint32(0), []string{"microatom"}},
Expand All @@ -1014,6 +1016,8 @@ func (suite *IntegrationTestSuite) getTestMetadata() []types.Metadata {
Display: "atom",
},
{
Name: "Token",
Symbol: "TOKEN",
Description: "The native staking token of the Token Hub.",
DenomUnits: []*types.DenomUnit{
{"1token", uint32(5), []string{"decitoken"}},
Expand Down
180 changes: 143 additions & 37 deletions x/bank/types/bank.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions x/bank/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func TestGenesisStateValidate(t *testing.T) {
Supply: sdk.Coins{sdk.NewInt64Coin("uatom", 1)},
DenomMetadata: []Metadata{
{
Name: "Cosmos Hub Atom",
Symbol: "ATOM",
Description: "The native staking token of the Cosmos Hub.",
DenomUnits: []*DenomUnit{
{"uatom", uint32(0), []string{"microatom"}},
Expand Down Expand Up @@ -85,6 +87,8 @@ func TestGenesisStateValidate(t *testing.T) {
GenesisState{
DenomMetadata: []Metadata{
{
Name: "Cosmos Hub Atom",
Symbol: "ATOM",
Description: "The native staking token of the Cosmos Hub.",
DenomUnits: []*DenomUnit{
{"uatom", uint32(0), []string{"microatom"}},
Expand All @@ -95,6 +99,8 @@ func TestGenesisStateValidate(t *testing.T) {
Display: "atom",
},
{
Name: "Cosmos Hub Atom",
Symbol: "ATOM",
Description: "The native staking token of the Cosmos Hub.",
DenomUnits: []*DenomUnit{
{"uatom", uint32(0), []string{"microatom"}},
Expand All @@ -113,6 +119,8 @@ func TestGenesisStateValidate(t *testing.T) {
GenesisState{
DenomMetadata: []Metadata{
{
Name: "Cosmos Hub Atom",
Symbol: "ATOM",
Description: "The native staking token of the Cosmos Hub.",
DenomUnits: []*DenomUnit{
{"uatom", uint32(0), []string{"microatom"}},
Expand Down
9 changes: 9 additions & 0 deletions x/bank/types/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,21 @@ import (
)

// Validate performs a basic validation of the coin metadata fields. It checks:
// - Name and Symbol are not blank
// - Base and Display denominations are valid coin denominations
// - Base and Display denominations are present in the DenomUnit slice
// - Base denomination has exponent 0
// - Denomination units are sorted in ascending order
// - Denomination units not duplicated
func (m Metadata) Validate() error {
if strings.TrimSpace(m.Name) == "" {
return errors.New("name field cannot be blank")
}

if strings.TrimSpace(m.Symbol) == "" {
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
return errors.New("symbol field cannot be blank")
}

if err := sdk.ValidateDenom(m.Base); err != nil {
return fmt.Errorf("invalid metadata base denom: %w", err)
}
Expand Down
Loading