-
Notifications
You must be signed in to change notification settings - Fork 38
/
key.go
62 lines (48 loc) · 1.76 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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)
const (
ModuleName = "oracle"
StoreKey = ModuleName
)
var (
// Keys for band store prefixes
BandPriceKey = []byte{0x01}
BandRelayerKey = []byte{0x02}
// Keys for pricefeeder store prefixes
PricefeedInfoKey = []byte{0x11}
PricefeedPriceKey = []byte{0x12}
PricefeedRelayerKey = []byte{0x13}
CoinbasePriceKey = []byte{0x21}
)
func GetBandPriceStoreKey(symbol string) []byte {
return append(BandPriceKey, []byte(symbol)...)
}
func GetBandRelayerStoreKey(relayer sdk.AccAddress) []byte {
return append(BandRelayerKey, relayer.Bytes()...)
}
func GetBaseQuoteHash(oracleBase, oracleQuote string) common.Hash {
return crypto.Keccak256Hash([]byte(oracleBase + oracleQuote))
}
func GetPriceFeedInfoKey(priceFeedInfo *PriceFeedInfo) []byte {
return append(PricefeedInfoKey, GetBaseQuoteHash(priceFeedInfo.Base, priceFeedInfo.Quote).Bytes()...)
}
func GetPriceFeedPriceStoreKey(baseQuoteHash common.Hash) []byte {
return append(PricefeedPriceKey, baseQuoteHash.Bytes()...)
}
func GetPricefeedRelayerStoreKey(oracleBase, oracleQuote string, relayer sdk.AccAddress) []byte {
return append(GetPricefeedRelayerStorePrefix(GetBaseQuoteHash(oracleBase, oracleQuote)), relayer.Bytes()...)
}
func GetPricefeedRelayerStorePrefix(baseQuoteHash common.Hash) []byte {
return append(PricefeedRelayerKey, baseQuoteHash.Bytes()...)
}
func GetCoinbasePriceStoreKey(key string, timestamp uint64) []byte {
timeKey := sdk.Uint64ToBigEndian(timestamp)
return append(append(CoinbasePriceKey, []byte(key)...), timeKey...)
}
func GetCoinbasePriceStoreIterationKey(key string) []byte {
return append(append(CoinbasePriceKey, []byte(key)...))
}