code.vegaprotocol.io/vega@v0.79.0/core/events/oracle_data.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 vegapb "code.vegaprotocol.io/vega/protos/vega" 22 datapb "code.vegaprotocol.io/vega/protos/vega/data/v1" 23 eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1" 24 ) 25 26 type OracleData struct { 27 *Base 28 o vegapb.OracleData 29 } 30 31 func NewOracleDataEvent(ctx context.Context, spec vegapb.OracleData) *OracleData { 32 cpy := &datapb.Data{} 33 if spec.ExternalData != nil { 34 if spec.ExternalData.Data != nil { 35 cpy = spec.ExternalData.Data.DeepClone() 36 } 37 } 38 39 return &OracleData{ 40 Base: newBase(ctx, OracleDataEvent), 41 o: vegapb.OracleData{ExternalData: &datapb.ExternalData{Data: cpy}}, 42 } 43 } 44 45 func (o *OracleData) OracleData() vegapb.OracleData { 46 data := vegapb.OracleData{ 47 ExternalData: &datapb.ExternalData{ 48 Data: &datapb.Data{}, 49 }, 50 } 51 if o.o.ExternalData != nil { 52 if o.o.ExternalData.Data != nil { 53 data.ExternalData.Data = o.o.ExternalData.Data.DeepClone() 54 } 55 } 56 return data 57 } 58 59 func (o OracleData) Proto() vegapb.OracleData { 60 return o.o 61 } 62 63 func (o OracleData) StreamMessage() *eventspb.BusEvent { 64 spec := o.o 65 66 busEvent := newBusEventFromBase(o.Base) 67 busEvent.Event = &eventspb.BusEvent_OracleData{ 68 OracleData: &spec, 69 } 70 71 return busEvent 72 } 73 74 func OracleDataEventFromStream(ctx context.Context, be *eventspb.BusEvent) *OracleData { 75 return &OracleData{ 76 Base: newBaseFromBusEvent(ctx, OracleDataEvent, be), 77 o: *be.GetOracleData(), 78 } 79 }