code.vegaprotocol.io/vega@v0.79.0/datanode/gateway/graphql/reward.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  	"fmt"
    21  
    22  	"code.vegaprotocol.io/vega/datanode/vegatime"
    23  	"code.vegaprotocol.io/vega/protos/vega"
    24  )
    25  
    26  type rewardResolver VegaResolverRoot
    27  
    28  func (r *rewardResolver) Asset(ctx context.Context, obj *vega.Reward) (*vega.Asset, error) {
    29  	asset, err := r.r.getAssetByID(ctx, obj.AssetId)
    30  	if err != nil {
    31  		return nil, err
    32  	}
    33  
    34  	return asset, nil
    35  }
    36  
    37  func (r *rewardResolver) Party(ctx context.Context, obj *vega.Reward) (*vega.Party, error) {
    38  	return &vega.Party{Id: obj.PartyId}, nil
    39  }
    40  
    41  func (r *rewardResolver) ReceivedAt(ctx context.Context, obj *vega.Reward) (string, error) {
    42  	return vegatime.Format(vegatime.UnixNano(obj.ReceivedAt)), nil
    43  }
    44  
    45  func (r *rewardResolver) Epoch(ctx context.Context, obj *vega.Reward) (*vega.Epoch, error) {
    46  	epoch, err := r.r.getEpochByID(ctx, obj.Epoch)
    47  	if err != nil {
    48  		return nil, err
    49  	}
    50  
    51  	return epoch, nil
    52  }
    53  
    54  func (r *rewardResolver) LockedUntilEpoch(ctx context.Context, obj *vega.Reward) (*vega.Epoch, error) {
    55  	epoch, err := r.r.getEpochByID(ctx, obj.LockedUntilEpoch)
    56  	if err != nil {
    57  		return nil, err
    58  	}
    59  
    60  	return epoch, nil
    61  }
    62  
    63  func (r *rewardResolver) RewardType(ctx context.Context, obj *vega.Reward) (vega.AccountType, error) {
    64  	accountType, ok := vega.AccountType_value[obj.RewardType]
    65  	if !ok {
    66  		return vega.AccountType_ACCOUNT_TYPE_UNSPECIFIED, fmt.Errorf("Unknown account type %v", obj.RewardType)
    67  	}
    68  
    69  	return vega.AccountType(accountType), nil
    70  }