code.vegaprotocol.io/vega@v0.79.0/core/events/ethereum_key_rotation.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 // EthereumKeyRotation ... 25 type EthereumKeyRotation struct { 26 *Base 27 NodeID string 28 OldAddr string 29 NewAddr string 30 BlockHeight uint64 31 } 32 33 func NewEthereumKeyRotationEvent( 34 ctx context.Context, 35 nodeID string, 36 oldAddr string, 37 newAddr string, 38 blockHeight uint64, 39 ) *EthereumKeyRotation { 40 return &EthereumKeyRotation{ 41 Base: newBase(ctx, EthereumKeyRotationEvent), 42 NodeID: nodeID, 43 OldAddr: oldAddr, 44 NewAddr: newAddr, 45 BlockHeight: blockHeight, 46 } 47 } 48 49 func (kr EthereumKeyRotation) EthereumKeyRotation() eventspb.EthereumKeyRotation { 50 return kr.Proto() 51 } 52 53 func (kr EthereumKeyRotation) Proto() eventspb.EthereumKeyRotation { 54 return eventspb.EthereumKeyRotation{ 55 NodeId: kr.NodeID, 56 OldAddress: kr.OldAddr, 57 NewAddress: kr.NewAddr, 58 BlockHeight: kr.BlockHeight, 59 } 60 } 61 62 func (kr EthereumKeyRotation) StreamMessage() *eventspb.BusEvent { 63 krproto := kr.Proto() 64 65 busEvent := newBusEventFromBase(kr.Base) 66 busEvent.Event = &eventspb.BusEvent_EthereumKeyRotation{ 67 EthereumKeyRotation: &krproto, 68 } 69 return busEvent 70 } 71 72 func EthereumKeyRotationEventFromStream(ctx context.Context, be *eventspb.BusEvent) *EthereumKeyRotation { 73 event := be.GetEthereumKeyRotation() 74 if event == nil { 75 return nil 76 } 77 78 return &EthereumKeyRotation{ 79 Base: newBaseFromBusEvent(ctx, EthereumKeyRotationEvent, be), 80 NodeID: event.GetNodeId(), 81 OldAddr: event.GetOldAddress(), 82 NewAddr: event.GetNewAddress(), 83 BlockHeight: event.GetBlockHeight(), 84 } 85 }