forked from dymensionxyz/dymension
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rollapp): validate rollapp token metadata (dymensionxyz#471)
- Loading branch information
1 parent
248650a
commit 4168eb0
Showing
9 changed files
with
399 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
) | ||
|
||
// Validate performs a basic validation of the coin metadata fields. | ||
// Inherits from x/bank metadata and following same spec of x/bank/types/metadata.go | ||
func (m *TokenMetadata) Validate() error { | ||
if m == nil { | ||
return fmt.Errorf("token metadata cannot be nil") | ||
} | ||
|
||
bankMetadata := m.ConvertToBankMetadata() | ||
return bankMetadata.Validate() | ||
} | ||
|
||
// ConvertToBankMetadata converts TokenMetadata to Metadata of x/bank/types | ||
func (m *TokenMetadata) ConvertToBankMetadata() banktypes.Metadata { | ||
var denomUnits []*banktypes.DenomUnit | ||
|
||
for _, denomUnit := range m.DenomUnits { | ||
denomUnits = append(denomUnits, &banktypes.DenomUnit{ | ||
Denom: denomUnit.Denom, | ||
Exponent: denomUnit.Exponent, | ||
Aliases: denomUnit.Aliases, | ||
}) | ||
} | ||
|
||
return banktypes.Metadata{ | ||
Description: m.Description, | ||
DenomUnits: denomUnits, | ||
Base: m.Base, | ||
Display: m.Display, | ||
Name: m.Name, | ||
Symbol: m.Symbol, | ||
URI: m.URI, | ||
URIHash: m.URIHash, | ||
} | ||
} |
Oops, something went wrong.