From cb9e6ea6fa07a02bb5210727cd939f6895a9732f Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 19 Feb 2021 11:03:34 +0300 Subject: [PATCH] [#398] cmd/cli: Add netinfo command to netmap section Add `netinfo` sub-cmd of `netmap` cmd that read recent information about NeoFS network. Info is read via NeoFS API NetmapService.NetworkInfo RPC. Signed-off-by: Leonard Lyubich --- cmd/neofs-cli/modules/netmap.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cmd/neofs-cli/modules/netmap.go b/cmd/neofs-cli/modules/netmap.go index 343115c30..36677d9af 100644 --- a/cmd/neofs-cli/modules/netmap.go +++ b/cmd/neofs-cli/modules/netmap.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/mr-tron/base58" + "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/util/signature" "github.com/nspcc-dev/neofs-node/pkg/services/control" @@ -36,6 +37,7 @@ func init() { getEpochCmd, localNodeInfoCmd, snapshotCmd, + netInfoCmd, ) localNodeInfoCmd.Flags().BoolVar(&nodeInfoJSON, "json", false, "print node info in JSON format") @@ -127,6 +129,30 @@ var snapshotCmd = &cobra.Command{ }, } +var netInfoCmd = &cobra.Command{ + Use: "netinfo", + Short: "Get information about NeoFS network", + Long: "Get information about NeoFS network", + RunE: func(cmd *cobra.Command, args []string) error { + cli, err := getSDKClient() + if err != nil { + return err + } + + netInfo, err := cli.NetworkInfo(context.Background(), globalCallOptions()...) + if err != nil { + return fmt.Errorf("rpc error: %w", err) + } + + cmd.Printf("Epoch: %d\n", netInfo.CurrentEpoch()) + + magic := netInfo.MagicNumber() + cmd.Printf("Network magic: [%s] %d\n", netmode.Magic(magic), magic) + + return nil + }, +} + func prettyPrintNodeInfo(i *netmap.NodeInfo, jsonEncoding bool) { if jsonEncoding { printJSONMarshaler(i, "node info")