-
Notifications
You must be signed in to change notification settings - Fork 28
/
block.go
49 lines (38 loc) · 1.06 KB
/
block.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package block
import (
"strconv"
"github.com/QOSGroup/qbase/client/context"
"github.com/QOSGroup/qbase/client/types"
"github.com/spf13/cobra"
"github.com/spf13/viper"
go_amino "github.com/tendermint/go-amino"
)
func blockCommand(cdc *go_amino.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "block [height]",
Short: "Get block info at given height",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
h, err := strconv.Atoi(args[0])
if err != nil {
return err
}
height := int64(h)
viper.Set(types.FlagTrustNode, true)
cliCtx := context.NewCLIContext().WithCodec(cdc)
node, err := cliCtx.GetNode()
if err != nil {
return err
}
res, err := node.Block(&height)
if err != nil {
return err
}
return cliCtx.PrintResult(res)
},
}
cmd.Flags().StringP(types.FlagNode, "n", "tcp://localhost:26657", "Node to connect to")
viper.BindPFlag(types.FlagNode, cmd.Flags().Lookup(types.FlagNode))
cmd.Flags().Bool(types.FlagJSONIndet, false, "print indent result json")
return cmd
}