code.vegaprotocol.io/vega@v0.79.0/core/events/vote.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package events 17 18 import ( 19 "context" 20 21 "code.vegaprotocol.io/vega/core/types" 22 proto "code.vegaprotocol.io/vega/protos/vega" 23 eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1" 24 ) 25 26 type Vote struct { 27 *Base 28 v proto.Vote 29 } 30 31 func NewVoteEvent(ctx context.Context, v types.Vote) *Vote { 32 return &Vote{ 33 Base: newBase(ctx, VoteEvent), 34 v: *v.IntoProto(), 35 } 36 } 37 38 // Vote get the vote object. 39 func (v *Vote) Vote() proto.Vote { 40 return v.v 41 } 42 43 // ProposalID get the proposal ID, part of the interface for event subscribers. 44 func (v *Vote) ProposalID() string { 45 return v.v.ProposalId 46 } 47 48 // IsParty - used in event stream API filter. 49 func (v Vote) IsParty(id string) bool { 50 return v.v.PartyId == id 51 } 52 53 // PartyID - return the PartyID for subscribers' convenience. 54 func (v *Vote) PartyID() string { 55 return v.v.PartyId 56 } 57 58 // Value - return a Y/N value, makes subscribers easier to implement. 59 func (v *Vote) Value() proto.Vote_Value { 60 return v.v.Value 61 } 62 63 // TotalGovernanceTokenBalance returns the total balance of token used for this 64 // vote. 65 func (v *Vote) TotalGovernanceTokenBalance() string { 66 return v.v.TotalGovernanceTokenBalance 67 } 68 69 // TotalGovernanceTokenWeight returns the total weight of token used for this 70 // vote. 71 func (v *Vote) TotalGovernanceTokenWeight() string { 72 return v.v.TotalGovernanceTokenWeight 73 } 74 75 func (v Vote) Proto() proto.Vote { 76 return v.v 77 } 78 79 func (v Vote) StreamMessage() *eventspb.BusEvent { 80 busEvent := newBusEventFromBase(v.Base) 81 busEvent.Event = &eventspb.BusEvent_Vote{ 82 Vote: &v.v, 83 } 84 85 return busEvent 86 } 87 88 func VoteEventFromStream(ctx context.Context, be *eventspb.BusEvent) *Vote { 89 return &Vote{ 90 Base: newBaseFromBusEvent(ctx, VoteEvent, be), 91 v: *be.GetVote(), 92 } 93 }