code.vegaprotocol.io/vega@v0.79.0/core/events/market_updated_event.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  	"fmt"
    21  
    22  	"code.vegaprotocol.io/vega/core/types"
    23  	proto "code.vegaprotocol.io/vega/protos/vega"
    24  	eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1"
    25  )
    26  
    27  type MarketUpdated struct {
    28  	*Base
    29  	pm proto.Market
    30  }
    31  
    32  func NewMarketUpdatedEvent(ctx context.Context, m types.Market) *MarketUpdated {
    33  	pm := m.IntoProto()
    34  	return &MarketUpdated{
    35  		Base: newBase(ctx, MarketUpdatedEvent),
    36  		pm:   *pm,
    37  	}
    38  }
    39  
    40  // MarketEvent -> is needs to be logged as a market event.
    41  func (m MarketUpdated) MarketEvent() string {
    42  	return fmt.Sprintf("Market ID %s updated (%s)", m.pm.Id, m.pm.String())
    43  }
    44  
    45  func (m MarketUpdated) MarketID() string {
    46  	return m.pm.Id
    47  }
    48  
    49  func (m MarketUpdated) Market() proto.Market {
    50  	return m.Proto()
    51  }
    52  
    53  func (m MarketUpdated) Proto() proto.Market {
    54  	return m.pm
    55  }
    56  
    57  func (m MarketUpdated) MarketProto() eventspb.MarketEvent {
    58  	return eventspb.MarketEvent{
    59  		MarketId: m.pm.Id,
    60  		Payload:  m.MarketEvent(),
    61  	}
    62  }
    63  
    64  func (m MarketUpdated) StreamMessage() *eventspb.BusEvent {
    65  	market := m.Proto()
    66  	busEvent := newBusEventFromBase(m.Base)
    67  	busEvent.Event = &eventspb.BusEvent_MarketUpdated{
    68  		MarketUpdated: &market,
    69  	}
    70  
    71  	return busEvent
    72  }
    73  
    74  func (m MarketUpdated) StreamMarketMessage() *eventspb.BusEvent {
    75  	return m.StreamMessage()
    76  }
    77  
    78  func MarketUpdatedEventFromStream(ctx context.Context, be *eventspb.BusEvent) *MarketUpdated {
    79  	m := be.GetMarketUpdated()
    80  	return &MarketUpdated{
    81  		Base: newBaseFromBusEvent(ctx, MarketUpdatedEvent, be),
    82  		pm:   *m,
    83  	}
    84  }