code.vegaprotocol.io/vega@v0.79.0/core/events/transfer.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 TransferFunds struct { 27 *Base 28 transfer *eventspb.Transfer 29 } 30 31 func NewGovTransferFundsEvent( 32 ctx context.Context, 33 t *types.GovernanceTransfer, 34 amount *num.Uint, 35 gameID *string, 36 ) *TransferFunds { 37 return &TransferFunds{ 38 Base: newBase(ctx, TransferEvent), 39 transfer: t.IntoEvent(amount, nil, gameID), 40 } 41 } 42 43 func NewGovTransferFundsEventWithReason( 44 ctx context.Context, 45 t *types.GovernanceTransfer, 46 amount *num.Uint, 47 reason string, 48 gameID *string, 49 ) *TransferFunds { 50 return &TransferFunds{ 51 Base: newBase(ctx, TransferEvent), 52 transfer: t.IntoEvent(amount, &reason, gameID), 53 } 54 } 55 56 func NewOneOffTransferFundsEvent( 57 ctx context.Context, 58 t *types.OneOffTransfer, 59 ) *TransferFunds { 60 return &TransferFunds{ 61 Base: newBase(ctx, TransferEvent), 62 transfer: t.IntoEvent(nil), 63 } 64 } 65 66 func NewOneOffTransferFundsEventWithReason( 67 ctx context.Context, 68 t *types.OneOffTransfer, 69 reason string, 70 ) *TransferFunds { 71 return &TransferFunds{ 72 Base: newBase(ctx, TransferEvent), 73 transfer: t.IntoEvent(&reason), 74 } 75 } 76 77 func NewRecurringTransferFundsEvent( 78 ctx context.Context, 79 t *types.RecurringTransfer, 80 gameID *string, 81 ) *TransferFunds { 82 return &TransferFunds{ 83 Base: newBase(ctx, TransferEvent), 84 transfer: t.IntoEvent(nil, gameID), 85 } 86 } 87 88 func NewRecurringTransferFundsEventWithReason( 89 ctx context.Context, 90 t *types.RecurringTransfer, 91 reason string, 92 gameID *string, 93 ) *TransferFunds { 94 return &TransferFunds{ 95 Base: newBase(ctx, TransferEvent), 96 transfer: t.IntoEvent(&reason, gameID), 97 } 98 } 99 100 func (t TransferFunds) PartyID() string { 101 return t.transfer.From 102 } 103 104 func (t TransferFunds) TransferFunds() eventspb.Transfer { 105 return t.Proto() 106 } 107 108 func (t TransferFunds) Proto() eventspb.Transfer { 109 return *t.transfer 110 } 111 112 func (t TransferFunds) StreamMessage() *eventspb.BusEvent { 113 p := t.Proto() 114 115 busEvent := newBusEventFromBase(t.Base) 116 busEvent.Event = &eventspb.BusEvent_Transfer{ 117 Transfer: &p, 118 } 119 120 return busEvent 121 } 122 123 func TransferFundsEventFromStream(ctx context.Context, be *eventspb.BusEvent) *TransferFunds { 124 event := be.GetTransfer() 125 if event == nil { 126 return nil 127 } 128 129 return &TransferFunds{ 130 Base: newBaseFromBusEvent(ctx, TransferEvent, be), 131 transfer: event, 132 } 133 }