code.vegaprotocol.io/vega@v0.79.0/core/processor/process_withdraw.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 processor
    17  
    18  import (
    19  	"context"
    20  	"errors"
    21  
    22  	"code.vegaprotocol.io/vega/core/types"
    23  	"code.vegaprotocol.io/vega/logging"
    24  )
    25  
    26  var ErrMissingWithdrawERC20Ext = errors.New("missing withdraw submission erc20 ext")
    27  
    28  func (app *App) processWithdraw(ctx context.Context, w *types.WithdrawSubmission, id string, party string) (err error) {
    29  	asset, err := app.assets.Get(w.Asset)
    30  	if err != nil {
    31  		app.log.Error("invalid vega asset ID for withdrawal",
    32  			logging.Error(err),
    33  			logging.BigUint("amount", w.Amount),
    34  			logging.AssetID(w.Asset))
    35  		return err
    36  	}
    37  
    38  	switch {
    39  	case asset.IsBuiltinAsset():
    40  		return app.banking.WithdrawBuiltinAsset(ctx, id, party, w.Asset, w.Amount)
    41  	case asset.IsERC20():
    42  		if w.Ext == nil {
    43  			return ErrMissingWithdrawERC20Ext
    44  		}
    45  		ext := w.Ext.GetErc20()
    46  		if ext == nil {
    47  			return ErrMissingWithdrawERC20Ext
    48  		}
    49  		return app.banking.WithdrawERC20(ctx, id, party, w.Asset, w.Amount, ext.Erc20)
    50  	}
    51  
    52  	return errors.New("unimplemented withdrawal")
    53  }