github.com/Finschia/finschia-sdk@v0.48.1/x/gov/types/tally.go (about) 1 package types 2 3 import ( 4 yaml "gopkg.in/yaml.v2" 5 6 sdk "github.com/Finschia/finschia-sdk/types" 7 ) 8 9 // ValidatorGovInfo used for tallying 10 type ValidatorGovInfo struct { 11 Address sdk.ValAddress // address of the validator operator 12 BondedTokens sdk.Int // Power of a Validator 13 DelegatorShares sdk.Dec // Total outstanding delegator shares 14 DelegatorDeductions sdk.Dec // 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 sdk.Int, delegatorShares, 20 delegatorDeductions sdk.Dec, 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 sdk.Int) TallyResult { 33 return TallyResult{ 34 Yes: yes, 35 Abstain: abstain, 36 No: no, 37 NoWithVeto: noWithVeto, 38 } 39 } 40 41 // NewTallyResultFromMap creates a new TallyResult instance from a Option -> Dec map 42 func NewTallyResultFromMap(results map[VoteOption]sdk.Dec) 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(sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt()) 54 } 55 56 // Equals returns if two proposals are equal. 57 func (tr TallyResult) Equals(comp TallyResult) bool { 58 return tr.Yes.Equal(comp.Yes) && 59 tr.Abstain.Equal(comp.Abstain) && 60 tr.No.Equal(comp.No) && 61 tr.NoWithVeto.Equal(comp.NoWithVeto) 62 } 63 64 // String implements stringer interface 65 func (tr TallyResult) String() string { 66 out, _ := yaml.Marshal(tr) 67 return string(out) 68 }