-
Notifications
You must be signed in to change notification settings - Fork 19
/
governance_vote.go
118 lines (106 loc) · 3.6 KB
/
governance_vote.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright (c) 2022 Gobalsky Labs Limited
//
// Use of this software is governed by the Business Source License included
// in the LICENSE.VEGA file and at https://www.mariadb.com/bsl11.
//
// Change Date: 18 months from the later of the date of the first publicly
// available Distribution of this version of the repository, and 25 June 2022.
//
// On the date above, in accordance with the Business Source License, use
// of this software will be governed by version 3 or later of the GNU General
// Public License.
package types
import (
"fmt"
"code.vegaprotocol.io/vega/libs/num"
vegapb "code.vegaprotocol.io/vega/protos/vega"
commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1"
)
type VoteValue = vegapb.Vote_Value
const (
// VoteValueUnspecified Default value, always invalid.
VoteValueUnspecified VoteValue = vegapb.Vote_VALUE_UNSPECIFIED
// VoteValueNo represents a vote against the proposal.
VoteValueNo VoteValue = vegapb.Vote_VALUE_NO
// VoteValueYes represents a vote in favour of the proposal.
VoteValueYes VoteValue = vegapb.Vote_VALUE_YES
)
type VoteSubmission struct {
// The ID of the proposal to vote for.
ProposalID string
// The actual value of the vote
Value VoteValue
}
func NewVoteSubmissionFromProto(p *commandspb.VoteSubmission) *VoteSubmission {
return &VoteSubmission{
ProposalID: p.ProposalId,
Value: p.Value,
}
}
func (v VoteSubmission) IntoProto() *commandspb.VoteSubmission {
return &commandspb.VoteSubmission{
ProposalId: v.ProposalID,
Value: v.Value,
}
}
func (v VoteSubmission) String() string {
return fmt.Sprintf(
"proposalID(%s) value(%s)",
v.ProposalID,
v.Value.String(),
)
}
// Vote represents a governance vote casted by a party for a given proposal.
type Vote struct {
// PartyID is the party that casted the vote.
PartyID string
// ProposalID is the proposal identifier concerned by the vote.
ProposalID string
// Value is the actual position of the vote: yes or no.
Value VoteValue
// Timestamp is the date and time (in nanoseconds) at which the vote has
// been casted.
Timestamp int64
// TotalGovernanceTokenBalance is the total number of tokens hold by the
// party that casted the vote.
TotalGovernanceTokenBalance *num.Uint
// TotalGovernanceTokenWeight is the weight of the vote compared to the
// total number of governance token.
TotalGovernanceTokenWeight num.Decimal
// TotalEquityLikeShareWeight is the weight of the vote compared to the
// total number of equity-like share on the market.
TotalEquityLikeShareWeight num.Decimal
}
func (v Vote) IntoProto() *vegapb.Vote {
return &vegapb.Vote{
PartyId: v.PartyID,
Value: v.Value,
ProposalId: v.ProposalID,
Timestamp: v.Timestamp,
TotalGovernanceTokenBalance: num.UintToString(v.TotalGovernanceTokenBalance),
TotalGovernanceTokenWeight: v.TotalGovernanceTokenWeight.String(),
TotalEquityLikeShareWeight: v.TotalEquityLikeShareWeight.String(),
}
}
func VoteFromProto(v *vegapb.Vote) (*Vote, error) {
ret := Vote{
PartyID: v.PartyId,
Value: v.Value,
ProposalID: v.ProposalId,
Timestamp: v.Timestamp,
}
if len(v.TotalGovernanceTokenBalance) > 0 {
ret.TotalGovernanceTokenBalance, _ = num.UintFromString(v.TotalGovernanceTokenBalance, 10)
}
if len(v.TotalGovernanceTokenWeight) > 0 {
w, err := num.DecimalFromString(v.TotalGovernanceTokenWeight)
if err != nil {
return nil, err
}
ret.TotalGovernanceTokenWeight = w
}
if len(v.TotalEquityLikeShareWeight) > 0 {
ret.TotalEquityLikeShareWeight, _ = num.DecimalFromString(v.TotalEquityLikeShareWeight)
}
return &ret, nil
}