/
query.go
55 lines (46 loc) · 1.49 KB
/
query.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
52
53
54
55
package cli
import (
"fmt"
"github.com/spf13/cobra"
"github.com/hdac-io/friday/client"
"github.com/hdac-io/friday/client/context"
"github.com/hdac-io/friday/codec"
"github.com/hdac-io/friday/x/nickname/types"
)
// GetDataQueryCmd controls GET type CLI controller
func GetDataQueryCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
nameserverGetDataQueryCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Nickname query commands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
nameserverGetDataQueryCmd.AddCommand(client.GetCommands(
GetCmdQueryAddress(cdc),
)...)
return nameserverGetDataQueryCmd
}
// GetCmdQueryAddress handles to get accounts list
func GetCmdQueryAddress(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "get-address <nickname>",
Short: "Get address of given nickname",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
queryData := types.QueryReqUnitAccount{
Nickname: args[0],
}
bz := cdc.MustMarshalJSON(queryData)
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/getaddress", types.ModuleName), bz)
if err != nil {
fmt.Printf("could not resolve account - %s \n", args[0])
return nil
}
var out types.QueryResUnitAccount
cdc.MustUnmarshalJSON(res, &out)
return cliCtx.PrintOutput(out)
},
}
}