-
Notifications
You must be signed in to change notification settings - Fork 337
/
keys.go
61 lines (48 loc) · 2.05 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
package types
import (
"encoding/binary"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
// ModuleName The name that will be used throughout the module
ModuleName = "incentive"
// StoreKey Top level store key where all module items will be stored
StoreKey = ModuleName
// RouterKey Top level router key
RouterKey = ModuleName
// DefaultParamspace default name for parameter store
DefaultParamspace = ModuleName
// QuerierRoute route used for abci queries
QuerierRoute = ModuleName
)
// Key Prefixes
var (
RewardPeriodKeyPrefix = []byte{0x01} // prefix for keys that store reward periods
ClaimPeriodKeyPrefix = []byte{0x02} // prefix for keys that store claim periods
ClaimKeyPrefix = []byte{0x03} // prefix for keys that store claims
NextClaimPeriodIDPrefix = []byte{0x04} // prefix for keys that store the next ID for claims periods
PreviousBlockTimeKey = []byte{0x05} // prefix for key that stores the previous blocktime
)
// Keys
// 0x00:CollateralType <> RewardPeriod the current active reward period (max 1 reward period per collateral type)
// 0x01:CollateralType:ID <> ClaimPeriod object for that ID, indexed by collateral type and ID
// 0x02:CollateralType:ID:Owner <> Claim object, indexed by collateral type, ID and owner
// 0x03:CollateralType <> NextClaimPeriodIDPrefix the ID of the next claim period, indexed by collateral type
// BytesToUint64 returns uint64 format from a byte array
func BytesToUint64(bz []byte) uint64 {
return binary.BigEndian.Uint64(bz)
}
// GetClaimPeriodPrefix returns the key (collateral type + id) for a claim prefix
func GetClaimPeriodPrefix(collateralType string, id uint64) []byte {
return createKey([]byte(collateralType), sdk.Uint64ToBigEndian(id))
}
// GetClaimPrefix returns the key (collateral type + id + address) for a claim
func GetClaimPrefix(addr sdk.AccAddress, collateralType string, id uint64) []byte {
return createKey([]byte(collateralType), sdk.Uint64ToBigEndian(id), addr)
}
func createKey(bytes ...[]byte) (r []byte) {
for _, b := range bytes {
r = append(r, b...)
}
return
}