/
queryCommit.go
51 lines (44 loc) · 1.4 KB
/
queryCommit.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
50
51
package cli
import (
"fmt"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/sdk-tutorials/scavenge/scavenge/x/scavenge/types"
"github.com/spf13/cobra"
)
func GetCmdListCommit(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "list-commit",
Short: "list all commit",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryListCommit), nil)
if err != nil {
fmt.Printf("could not list Commit\n%s\n", err.Error())
return nil
}
var out []types.Commit
cdc.MustUnmarshalJSON(res, &out)
return cliCtx.PrintOutput(out)
},
}
}
func GetCmdGetCommit(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "get-commit [key]",
Short: "Get a commit by key",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
key := args[0]
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s/%s", queryRoute, types.QueryGetCommit, key), nil)
if err != nil {
fmt.Printf("could not get Commit with key %s\n%s\n", key, err.Error())
return nil
}
var out types.Commit
cdc.MustUnmarshalJSON(res, &out)
return cliCtx.PrintOutput(out)
},
}
}