code.vegaprotocol.io/vega@v0.79.0/core/events/validator_score.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/libs/num" 22 eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1" 23 ) 24 25 type ValidatorScore struct { 26 *Base 27 NodeID string 28 EpochSeq string 29 ValidatorScore string 30 NormalisedScore string 31 RawValidatorScore string 32 ValidatorPerformance string 33 MultisigScore string 34 ValidatorStatus string 35 } 36 37 func NewValidatorScore(ctx context.Context, nodeID, epochSeq string, score, normalisedScore, rawValidatorScore, 38 validatorPerformance num.Decimal, multisigScore num.Decimal, validatorStatus string, 39 ) *ValidatorScore { 40 return &ValidatorScore{ 41 Base: newBase(ctx, ValidatorScoreEvent), 42 NodeID: nodeID, 43 EpochSeq: epochSeq, 44 ValidatorScore: score.String(), 45 NormalisedScore: normalisedScore.String(), 46 RawValidatorScore: rawValidatorScore.String(), 47 ValidatorPerformance: validatorPerformance.String(), 48 MultisigScore: multisigScore.String(), 49 ValidatorStatus: validatorStatus, 50 } 51 } 52 53 func (vd ValidatorScore) Proto() eventspb.ValidatorScoreEvent { 54 return eventspb.ValidatorScoreEvent{ 55 NodeId: vd.NodeID, 56 EpochSeq: vd.EpochSeq, 57 ValidatorScore: vd.ValidatorScore, 58 NormalisedScore: vd.NormalisedScore, 59 ValidatorPerformance: vd.ValidatorPerformance, 60 RawValidatorScore: vd.RawValidatorScore, 61 MultisigScore: vd.MultisigScore, 62 ValidatorStatus: vd.ValidatorStatus, 63 } 64 } 65 66 func (vd ValidatorScore) ValidatorScoreEvent() eventspb.ValidatorScoreEvent { 67 return vd.Proto() 68 } 69 70 func (vd ValidatorScore) StreamMessage() *eventspb.BusEvent { 71 p := vd.Proto() 72 busEvent := newBusEventFromBase(vd.Base) 73 busEvent.Event = &eventspb.BusEvent_ValidatorScore{ 74 ValidatorScore: &p, 75 } 76 77 return busEvent 78 } 79 80 func ValidatorScoreEventFromStream(ctx context.Context, be *eventspb.BusEvent) *ValidatorScore { 81 event := be.GetValidatorScore() 82 if event == nil { 83 return nil 84 } 85 86 return &ValidatorScore{ 87 Base: newBaseFromBusEvent(ctx, ValidatorScoreEvent, be), 88 NodeID: event.GetNodeId(), 89 EpochSeq: event.GetEpochSeq(), 90 ValidatorScore: event.ValidatorScore, 91 NormalisedScore: event.NormalisedScore, 92 RawValidatorScore: event.RawValidatorScore, 93 ValidatorPerformance: event.ValidatorPerformance, 94 MultisigScore: event.MultisigScore, 95 ValidatorStatus: event.ValidatorStatus, 96 } 97 }