-
Notifications
You must be signed in to change notification settings - Fork 368
/
querier.go
98 lines (84 loc) · 2.49 KB
/
querier.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
package types
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Query endpoints supported by the Querier
const (
QueryCommittees = "committees"
QueryCommittee = "committee"
QueryProposals = "proposals"
QueryProposal = "proposal"
QueryNextProposalID = "next-proposal-id"
QueryVotes = "votes"
QueryVote = "vote"
QueryTally = "tally"
QueryRawParams = "raw_params"
)
type QueryCommitteeParams struct {
CommitteeID uint64 `json:"committee_id" yaml:"committee_id"`
}
func NewQueryCommitteeParams(committeeID uint64) QueryCommitteeParams {
return QueryCommitteeParams{
CommitteeID: committeeID,
}
}
type QueryProposalParams struct {
ProposalID uint64 `json:"proposal_id" yaml:"proposal_id"`
}
func NewQueryProposalParams(proposalID uint64) QueryProposalParams {
return QueryProposalParams{
ProposalID: proposalID,
}
}
type QueryVoteParams struct {
ProposalID uint64 `json:"proposal_id" yaml:"proposal_id"`
Voter sdk.AccAddress `json:"voter" yaml:"voter"`
}
func NewQueryVoteParams(proposalID uint64, voter sdk.AccAddress) QueryVoteParams {
return QueryVoteParams{
ProposalID: proposalID,
Voter: voter,
}
}
type QueryRawParamsParams struct {
Subspace string
Key string
}
func NewQueryRawParamsParams(subspace, key string) QueryRawParamsParams {
return QueryRawParamsParams{
Subspace: subspace,
Key: key,
}
}
type ProposalPollingStatus struct {
ProposalID uint64 `json:"proposal_id" yaml:"proposal_id"`
YesVotes sdk.Dec `json:"yes_votes" yaml:"yes_votes"`
CurrentVotes sdk.Dec `json:"current_votes" yaml:"current_votes"`
PossibleVotes sdk.Dec `json:"possible_votes" yaml:"possible_votes"`
VoteThreshold sdk.Dec `json:"vote_threshold" yaml:"vote_threshold"`
Quorum sdk.Dec `json:"quorum" yaml:"quorum"`
}
func NewProposalPollingStatus(proposalID uint64, yesVotes, currentVotes, possibleVotes,
voteThreshold, quorum sdk.Dec) ProposalPollingStatus {
return ProposalPollingStatus{
ProposalID: proposalID,
YesVotes: yesVotes,
CurrentVotes: currentVotes,
PossibleVotes: possibleVotes,
VoteThreshold: voteThreshold,
Quorum: quorum,
}
}
// String implements fmt.Stringer
func (p ProposalPollingStatus) String() string {
return fmt.Sprintf(`Proposal ID: %d
Yes votes: %d
Current votes: %d
Possible votes: %d
Vote threshold: %d
Quorum: %d`,
p.ProposalID, p.YesVotes, p.CurrentVotes,
p.PossibleVotes, p.VoteThreshold, p.Quorum,
)
}