/
queryIdentifier.go
51 lines (44 loc) · 1.42 KB
/
queryIdentifier.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/mingderwang/did/x/did/types"
"github.com/spf13/cobra"
)
func GetCmdListIdentifier(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "list-identifier",
Short: "list all identifier",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/"+types.QueryListIdentifier, queryRoute), nil)
if err != nil {
fmt.Printf("could not list Identifier\n%s\n", err.Error())
return nil
}
var out []types.Identifier
cdc.MustUnmarshalJSON(res, &out)
return cliCtx.PrintOutput(out)
},
}
}
func GetCmdGetIdentifier(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "get-identifier [key]",
Short: "Query a identifier 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.QueryGetIdentifier, key), nil)
if err != nil {
fmt.Printf("could not resolve identifier %s \n%s\n", key, err.Error())
return nil
}
var out types.Identifier
cdc.MustUnmarshalJSON(res, &out)
return cliCtx.PrintOutput(out)
},
}
}