code.vegaprotocol.io/vega@v0.79.0/cmd/vega/commands/query/network_parameters.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 query 17 18 import ( 19 "errors" 20 "fmt" 21 22 apipb "code.vegaprotocol.io/vega/protos/vega/api/v1" 23 24 "github.com/golang/protobuf/jsonpb" 25 ) 26 27 type NetworkParametersCmd struct { 28 NodeAddress string `default:"0.0.0.0:3002" description:"The address of the vega node to use" long:"node-address"` 29 } 30 31 func (opts *NetworkParametersCmd) Execute(params []string) error { 32 if len(params) > 1 { 33 return errors.New("only one network parameter key can be to be specified") 34 } 35 36 var key string 37 if len(params) == 1 { 38 key = params[0] 39 } 40 41 req := apipb.ListNetworkParametersRequest{ 42 NetworkParameterKey: key, 43 } 44 return getPrintNetworkParameters(opts.NodeAddress, &req) 45 } 46 47 func getPrintNetworkParameters(nodeAddress string, req *apipb.ListNetworkParametersRequest) error { 48 clt, err := getClient(nodeAddress) 49 if err != nil { 50 return fmt.Errorf("could not connect to the vega node: %w", err) 51 } 52 53 ctx, cancel := timeoutContext() 54 defer cancel() 55 res, err := clt.ListNetworkParameters(ctx, req) 56 if err != nil { 57 return fmt.Errorf("error querying the vega node: %w", err) 58 } 59 60 m := jsonpb.Marshaler{ 61 Indent: " ", 62 } 63 buf, err := m.MarshalToString(res) 64 if err != nil { 65 return fmt.Errorf("invalid response from vega node: %w", err) 66 } 67 68 fmt.Printf("%v", buf) 69 70 return nil 71 }