-
Notifications
You must be signed in to change notification settings - Fork 47
/
keys.go
104 lines (74 loc) · 2.35 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package types
import (
"encoding/binary"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
// ModuleName defines the module name
ModuleName = "masterchef"
// StoreKey defines the primary module store key
StoreKey = ModuleName
// RouterKey defines the module's message routing key
RouterKey = ModuleName
// MemStoreKey defines the in-memory store key
MemStoreKey = "mem_masterchef"
ParamsKey = "ParamsKey"
PoolInfoKeyPrefix = "PoolInfo"
ExternalIncentiveIndexKeyPrefix = "IndexExternalIncentive"
ExternalIncentiveKeyPrefix = "ExternalIncentive"
PoolRewardInfoKeyPrefix = "PoolRewardInfo"
UserRewardInfoKeyPrefix = "UserRewardInfo"
PoolRewardsAccumKeyPrefix = "PoolRewardsAccum"
)
func KeyPrefix(p string) []byte {
return []byte(p)
}
func PoolInfoKey(poolId uint64) []byte {
var key []byte
poolIdBytes := make([]byte, 8)
binary.BigEndian.PutUint64(poolIdBytes, poolId)
key = append(key, poolIdBytes...)
key = append(key, []byte("/")...)
return key
}
func ExternalIncentiveKey(incentiveId uint64) []byte {
var key []byte
incentiveIdBytes := make([]byte, 8)
binary.BigEndian.PutUint64(incentiveIdBytes, incentiveId)
key = append(key, incentiveIdBytes...)
key = append(key, []byte("/")...)
return key
}
func ExternalIncentiveIndex() []byte {
var key []byte
key = append(key, ExternalIncentiveIndexKeyPrefix...)
return key
}
func PoolRewardInfoKey(poolId uint64, rewardDenom string) []byte {
var key []byte
poolIdBytes := make([]byte, 8)
binary.BigEndian.PutUint64(poolIdBytes, poolId)
key = append(key, poolIdBytes...)
key = append(key, []byte("/")...)
key = append(key, rewardDenom...)
key = append(key, []byte("/")...)
return key
}
func UserRewardInfoKey(user string, poolId uint64, rewardDenom string) []byte {
var key []byte
key = append(key, user...)
key = append(key, []byte("/")...)
poolIdBytes := make([]byte, 8)
binary.BigEndian.PutUint64(poolIdBytes, poolId)
key = append(key, poolIdBytes...)
key = append(key, []byte("/")...)
key = append(key, rewardDenom...)
key = append(key, []byte("/")...)
return key
}
func GetPoolRewardsAccumPrefix(poolId uint64) []byte {
return append([]byte(PoolRewardsAccumKeyPrefix), sdk.Uint64ToBigEndian(uint64(poolId))...)
}
func GetPoolRewardsAccumKey(poolId uint64, timestamp uint64) []byte {
return append(GetPoolRewardsAccumPrefix(poolId), sdk.Uint64ToBigEndian(timestamp)...)
}