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