-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
R4R: tallyResults added to state #1914
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,9 @@ type Proposal interface { | |
GetStatus() ProposalStatus | ||
SetStatus(ProposalStatus) | ||
|
||
GetTallyResult() TallyResult | ||
SetTallyResult(TallyResult) | ||
|
||
GetSubmitBlock() int64 | ||
SetSubmitBlock(int64) | ||
|
||
|
@@ -39,17 +42,18 @@ type Proposal interface { | |
|
||
// checks if two proposals are equal | ||
func ProposalEqual(proposalA Proposal, proposalB Proposal) bool { | ||
if proposalA.GetProposalID() != proposalB.GetProposalID() || | ||
proposalA.GetTitle() != proposalB.GetTitle() || | ||
proposalA.GetDescription() != proposalB.GetDescription() || | ||
proposalA.GetProposalType() != proposalB.GetProposalType() || | ||
proposalA.GetStatus() != proposalB.GetStatus() || | ||
proposalA.GetSubmitBlock() != proposalB.GetSubmitBlock() || | ||
!(proposalA.GetTotalDeposit().IsEqual(proposalB.GetTotalDeposit())) || | ||
proposalA.GetVotingStartBlock() != proposalB.GetVotingStartBlock() { | ||
return false | ||
if proposalA.GetProposalID() == proposalB.GetProposalID() && | ||
proposalA.GetTitle() == proposalB.GetTitle() && | ||
proposalA.GetDescription() == proposalB.GetDescription() && | ||
proposalA.GetProposalType() == proposalB.GetProposalType() && | ||
proposalA.GetStatus() == proposalB.GetStatus() && | ||
TallyResultEqual(proposalA.GetTallyResult(), proposalB.GetTallyResult()) && | ||
proposalA.GetSubmitBlock() == proposalB.GetSubmitBlock() && | ||
proposalA.GetTotalDeposit().IsEqual(proposalB.GetTotalDeposit()) && | ||
proposalA.GetVotingStartBlock() == proposalB.GetVotingStartBlock() { | ||
return true | ||
} | ||
return true | ||
return false | ||
} | ||
|
||
//----------------------------------------------------------- | ||
|
@@ -60,7 +64,8 @@ type TextProposal struct { | |
Description string `json:"description"` // Description of the proposal | ||
ProposalType ProposalKind `json:"proposal_type"` // Type of proposal. Initial set {PlainTextProposal, SoftwareUpgradeProposal} | ||
|
||
Status ProposalStatus `json:"proposal_status"` // Status of the Proposal {Pending, Active, Passed, Rejected} | ||
Status ProposalStatus `json:"proposal_status"` // Status of the Proposal {Pending, Active, Passed, Rejected} | ||
TallyResult TallyResult `json:"tally_result"` // Result of Tallys | ||
|
||
SubmitBlock int64 `json:"submit_block"` // Height of the block where TxGovSubmitProposal was included | ||
TotalDeposit sdk.Coins `json:"total_deposit"` // Current deposit on this proposal. Initial value is set at InitialDeposit | ||
|
@@ -82,6 +87,8 @@ func (tp TextProposal) GetProposalType() ProposalKind { return tp.P | |
func (tp *TextProposal) SetProposalType(proposalType ProposalKind) { tp.ProposalType = proposalType } | ||
func (tp TextProposal) GetStatus() ProposalStatus { return tp.Status } | ||
func (tp *TextProposal) SetStatus(status ProposalStatus) { tp.Status = status } | ||
func (tp TextProposal) GetTallyResult() TallyResult { return tp.TallyResult } | ||
func (tp *TextProposal) SetTallyResult(tallyResult TallyResult) { tp.TallyResult = tallyResult } | ||
func (tp TextProposal) GetSubmitBlock() int64 { return tp.SubmitBlock } | ||
func (tp *TextProposal) SetSubmitBlock(submitBlock int64) { tp.SubmitBlock = submitBlock } | ||
func (tp TextProposal) GetTotalDeposit() sdk.Coins { return tp.TotalDeposit } | ||
|
@@ -286,3 +293,33 @@ func (status ProposalStatus) Format(s fmt.State, verb rune) { | |
s.Write([]byte(fmt.Sprintf("%v", byte(status)))) | ||
} | ||
} | ||
|
||
//----------------------------------------------------------- | ||
// Tally Results | ||
type TallyResult struct { | ||
Yes sdk.Rat `json:"yes"` | ||
Abstain sdk.Rat `json:"abstain"` | ||
No sdk.Rat `json:"no"` | ||
NoWithVeto sdk.Rat `json:"no_with_veto"` | ||
} | ||
|
||
// checks if two proposals are equal | ||
func EmptyTallyResult() TallyResult { | ||
return TallyResult{ | ||
Yes: sdk.ZeroRat(), | ||
Abstain: sdk.ZeroRat(), | ||
No: sdk.ZeroRat(), | ||
NoWithVeto: sdk.ZeroRat(), | ||
} | ||
} | ||
|
||
// checks if two proposals are equal | ||
func TallyResultEqual(resultA TallyResult, resultB TallyResult) bool { | ||
if resultA.Yes.Equal(resultB.Yes) && | ||
resultA.Abstain.Equal(resultB.Yes) && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😱 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed |
||
resultA.No.Equal(resultB.No) && | ||
resultA.NoWithVeto.Equal(resultB.Yes) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed |
||
return true | ||
} | ||
return false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a quick testcase for a non-empty tally result?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in following test,
TestSlashing