code.vegaprotocol.io/vega@v0.79.0/core/events/automated_purchase.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 "code.vegaprotocol.io/vega/core/types" 22 "code.vegaprotocol.io/vega/libs/num" 23 eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1" 24 ) 25 26 type AutomatedPurchaseAnnounced struct { 27 *Base 28 From string 29 FromAccountType types.AccountType 30 ToAccountType types.AccountType 31 MarketID string 32 Amount *num.Uint 33 } 34 35 func NewProtocolAutomatedPurchaseAnnouncedEvent(ctx context.Context, from string, fromAccountType types.AccountType, toAccountType types.AccountType, marketID string, amount *num.Uint) *AutomatedPurchaseAnnounced { 36 return &AutomatedPurchaseAnnounced{ 37 Base: newBase(ctx, AutomatedPurchaseAnnouncedEvent), 38 From: from, 39 FromAccountType: fromAccountType, 40 ToAccountType: toAccountType, 41 MarketID: marketID, 42 Amount: amount, 43 } 44 } 45 46 func (ap AutomatedPurchaseAnnounced) Proto() eventspb.AutomatedPurchaseAnnounced { 47 return eventspb.AutomatedPurchaseAnnounced{ 48 From: ap.From, 49 FromAccountType: ap.FromAccountType, 50 ToAccountType: ap.ToAccountType, 51 MarketId: ap.MarketID, 52 Amount: ap.Amount.String(), 53 } 54 } 55 56 func (ap AutomatedPurchaseAnnounced) AutomatedPurchaseAnnouncedEvent() eventspb.AutomatedPurchaseAnnounced { 57 return ap.Proto() 58 } 59 60 func (ap AutomatedPurchaseAnnounced) StreamMessage() *eventspb.BusEvent { 61 p := ap.Proto() 62 busEvent := newBusEventFromBase(ap.Base) 63 busEvent.Event = &eventspb.BusEvent_AutomatedPurchaseAnnounced{ 64 AutomatedPurchaseAnnounced: &p, 65 } 66 67 return busEvent 68 } 69 70 func AutomatedPurchaseAnnouncedFromStream(ctx context.Context, be *eventspb.BusEvent) *AutomatedPurchaseAnnounced { 71 event := be.GetAutomatedPurchaseAnnounced() 72 if event == nil { 73 return nil 74 } 75 76 return &AutomatedPurchaseAnnounced{ 77 Base: newBaseFromBusEvent(ctx, AutomatedPurchaseAnnouncedEvent, be), 78 From: event.From, 79 FromAccountType: event.FromAccountType, 80 ToAccountType: event.ToAccountType, 81 MarketID: event.MarketId, 82 Amount: num.MustUintFromString(event.Amount, 10), 83 } 84 }