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