code.vegaprotocol.io/vega@v0.79.0/core/banking/cancel_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 banking 17 18 import ( 19 "context" 20 "errors" 21 "fmt" 22 23 "code.vegaprotocol.io/vega/core/events" 24 "code.vegaprotocol.io/vega/core/types" 25 ) 26 27 var ( 28 ErrRecurringTransferDoesNotExists = errors.New("recurring transfer does not exists") 29 ErrCannotCancelOtherPartiesRecurringTransfers = errors.New("cannot cancel other parties recurring transfers") 30 ) 31 32 func (e *Engine) CancelTransferFunds( 33 ctx context.Context, 34 cancel *types.CancelTransferFunds, 35 ) error { 36 // validation is simple, does the transfer 37 // exists 38 transfer, ok := e.recurringTransfersMap[cancel.TransferID] 39 if !ok { 40 return ErrRecurringTransferDoesNotExists 41 } 42 43 // Is the From party of the transfer 44 // the party which submitted the transaction? 45 if transfer.From != cancel.Party { 46 return ErrCannotCancelOtherPartiesRecurringTransfers 47 } 48 49 // all good, let's delete 50 e.deleteTransfer(cancel.TransferID) 51 52 // send an event because we are nice with the data-node 53 transfer.Status = types.TransferStatusCancelled 54 e.broker.Send(events.NewRecurringTransferFundsEventWithReason(ctx, transfer, "transfer cancelled", e.getGameID(transfer))) 55 56 return nil 57 } 58 59 func (e *Engine) CancelGovTransfer(ctx context.Context, ID string) error { 60 gTransfer, ok := e.recurringGovernanceTransfersMap[ID] 61 if !ok { 62 return fmt.Errorf("Governance transfer %s not found", ID) 63 } 64 e.deleteGovTransfer(ID) 65 gTransfer.Status = types.TransferStatusCancelled 66 e.broker.Send(events.NewGovTransferFundsEvent(ctx, gTransfer, gTransfer.Config.MaxAmount, e.getGovGameID(gTransfer))) 67 return nil 68 }