code.vegaprotocol.io/vega@v0.79.0/cmd/vega/commands/query/proposals.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 "fmt" 20 21 apipb "code.vegaprotocol.io/vega/protos/vega/api/v1" 22 23 "github.com/golang/protobuf/jsonpb" 24 ) 25 26 type ProposalsCmd struct { 27 NodeAddress string `default:"0.0.0.0:3002" description:"The address of the vega node to use" long:"node-address"` 28 } 29 30 func (opts *ProposalsCmd) Execute(_ []string) error { 31 req := apipb.ListProposalsRequest{} 32 return getPrintProposals(opts.NodeAddress, &req) 33 } 34 35 func getPrintProposals(nodeAddress string, req *apipb.ListProposalsRequest) error { 36 clt, err := getClient(nodeAddress) 37 if err != nil { 38 return fmt.Errorf("could not connect to the vega node: %w", err) 39 } 40 41 ctx, cancel := timeoutContext() 42 defer cancel() 43 res, err := clt.ListProposals(ctx, req) 44 if err != nil { 45 return fmt.Errorf("error querying the vega node: %w", err) 46 } 47 48 m := jsonpb.Marshaler{ 49 Indent: " ", 50 } 51 buf, err := m.MarshalToString(res) 52 if err != nil { 53 return fmt.Errorf("invalid response from vega node: %w", err) 54 } 55 56 fmt.Printf("%v", buf) 57 58 return nil 59 }