forked from bandprotocol/chain
-
Notifications
You must be signed in to change notification settings - Fork 2
/
query.go
executable file
·82 lines (72 loc) · 2 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package cli
import (
coinswaptypes "github.com/GeoDB-Limited/odin-core/x/coinswap/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/cobra"
)
// GetQueryCmd returns the cli query commands for this module.
func GetQueryCmd() *cobra.Command {
coinswapCmd := &cobra.Command{
Use: coinswaptypes.ModuleName,
Short: "Querying commands for the coinswap module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
coinswapCmd.AddCommand(
GetQueryCmdParams(),
GetQueryCmdRate(),
)
return coinswapCmd
}
// GetQueryCmdParams implements the query parameters command.
func GetQueryCmdParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := coinswaptypes.NewQueryClient(clientCtx)
res, err := queryClient.Params(cmd.Context(), &coinswaptypes.QueryParamsRequest{})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
func GetQueryCmdRate() *cobra.Command {
cmd := &cobra.Command{
Use: "rate [from-denom] [to-denom]",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
err = sdk.ValidateDenom(args[0])
if err != nil {
return err
}
err = sdk.ValidateDenom(args[1])
if err != nil {
return err
}
queryClient := coinswaptypes.NewQueryClient(clientCtx)
res, err := queryClient.Rate(cmd.Context(), &coinswaptypes.QueryRateRequest{From: args[0], To: args[1]})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}