-
Notifications
You must be signed in to change notification settings - Fork 12
/
metadata.go
68 lines (63 loc) · 1.37 KB
/
metadata.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package types
import (
"fmt"
"strings"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)
func GetFXMetaData(denom string) banktypes.Metadata {
return banktypes.Metadata{
Description: "The native staking token of the Function X",
DenomUnits: []*banktypes.DenomUnit{
{
Denom: denom,
Exponent: 0,
},
},
Base: denom,
Display: denom,
Name: "Function X",
Symbol: denom,
}
}
func GetCrossChainMetadata(name, symbol string, decimals uint32, aliases ...string) banktypes.Metadata {
return banktypes.Metadata{
Description: "The cross chain token of the Function X",
DenomUnits: []*banktypes.DenomUnit{
{
Denom: strings.ToLower(symbol),
Exponent: 0,
Aliases: aliases,
},
{
Denom: symbol,
Exponent: decimals,
},
},
Base: strings.ToLower(symbol),
Display: strings.ToLower(symbol),
Name: name,
Symbol: symbol,
}
}
func ValidateMetadata(md banktypes.Metadata) error {
decimals := uint8(0)
for _, du := range md.DenomUnits {
if du.Denom == md.Symbol {
decimals = uint8(du.Exponent)
break
}
}
if md.Base == DefaultDenom {
decimals = DenomUnit
}
if len(md.Name) == 0 {
return fmt.Errorf("invalid name %s", md.Name)
}
if len(md.Symbol) == 0 {
return fmt.Errorf("invalid symbol %s", md.Symbol)
}
if decimals == 0 {
return fmt.Errorf("invalid decimals %d", decimals)
}
return nil
}