-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
tally.go
61 lines (54 loc) · 2.04 KB
/
tally.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
package v1
import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// ValidatorGovInfo used for tallying
type ValidatorGovInfo struct {
Address sdk.ValAddress // address of the validator operator
BondedTokens math.Int // Power of a Validator
DelegatorShares math.LegacyDec // Total outstanding delegator shares
DelegatorDeductions math.LegacyDec // Delegator deductions from validator's delegators voting independently
Vote WeightedVoteOptions // Vote of the validator
}
// NewValidatorGovInfo creates a ValidatorGovInfo instance
func NewValidatorGovInfo(address sdk.ValAddress, bondedTokens math.Int, delegatorShares,
delegatorDeductions sdk.Dec, options WeightedVoteOptions,
) ValidatorGovInfo {
return ValidatorGovInfo{
Address: address,
BondedTokens: bondedTokens,
DelegatorShares: delegatorShares,
DelegatorDeductions: delegatorDeductions,
Vote: options,
}
}
// NewTallyResult creates a new TallyResult instance
func NewTallyResult(yes, abstain, no, noWithVeto math.Int) TallyResult {
return TallyResult{
YesCount: yes.String(),
AbstainCount: abstain.String(),
NoCount: no.String(),
NoWithVetoCount: noWithVeto.String(),
}
}
// NewTallyResultFromMap creates a new TallyResult instance from a Option -> Dec map
func NewTallyResultFromMap(results map[VoteOption]sdk.Dec) TallyResult {
return NewTallyResult(
results[OptionYes].TruncateInt(),
results[OptionAbstain].TruncateInt(),
results[OptionNo].TruncateInt(),
results[OptionNoWithVeto].TruncateInt(),
)
}
// EmptyTallyResult returns an empty TallyResult.
func EmptyTallyResult() TallyResult {
return NewTallyResult(math.ZeroInt(), math.ZeroInt(), math.ZeroInt(), math.ZeroInt())
}
// Equals returns if two tally results are equal.
func (tr TallyResult) Equals(comp TallyResult) bool {
return tr.YesCount == comp.YesCount &&
tr.AbstainCount == comp.AbstainCount &&
tr.NoCount == comp.NoCount &&
tr.NoWithVetoCount == comp.NoWithVetoCount
}