/
keys.go
88 lines (70 loc) · 2.08 KB
/
keys.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
// ModuleName is the name of the module
ModuleName = "mt"
// StoreKey is the default store key for MT
StoreKey = ModuleName
// QuerierRoute is the querier route for the MT store.
QuerierRoute = ModuleName
// RouterKey is the message route for the MT module
RouterKey = ModuleName
// KeyNextDenomSequence is the key used to store the next denom sequence in the keeper
KeyNextDenomSequence = "nextDenomSequence"
// KeyNextMTSequence is the key used to store the next MT sequence in the keeper
KeyNextMTSequence = "nextMTSequence"
)
var (
PrefixDenom = []byte{0x01}
PrefixMT = []byte{0x02}
PrefixBalance = []byte{0x03}
PrefixSupply = []byte{0x04}
Delimiter = []byte("/")
)
// KeyDenom gets the storeKey by the denom
func KeyDenom(id string) []byte {
key := append(PrefixDenom, Delimiter...)
return append(key, []byte(id)...)
}
// KeyMT gets the key of MT stored by an denom and MT
func KeyMT(denomID, mtID string) []byte {
key := append(PrefixMT, Delimiter...)
if len(denomID) > 0 {
key = append(key, []byte(denomID)...)
key = append(key, Delimiter...)
}
if len(denomID) > 0 && len(mtID) > 0 {
key = append(key, []byte(mtID)...)
}
return key
}
// KeyBalance gets the key of a balance owned by an account address
func KeyBalance(address sdk.AccAddress, denomID, mtID string) []byte {
key := append(PrefixBalance, Delimiter...)
if address != nil {
key = append(key, []byte(address.String())...)
key = append(key, Delimiter...)
}
if address != nil && len(denomID) > 0 {
key = append(key, []byte(denomID)...)
key = append(key, Delimiter...)
}
if address != nil && len(denomID) > 0 && len(mtID) > 0 {
key = append(key, []byte(mtID)...)
}
return key
}
// KeySupply gets the key of supply of a denom or MT
func KeySupply(denomID, mtID string) []byte {
key := append(PrefixSupply, Delimiter...)
if len(denomID) > 0 {
key = append(key, []byte(denomID)...)
key = append(key, Delimiter...)
}
if len(denomID) > 0 && len(mtID) > 0 {
key = append(key, []byte(mtID)...)
}
return key
}