-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
keeper_keys.go
77 lines (64 loc) · 2.27 KB
/
keeper_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
package gov
import (
"bytes"
"fmt"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Key for getting a the next available proposalID from the store
var (
KeyDelimiter = []byte(":")
KeyNextProposalID = []byte("newProposalID")
PrefixActiveProposalQueue = []byte("activeProposalQueue")
PrefixInactiveProposalQueue = []byte("inactiveProposalQueue")
)
// Key for getting a specific proposal from the store
func KeyProposal(proposalID uint64) []byte {
return []byte(fmt.Sprintf("proposals:%d", proposalID))
}
// Key for getting a specific deposit from the store
func KeyDeposit(proposalID uint64, depositorAddr sdk.AccAddress) []byte {
return []byte(fmt.Sprintf("deposits:%d:%d", proposalID, depositorAddr))
}
// Key for getting a specific vote from the store
func KeyVote(proposalID uint64, voterAddr sdk.AccAddress) []byte {
return []byte(fmt.Sprintf("votes:%d:%d", proposalID, voterAddr))
}
// Key for getting all deposits on a proposal from the store
func KeyDepositsSubspace(proposalID uint64) []byte {
return []byte(fmt.Sprintf("deposits:%d:", proposalID))
}
// Key for getting all votes on a proposal from the store
func KeyVotesSubspace(proposalID uint64) []byte {
return []byte(fmt.Sprintf("votes:%d:", proposalID))
}
// Returns the key for a proposalID in the activeProposalQueue
func PrefixActiveProposalQueueTime(endTime time.Time) []byte {
return bytes.Join([][]byte{
PrefixActiveProposalQueue,
sdk.FormatTimeBytes(endTime),
}, KeyDelimiter)
}
// Returns the key for a proposalID in the activeProposalQueue
func KeyActiveProposalQueueProposal(endTime time.Time, proposalID uint64) []byte {
return bytes.Join([][]byte{
PrefixActiveProposalQueue,
sdk.FormatTimeBytes(endTime),
sdk.Uint64ToBigEndian(proposalID),
}, KeyDelimiter)
}
// Returns the key for a proposalID in the activeProposalQueue
func PrefixInactiveProposalQueueTime(endTime time.Time) []byte {
return bytes.Join([][]byte{
PrefixInactiveProposalQueue,
sdk.FormatTimeBytes(endTime),
}, KeyDelimiter)
}
// Returns the key for a proposalID in the activeProposalQueue
func KeyInactiveProposalQueueProposal(endTime time.Time, proposalID uint64) []byte {
return bytes.Join([][]byte{
PrefixInactiveProposalQueue,
sdk.FormatTimeBytes(endTime),
sdk.Uint64ToBigEndian(proposalID),
}, KeyDelimiter)
}