/
proposal.go
47 lines (41 loc) · 1.28 KB
/
proposal.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
package types
func NewPublicKeysChangeProposal(
id uint64,
creator string,
modifications PubkeysChangeProposalPayload,
startTS int64,
) PublicKeysChangeProposal {
return PublicKeysChangeProposal{
Id: id,
Creator: creator,
Modifications: modifications,
StartTS: startTS,
Status: ProposalStatus_PROPOSAL_STATUS_ACTIVE,
}
}
func (proposal *PublicKeysChangeProposal) IsExpired(blockTime int64) bool {
diff := blockTime - proposal.StartTS
return diff > MaxValidProposalSeconds
}
func (proposal *PublicKeysChangeProposal) DecideResult(keyvault *KeyVault) ProposalResult {
var yesCount, noCount int64
for _, v := range proposal.Votes {
switch v.Vote {
case ProposalVote_PROPOSAL_VOTE_YES:
yesCount++
case ProposalVote_PROPOSAL_VOTE_NO:
noCount++
}
}
// minimum accepted count of yes votes (note vote) for the decision.
majorityCount := keyvault.MajorityCount()
// check if minimum majority vote count is met or not
if noCount >= majorityCount {
return ProposalResult_PROPOSAL_RESULT_REJECTED
} else if yesCount > majorityCount {
return ProposalResult_PROPOSAL_RESULT_APPROVED
}
// else if the yes and no votes counts are equal and we can not make decision for
// result of the proposal
return ProposalResult_PROPOSAL_RESULT_UNSPECIFIED
}