code.vegaprotocol.io/vega@v0.79.0/core/events/protocol_upgrade.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 ProtocolUpgradeProposalEvent struct {
    25  	*Base
    26  	UpgradeBlockHeight uint64
    27  	VegaReleaseTag     string
    28  	AcceptedBy         []string
    29  	ProposalStatus     eventspb.ProtocolUpgradeProposalStatus
    30  }
    31  
    32  func NewProtocolUpgradeProposalEvent(ctx context.Context, upgradeBlockHeight uint64, vegaReleaseTag string, acceptedBy []string, status eventspb.ProtocolUpgradeProposalStatus) *ProtocolUpgradeProposalEvent {
    33  	return &ProtocolUpgradeProposalEvent{
    34  		Base:               newBase(ctx, ProtocolUpgradeEvent),
    35  		UpgradeBlockHeight: upgradeBlockHeight,
    36  		VegaReleaseTag:     vegaReleaseTag,
    37  		AcceptedBy:         acceptedBy,
    38  		ProposalStatus:     status,
    39  	}
    40  }
    41  
    42  func (pup ProtocolUpgradeProposalEvent) Proto() eventspb.ProtocolUpgradeEvent {
    43  	return eventspb.ProtocolUpgradeEvent{
    44  		VegaReleaseTag:     pup.VegaReleaseTag,
    45  		UpgradeBlockHeight: pup.UpgradeBlockHeight,
    46  		Approvers:          pup.AcceptedBy,
    47  		Status:             pup.ProposalStatus,
    48  	}
    49  }
    50  
    51  func (pup ProtocolUpgradeProposalEvent) ProtocolUpgradeProposalEvent() eventspb.ProtocolUpgradeEvent {
    52  	return pup.Proto()
    53  }
    54  
    55  func (pup ProtocolUpgradeProposalEvent) StreamMessage() *eventspb.BusEvent {
    56  	p := pup.Proto()
    57  	busEvent := newBusEventFromBase(pup.Base)
    58  	busEvent.Event = &eventspb.BusEvent_ProtocolUpgradeEvent{
    59  		ProtocolUpgradeEvent: &p,
    60  	}
    61  
    62  	return busEvent
    63  }
    64  
    65  func ProtocolUpgradeProposalEventFromStream(ctx context.Context, be *eventspb.BusEvent) *ProtocolUpgradeProposalEvent {
    66  	event := be.GetProtocolUpgradeEvent()
    67  	if event == nil {
    68  		return nil
    69  	}
    70  
    71  	return &ProtocolUpgradeProposalEvent{
    72  		Base:               newBaseFromBusEvent(ctx, ProtocolUpgradeEvent, be),
    73  		UpgradeBlockHeight: event.UpgradeBlockHeight,
    74  		VegaReleaseTag:     event.VegaReleaseTag,
    75  		AcceptedBy:         event.Approvers,
    76  		ProposalStatus:     event.Status,
    77  	}
    78  }