code.vegaprotocol.io/vega@v0.79.0/datanode/gateway/graphql/node_data_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 "code.vegaprotocol.io/vega/libs/ptr" 22 proto "code.vegaprotocol.io/vega/protos/vega" 23 ) 24 25 type nodeDataResolver VegaResolverRoot 26 27 func toNodeSet(obj *proto.NodeSet) *NodeSet { 28 ns := &NodeSet{ 29 Total: int(obj.Total), 30 Demoted: obj.Demoted, 31 Promoted: obj.Promoted, 32 Inactive: int(obj.Inactive), 33 } 34 if obj.Maximum != nil { 35 ns.Maximum = ptr.From(int(*obj.Maximum)) 36 } 37 return ns 38 } 39 40 func (r *nodeDataResolver) TotalNodes(ctx context.Context, obj *proto.NodeData) (int, error) { 41 return int(obj.TotalNodes), nil 42 } 43 44 func (r *nodeDataResolver) InactiveNodes(ctx context.Context, obj *proto.NodeData) (int, error) { 45 return int(obj.InactiveNodes), nil 46 } 47 48 func (r *nodeDataResolver) Uptime(ctx context.Context, obj *proto.NodeData) (float64, error) { 49 return float64(obj.Uptime), nil 50 } 51 52 func (r *nodeDataResolver) TendermintNodes(ctx context.Context, obj *proto.NodeData) (*NodeSet, error) { 53 return toNodeSet(obj.TendermintNodes), nil 54 } 55 56 func (r *nodeDataResolver) ErsatzNodes(ctx context.Context, obj *proto.NodeData) (*NodeSet, error) { 57 if obj.ErsatzNodes == nil || obj.ErsatzNodes.Total == 0 { 58 return nil, nil 59 } 60 return toNodeSet(obj.ErsatzNodes), nil 61 } 62 63 func (r *nodeDataResolver) PendingNodes(ctx context.Context, obj *proto.NodeData) (*NodeSet, error) { 64 if obj.PendingNodes == nil || obj.PendingNodes.Total == 0 { 65 return nil, nil 66 } 67 return toNodeSet(obj.PendingNodes), nil 68 }