-
Notifications
You must be signed in to change notification settings - Fork 36
/
key.go
109 lines (84 loc) · 3.06 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package types
import (
fmt "fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)
const (
ModuleName = "oracle"
StoreKey = ModuleName
// MemStoreKey defines the in-memory store key
MemStoreKey = "mem_capability"
//// Version defines the current version the IBC module supports
//Version = "bandchain-1"
//
//// PortID is the default port id that module binds to
//PortID = "oracle"
)
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}
// Band IBC
BandIBCPriceKey = []byte{0x31}
LatestClientIDKey = []byte{0x32}
BandIBCCallDataRecordKey = []byte{0x33}
BandIBCOracleRequestIDKey = []byte{0x34}
BandIBCParamsKey = []byte{0x35}
LatestRequestIDKey = []byte{0x36}
// Keys for chainlink price prefixes
ChainlinkPriceKey = []byte{0x41}
)
func GetBandPriceStoreKey(symbol string) []byte {
return append(BandPriceKey, []byte(symbol)...)
}
func GetBandRelayerStoreKey(relayer sdk.AccAddress) []byte {
return append(BandRelayerKey, relayer.Bytes()...)
}
func GetBandIBCOracleRequestIDKey(requestID uint64) []byte {
return append(BandIBCOracleRequestIDKey, sdk.Uint64ToBigEndian(requestID)...)
}
func GetBandIBCPriceStoreKey(symbol string) []byte {
return append(BandIBCPriceKey, []byte(symbol)...)
}
func GetBandIBCCallDataRecordKey(clientID uint64) []byte {
return append(BandIBCCallDataRecordKey, sdk.Uint64ToBigEndian(clientID)...)
}
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)...))
}
func GetChainlinkPriceStoreKey(feedId string) []byte {
feedIdBz := getPaddedFeedIdBz(feedId)
buf := make([]byte, 0, len(ChainlinkPriceKey)+len(feedIdBz))
buf = append(buf, ChainlinkPriceKey...)
buf = append(buf, feedIdBz...)
return buf
}
func getPaddedFeedIdBz(feedId string) string {
return fmt.Sprintf("%20s", feedId)
}