-
Notifications
You must be signed in to change notification settings - Fork 4
/
key.go
89 lines (68 loc) · 2.73 KB
/
key.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
package types
import (
"encoding/binary"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
// ModuleName is the name of the module
ModuleName = "farm"
// StoreKey to be used when creating the KVStore
StoreKey = ModuleName
// TStoreKey is the string transient store representation
TStoreKey = "transient_" + ModuleName
// RouterKey to be used for routing msgs
RouterKey = ModuleName
// MintFarmingAccount as module account to be used for saving all mint farming tokens
MintFarmingAccount = "mint_farming_account"
// YieldFarmingAccount as module account to be used for saving all yield farming tokens
YieldFarmingAccount = "yield_farming_account"
// QuerierRoute to be used for querier msgs
QuerierRoute = ModuleName
// Byte length of period occupied
PeriodByteArrayLength = 8
)
var (
FarmPoolPrefix = []byte{0x01}
Pool2AddressPrefix = []byte{0x02}
Address2PoolPrefix = []byte{0x03}
PoolsYieldNativeTokenPrefix = []byte{0x04}
PoolHistoricalRewardsPrefix = []byte{0x05}
PoolCurrentRewardsPrefix = []byte{0x06}
)
const (
poolNameFromLockInfoKeyIndex = sdk.AddrLen + 1
)
func GetFarmPoolKey(poolName string) []byte {
return append(FarmPoolPrefix, []byte(poolName)...)
}
func GetAddressInFarmPoolKey(poolName string, addr sdk.AccAddress) []byte {
return append(Pool2AddressPrefix, append([]byte(poolName), addr.Bytes()...)...)
}
func GetLockInfoKey(addr sdk.AccAddress, poolName string) []byte {
return append(Address2PoolPrefix, append(addr.Bytes(), []byte(poolName)...)...)
}
func SplitPoolsYieldNativeTokenKey(keyWithPrefix []byte) (poolName string) {
return string(keyWithPrefix[1:])
}
// GetWhitelistMemberKey builds the key for a available pool name
func GetWhitelistMemberKey(poolName string) []byte {
return append(PoolsYieldNativeTokenPrefix, []byte(poolName)...)
}
// SplitPoolNameFromLockInfoKey splits the pool name out from a LockInfoKey
func SplitPoolNameFromLockInfoKey(lockInfoKey []byte) string {
return string(lockInfoKey[poolNameFromLockInfoKeyIndex:])
}
// GetPoolHistoricalRewardsKey gets the key for a pool's historical reward
func GetPoolHistoricalRewardsKey(poolName string, period uint64) []byte {
b := make([]byte, PeriodByteArrayLength)
binary.LittleEndian.PutUint64(b, period)
return append(PoolHistoricalRewardsPrefix, append([]byte(poolName), b...)...)
}
// GetPoolHistoricalRewardsPrefix gets the prefix key with pool name for a pool's historical rewards
func GetPoolHistoricalRewardsPrefix(poolName string) []byte {
return append(PoolHistoricalRewardsPrefix, []byte(poolName)...)
}
// GetPoolCurrentRewardsKey gets the key for a pool's current period reward
func GetPoolCurrentRewardsKey(poolName string) []byte {
return append(PoolCurrentRewardsPrefix, []byte(poolName)...)
}