github.com/cosmos/cosmos-sdk@v0.50.10/x/gov/types/v1/tally.go (about) 1 package v1 2 3 import ( 4 "cosmossdk.io/math" 5 6 sdk "github.com/cosmos/cosmos-sdk/types" 7 ) 8 9 // ValidatorGovInfo used for tallying 10 type ValidatorGovInfo struct { 11 Address sdk.ValAddress // address of the validator operator 12 BondedTokens math.Int // Power of a Validator 13 DelegatorShares math.LegacyDec // Total outstanding delegator shares 14 DelegatorDeductions math.LegacyDec // Delegator deductions from validator's delegators voting independently 15 Vote WeightedVoteOptions // Vote of the validator 16 } 17 18 // NewValidatorGovInfo creates a ValidatorGovInfo instance 19 func NewValidatorGovInfo(address sdk.ValAddress, bondedTokens math.Int, delegatorShares, 20 delegatorDeductions math.LegacyDec, options WeightedVoteOptions, 21 ) ValidatorGovInfo { 22 return ValidatorGovInfo{ 23 Address: address, 24 BondedTokens: bondedTokens, 25 DelegatorShares: delegatorShares, 26 DelegatorDeductions: delegatorDeductions, 27 Vote: options, 28 } 29 } 30 31 // NewTallyResult creates a new TallyResult instance 32 func NewTallyResult(yes, abstain, no, noWithVeto math.Int) TallyResult { 33 return TallyResult{ 34 YesCount: yes.String(), 35 AbstainCount: abstain.String(), 36 NoCount: no.String(), 37 NoWithVetoCount: noWithVeto.String(), 38 } 39 } 40 41 // NewTallyResultFromMap creates a new TallyResult instance from a Option -> Dec map 42 func NewTallyResultFromMap(results map[VoteOption]math.LegacyDec) TallyResult { 43 return NewTallyResult( 44 results[OptionYes].TruncateInt(), 45 results[OptionAbstain].TruncateInt(), 46 results[OptionNo].TruncateInt(), 47 results[OptionNoWithVeto].TruncateInt(), 48 ) 49 } 50 51 // EmptyTallyResult returns an empty TallyResult. 52 func EmptyTallyResult() TallyResult { 53 return NewTallyResult(math.ZeroInt(), math.ZeroInt(), math.ZeroInt(), math.ZeroInt()) 54 } 55 56 // Equals returns if two tally results are equal. 57 func (tr TallyResult) Equals(comp TallyResult) bool { 58 return tr.YesCount == comp.YesCount && 59 tr.AbstainCount == comp.AbstainCount && 60 tr.NoCount == comp.NoCount && 61 tr.NoWithVetoCount == comp.NoWithVetoCount 62 }