-
Notifications
You must be signed in to change notification settings - Fork 2
/
query_upgrade.go
48 lines (40 loc) · 1.18 KB
/
query_upgrade.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
package cli
import (
"fmt"
"strings"
"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context"
"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec"
"github.com/fibonacci-chain/fbc/x/params/types"
"github.com/spf13/cobra"
)
func GetCmdQueryUpgrade(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "upgrade [name]",
Args: cobra.MinimumNArgs(0),
Short: "Query info of upgrade",
Long: strings.TrimSpace(`Query info of a upgrade, query all upgrade if 'name' is omitted:
$ exchaincli query params upgrade <name>
`),
RunE: func(_ *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
upgradeName := ""
if len(args) > 0 {
upgradeName = args[0]
}
route := fmt.Sprintf("custom/%s/%s/%s", queryRoute, types.QueryUpgrade, upgradeName)
bz, _, err := cliCtx.QueryWithData(route, nil)
if err != nil {
return err
}
var infos []types.UpgradeInfo
cdc.MustUnmarshalJSON(bz, &infos)
if len(upgradeName) != 0 {
return cliCtx.PrintOutput(infos[0])
}
if len(infos) == 0 {
return cliCtx.PrintOutput("there's no upgrade")
}
return cliCtx.PrintOutput(infos)
},
}
}