/
keys.go
100 lines (81 loc) · 3.88 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
package types
import (
"encoding/binary"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
"github.com/ojo-network/ojo/util"
)
const (
// ModuleName is the name of the oracle module
ModuleName = "oracle"
// StoreKey is the string store representation
StoreKey = ModuleName
// RouterKey is the message route
RouterKey = ModuleName
// QuerierRoute is the query router key for the oracle module
QuerierRoute = ModuleName
)
// KVStore key prefixes
var (
KeyPrefixExchangeRate = []byte{0x01} // prefix for each key to a rate
KeyPrefixFeederDelegation = []byte{0x02} // prefix for each key to a feeder delegation
KeyPrefixMissCounter = []byte{0x03} // prefix for each key to a miss counter
KeyPrefixAggregateExchangeRatePrevote = []byte{0x04} // prefix for each key to a aggregate prevote
KeyPrefixAggregateExchangeRateVote = []byte{0x05} // prefix for each key to a aggregate vote
KeyPrefixMedian = []byte{0x06} // prefix for each key to a price median
KeyPrefixMedianDeviation = []byte{0x07} // prefix for each key to a price median standard deviation
KeyPrefixHistoricPrice = []byte{0x08} // prefix for each key to a historic price
KeyPrefixValidatorRewardSet = []byte{0x09} // prefix for each key to a validator reward set
KeyPrefixParamUpdatePlan = []byte{0x10} // prefix for each key to a param update plan
)
// GetExchangeRateKey - stored by *denom*
func GetExchangeRateKey(denom string) (key []byte) {
key = append(key, KeyPrefixExchangeRate...)
key = append(key, []byte(denom)...)
return append(key, 0) // append 0 for null-termination
}
// GetFeederDelegationKey - stored by *Validator* address
func GetFeederDelegationKey(v sdk.ValAddress) (key []byte) {
key = append(key, KeyPrefixFeederDelegation...)
return append(key, address.MustLengthPrefix(v)...)
}
// GetMissCounterKey - stored by *Validator* address
func GetMissCounterKey(v sdk.ValAddress) (key []byte) {
key = append(key, KeyPrefixMissCounter...)
return append(key, address.MustLengthPrefix(v)...)
}
// GetAggregateExchangeRatePrevoteKey - stored by *Validator* address
func GetAggregateExchangeRatePrevoteKey(v sdk.ValAddress) (key []byte) {
key = append(key, KeyPrefixAggregateExchangeRatePrevote...)
return append(key, address.MustLengthPrefix(v)...)
}
// GetAggregateExchangeRateVoteKey - stored by *Validator* address
func GetAggregateExchangeRateVoteKey(v sdk.ValAddress) (key []byte) {
key = append(key, KeyPrefixAggregateExchangeRateVote...)
return append(key, address.MustLengthPrefix(v)...)
}
// KeyMedian - stored by *denom*
func KeyMedian(denom string, blockNum uint64) (key []byte) {
return util.ConcatBytes(0, KeyPrefixMedian, []byte(denom), util.UintWithNullPrefix(blockNum))
}
// KeyMedianDeviation - stored by *denom*
func KeyMedianDeviation(denom string, blockNum uint64) (key []byte) {
return util.ConcatBytes(0, KeyPrefixMedianDeviation, []byte(denom), util.UintWithNullPrefix(blockNum))
}
// KeyHistoricPrice - stored by *denom* and *block*
func KeyHistoricPrice(denom string, blockNum uint64) (key []byte) {
return util.ConcatBytes(0, KeyPrefixHistoricPrice, []byte(denom), util.UintWithNullPrefix(blockNum))
}
// KeyValidatorRewardSet - stored by *block*
func KeyValidatorRewardSet() (key []byte) {
return util.ConcatBytes(0, KeyPrefixValidatorRewardSet)
}
// KeyParamUpdatePlan - stored by *planHeight*
func KeyParamUpdatePlan(planHeight uint64) (key []byte) {
return util.ConcatBytes(0, KeyPrefixParamUpdatePlan, util.UintWithNullPrefix(planHeight))
}
// ParseDenomAndBlockFromKey returns the denom and block contained in the *key*
// that has a uint64 at the end with a null prefix (length 9).
func ParseDenomAndBlockFromKey(key []byte, prefix []byte) (string, uint64) {
return string(key[len(prefix) : len(key)-9]), binary.LittleEndian.Uint64(key[len(key)-8:])
}