code.vegaprotocol.io/vega@v0.79.0/core/events/validator_ranking.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 eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1" 22 ) 23 24 type ValidatorRanking struct { 25 *Base 26 NodeID string 27 EpochSeq string 28 StakeScore string 29 PerformanceScore string 30 Ranking string 31 PreviousStatus string 32 Status string 33 TMVotingPower int 34 } 35 36 func NewValidatorRanking(ctx context.Context, epochSeq, nodeID, stakeScore, performanceScore, ranking, previousStatus, status string, votingPower int) *ValidatorRanking { 37 return &ValidatorRanking{ 38 Base: newBase(ctx, ValidatorRankingEvent), 39 NodeID: nodeID, 40 EpochSeq: epochSeq, 41 StakeScore: stakeScore, 42 PerformanceScore: performanceScore, 43 Ranking: ranking, 44 PreviousStatus: previousStatus, 45 Status: status, 46 TMVotingPower: votingPower, 47 } 48 } 49 50 func (vr ValidatorRanking) Proto() eventspb.ValidatorRankingEvent { 51 return eventspb.ValidatorRankingEvent{ 52 NodeId: vr.NodeID, 53 EpochSeq: vr.EpochSeq, 54 StakeScore: vr.StakeScore, 55 PerformanceScore: vr.PerformanceScore, 56 RankingScore: vr.Ranking, 57 PreviousStatus: vr.PreviousStatus, 58 NextStatus: vr.Status, 59 TmVotingPower: uint32(vr.TMVotingPower), 60 } 61 } 62 63 func (vr ValidatorRanking) ValidatorRankingEvent() eventspb.ValidatorRankingEvent { 64 return vr.Proto() 65 } 66 67 func (vr ValidatorRanking) StreamMessage() *eventspb.BusEvent { 68 p := vr.Proto() 69 busEvent := newBusEventFromBase(vr.Base) 70 busEvent.Event = &eventspb.BusEvent_RankingEvent{ 71 RankingEvent: &p, 72 } 73 74 return busEvent 75 } 76 77 func ValidatorRankingEventFromStream(ctx context.Context, be *eventspb.BusEvent) *ValidatorRanking { 78 event := be.GetRankingEvent() 79 if event == nil { 80 return nil 81 } 82 83 return &ValidatorRanking{ 84 Base: newBaseFromBusEvent(ctx, ValidatorRankingEvent, be), 85 NodeID: event.GetNodeId(), 86 EpochSeq: event.GetEpochSeq(), 87 StakeScore: event.GetStakeScore(), 88 PerformanceScore: event.GetPerformanceScore(), 89 Ranking: event.GetRankingScore(), 90 PreviousStatus: event.GetPreviousStatus(), 91 Status: event.GetNextStatus(), 92 TMVotingPower: int(event.GetTmVotingPower()), 93 } 94 }