/
keys.go
82 lines (67 loc) · 2.79 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
package types
import (
time "time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
)
const (
// ModuleName defines the module name
ModuleName = "liquidfarming"
// StoreKey defines the primary module store key
StoreKey = ModuleName
// RouterKey is the message route key
RouterKey = ModuleName
// QuerierRoute defines the module's query routing key
QuerierRoute = ModuleName
)
// keys for the store prefixes
var (
LastRewardsAuctionEndTimeKey = []byte{0xe1} // key to retrieve the auction end time
LastRewardsAuctionIdKeyPrefix = []byte{0xe2}
LiquidFarmKeyPrefix = []byte{0xe3}
CompoundingRewardsKeyPrefix = []byte{0xe4}
RewardsAuctionKeyPrefix = []byte{0xe5}
BidKeyPrefix = []byte{0xe6}
WinningBidKeyPrefix = []byte{0xe7}
)
// GetLastRewardsAuctionIdKey returns the store key to retrieve the last rewards auction
// by the given pool id.
func GetLastRewardsAuctionIdKey(poolId uint64) []byte {
return append(LastRewardsAuctionIdKeyPrefix, sdk.Uint64ToBigEndian(poolId)...)
}
// GetLiquidFarmKey returns the store key to retrieve the liquid farm object
// by the given pool id.
func GetLiquidFarmKey(poolId uint64) []byte {
return append(LiquidFarmKeyPrefix, sdk.Uint64ToBigEndian(poolId)...)
}
// GetCompoundingRewardsKey returns the store key to retrieve the compounding rewards object
// by the given pool id.
func GetCompoundingRewardsKey(poolId uint64) []byte {
return append(CompoundingRewardsKeyPrefix, sdk.Uint64ToBigEndian(poolId)...)
}
// GetRewardsAuctionKey returns the store key to retrieve the rewards auction object
// by the given pool id and auction id.
func GetRewardsAuctionKey(auctionId, poolId uint64) []byte {
return append(append(RewardsAuctionKeyPrefix, sdk.Uint64ToBigEndian(auctionId)...), sdk.Uint64ToBigEndian(poolId)...)
}
// GetBidKey returns the store key to retrieve the bid object
// by the given pool id and bidder address.
func GetBidKey(poolId uint64, bidder sdk.AccAddress) []byte {
return append(append(BidKeyPrefix, sdk.Uint64ToBigEndian(poolId)...), address.MustLengthPrefix(bidder)...)
}
// GetBidByPoolIdPrefix returns the prefix to iterate all bids
// by the given pool id.
func GetBidByPoolIdPrefix(poolId uint64) []byte {
return append(BidKeyPrefix, sdk.Uint64ToBigEndian(poolId)...)
}
// GetWinningBidKey returns the store key to retrieve the winning bid
// by the given pool id and the auction id.
func GetWinningBidKey(auctionId uint64, poolId uint64) []byte {
return append(append(WinningBidKeyPrefix, sdk.Uint64ToBigEndian(auctionId)...), sdk.Uint64ToBigEndian(poolId)...)
}
// LengthPrefixTimeBytes returns length-prefixed bytes representation
// of time.Time.
func LengthPrefixTimeBytes(t time.Time) []byte {
bz := sdk.FormatTimeBytes(t)
return append([]byte{byte(len(bz))}, bz...)
}