code.vegaprotocol.io/vega@v0.79.0/datanode/gateway/graphql/update_asset_resolver.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 gql
    17  
    18  import (
    19  	"context"
    20  
    21  	types "code.vegaprotocol.io/vega/protos/vega"
    22  )
    23  
    24  type updateAssetResolver VegaResolverRoot
    25  
    26  func (r *updateAssetResolver) Source(ctx context.Context, obj *types.UpdateAsset) (UpdateAssetSource, error) {
    27  	return UpdateAssetSourceFromProto(obj.Changes)
    28  }
    29  
    30  func (r *updateAssetResolver) Quantum(ctx context.Context, obj *types.UpdateAsset) (string, error) {
    31  	return obj.Changes.Quantum, nil
    32  }
    33  
    34  func UpdateAssetSourceFromProto(pdetails *types.AssetDetailsUpdate) (UpdateAssetSource, error) {
    35  	if pdetails == nil {
    36  		return nil, ErrNilAssetSource
    37  	}
    38  
    39  	switch asimpl := pdetails.Source.(type) {
    40  	case *types.AssetDetailsUpdate_Erc20:
    41  		return UpdateERC20FromProto(asimpl.Erc20), nil
    42  	default:
    43  		return nil, ErrUnimplementedAssetSource
    44  	}
    45  }
    46  
    47  func UpdateERC20FromProto(ea *types.ERC20Update) *UpdateErc20 {
    48  	return &UpdateErc20{
    49  		LifetimeLimit:     ea.LifetimeLimit,
    50  		WithdrawThreshold: ea.WithdrawThreshold,
    51  	}
    52  }