-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
keys.go
45 lines (34 loc) · 860 Bytes
/
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
package v2
import (
"errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
)
const (
ModuleName = "bank"
)
var (
SupplyKey = []byte{0x00}
BalancesPrefix = []byte{0x02}
DenomMetadataPrefix = []byte{0x1}
ErrInvalidKey = errors.New("invalid key")
)
func CreateAccountBalancesPrefix(addr []byte) []byte {
return append(BalancesPrefix, address.MustLengthPrefix(addr)...)
}
func AddressFromBalancesStore(key []byte) (sdk.AccAddress, error) {
if len(key) == 0 {
return nil, ErrInvalidKey
}
addrLen := key[0]
bound := int(addrLen)
if len(key)-1 < bound {
return nil, ErrInvalidKey
}
return key[1 : bound+1], nil
}
// DenomMetadataKey returns the denomination metadata key.
func DenomMetadataKey(denom string) []byte {
d := []byte(denom)
return append(DenomMetadataPrefix, d...)
}