-
Notifications
You must be signed in to change notification settings - Fork 0
/
keys.go
39 lines (30 loc) · 912 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
package types
import (
"fmt"
"github.com/gogo/protobuf/proto"
)
const (
ModuleName = "poolmanager"
StoreKey = ModuleName
RouterKey = ModuleName
)
var (
// KeyNextGlobalPoolId defines key to store the next Pool ID to be used.
KeyNextGlobalPoolId = []byte{0x01}
// SwapModuleRouterPrefix defines prefix to store pool id to swap module mappings.
SwapModuleRouterPrefix = []byte{0x02}
)
// ModuleRouteToBytes serializes moduleRoute to bytes.
func FormatModuleRouteKey(poolId uint64) []byte {
return []byte(fmt.Sprintf("%s%d", SwapModuleRouterPrefix, poolId))
}
// ParseModuleRouteFromBz parses the raw bytes into ModuleRoute.
// Returns error if fails to parse or if the bytes are empty.
func ParseModuleRouteFromBz(bz []byte) (ModuleRoute, error) {
moduleRoute := ModuleRoute{}
err := proto.Unmarshal(bz, &moduleRoute)
if err != nil {
return ModuleRoute{}, err
}
return moduleRoute, err
}