code.vegaprotocol.io/vega@v0.79.0/datanode/gateway/graphql/transfers_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 "errors" 21 22 "code.vegaprotocol.io/vega/datanode/vegatime" 23 "code.vegaprotocol.io/vega/protos/vega" 24 eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1" 25 ) 26 27 var ErrUnsupportedTransferKind = errors.New("unsupported transfer kind") 28 29 type transferResolver VegaResolverRoot 30 31 func (r *transferResolver) Asset(ctx context.Context, obj *eventspb.Transfer) (*vega.Asset, error) { 32 return r.r.getAssetByID(ctx, obj.Asset) 33 } 34 35 func (r *transferResolver) Timestamp(ctx context.Context, obj *eventspb.Transfer) (string, error) { 36 return vegatime.Format(vegatime.UnixNano(obj.Timestamp)), nil 37 } 38 39 func (r *transferResolver) Kind(ctx context.Context, obj *eventspb.Transfer) (TransferKind, error) { 40 switch obj.GetKind().(type) { 41 case *eventspb.Transfer_OneOff: 42 return obj.GetOneOff(), nil 43 case *eventspb.Transfer_OneOffGovernance: 44 return obj.GetOneOffGovernance(), nil 45 case *eventspb.Transfer_Recurring: 46 return obj.GetRecurring(), nil 47 case *eventspb.Transfer_RecurringGovernance: 48 return obj.GetRecurringGovernance(), nil 49 default: 50 return nil, ErrUnsupportedTransferKind 51 } 52 } 53 54 type recurringTransferResolver VegaResolverRoot 55 56 func (r *recurringTransferResolver) StartEpoch(ctx context.Context, obj *eventspb.RecurringTransfer) (int, error) { 57 return int(obj.StartEpoch), nil 58 } 59 60 func (r *recurringTransferResolver) EndEpoch(ctx context.Context, obj *eventspb.RecurringTransfer) (*int, error) { 61 if obj.EndEpoch != nil { 62 i := int(*obj.EndEpoch) 63 return &i, nil 64 } 65 return nil, nil 66 } 67 68 type recurringGovernanceTransferResolver VegaResolverRoot 69 70 func (r *recurringGovernanceTransferResolver) StartEpoch(ctx context.Context, obj *eventspb.RecurringGovernanceTransfer) (int, error) { 71 return int(obj.StartEpoch), nil 72 } 73 74 func (r *recurringGovernanceTransferResolver) EndEpoch(ctx context.Context, obj *eventspb.RecurringGovernanceTransfer) (*int, error) { 75 if obj.EndEpoch != nil { 76 i := int(*obj.EndEpoch) 77 return &i, nil 78 } 79 return nil, nil 80 }