code.vegaprotocol.io/vega@v0.79.0/core/events/validator_update.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 // ValidatorUpdate ... 25 type ValidatorUpdate struct { 26 *Base 27 nodeID string 28 vegaPubKey string 29 vegaPubKeyIndex uint32 30 ethAddress string 31 tmPubKey string 32 infoURL string 33 country string 34 name string 35 avatarURL string 36 fromEpoch uint64 37 added bool 38 epochSeq uint64 39 } 40 41 func NewValidatorUpdateEvent( 42 ctx context.Context, 43 nodeID string, 44 vegaPubKey string, 45 vegaPubKeyIndex uint32, 46 ethAddress string, 47 tmPubKey string, 48 infoURL string, 49 country string, 50 name string, 51 avatarURL string, 52 fromEpoch uint64, 53 added bool, 54 epochSeq uint64, 55 ) *ValidatorUpdate { 56 return &ValidatorUpdate{ 57 Base: newBase(ctx, ValidatorUpdateEvent), 58 nodeID: nodeID, 59 vegaPubKey: vegaPubKey, 60 vegaPubKeyIndex: vegaPubKeyIndex, 61 ethAddress: ethAddress, 62 tmPubKey: tmPubKey, 63 infoURL: infoURL, 64 country: country, 65 name: name, 66 avatarURL: avatarURL, 67 fromEpoch: fromEpoch, 68 added: added, 69 epochSeq: epochSeq, 70 } 71 } 72 73 // NodeID returns nodes ID. 74 func (vu ValidatorUpdate) NodeID() string { 75 return vu.nodeID 76 } 77 78 // VegaPublicKey returns validator's vega public key. 79 func (vu ValidatorUpdate) VegaPublicKey() string { 80 return vu.vegaPubKey 81 } 82 83 // VegaPublicKey returns validator's vega public key index. 84 func (vu ValidatorUpdate) VegaPublicKeyIndex() uint32 { 85 return vu.vegaPubKeyIndex 86 } 87 88 // EthereumAddress returns validator's ethereum address. 89 func (vu ValidatorUpdate) EthereumAddress() string { 90 return vu.ethAddress 91 } 92 93 // TendermintPublicKey returns Tendermint nodes public key. 94 func (vu ValidatorUpdate) TendermintPublicKey() string { 95 return vu.tmPubKey 96 } 97 98 // InfoURL returns an url with information about validator node. 99 func (vu ValidatorUpdate) InfoURL() string { 100 return vu.infoURL 101 } 102 103 // Country returns country code of node's location. 104 func (vu ValidatorUpdate) Country() string { 105 return vu.country 106 } 107 108 // Name return the name of the validator. 109 func (vu ValidatorUpdate) Name() string { 110 return vu.name 111 } 112 113 // AvatarURL return an URL to the validator avatar for UI purpose. 114 func (vu ValidatorUpdate) AvatarURL() string { 115 return vu.avatarURL 116 } 117 118 func (vu ValidatorUpdate) ValidatorUpdate() eventspb.ValidatorUpdate { 119 return vu.Proto() 120 } 121 122 func (vu ValidatorUpdate) Proto() eventspb.ValidatorUpdate { 123 return eventspb.ValidatorUpdate{ 124 NodeId: vu.nodeID, 125 VegaPubKey: vu.vegaPubKey, 126 VegaPubKeyIndex: vu.vegaPubKeyIndex, 127 EthereumAddress: vu.ethAddress, 128 TmPubKey: vu.tmPubKey, 129 InfoUrl: vu.infoURL, 130 Country: vu.country, 131 Name: vu.name, 132 AvatarUrl: vu.avatarURL, 133 FromEpoch: vu.fromEpoch, 134 Added: vu.added, 135 EpochSeq: vu.epochSeq, 136 } 137 } 138 139 func (vu ValidatorUpdate) StreamMessage() *eventspb.BusEvent { 140 vuproto := vu.Proto() 141 142 busEvent := newBusEventFromBase(vu.Base) 143 busEvent.Event = &eventspb.BusEvent_ValidatorUpdate{ 144 ValidatorUpdate: &vuproto, 145 } 146 147 return busEvent 148 } 149 150 func ValidatorUpdateEventFromStream(ctx context.Context, be *eventspb.BusEvent) *ValidatorUpdate { 151 event := be.GetValidatorUpdate() 152 if event == nil { 153 return nil 154 } 155 156 return &ValidatorUpdate{ 157 Base: newBaseFromBusEvent(ctx, ValidatorUpdateEvent, be), 158 nodeID: event.GetNodeId(), 159 vegaPubKey: event.GetVegaPubKey(), 160 vegaPubKeyIndex: event.GetVegaPubKeyIndex(), 161 ethAddress: event.GetEthereumAddress(), 162 tmPubKey: event.GetTmPubKey(), 163 infoURL: event.GetInfoUrl(), 164 country: event.GetCountry(), 165 name: event.GetName(), 166 avatarURL: event.GetAvatarUrl(), 167 fromEpoch: event.FromEpoch, 168 added: event.Added, 169 epochSeq: event.EpochSeq, 170 } 171 }