-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_pool.go
95 lines (75 loc) · 2.15 KB
/
query_pool.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
83
84
85
86
87
88
89
90
91
92
93
94
95
package cli
import (
"context"
"strconv"
"strings"
"github.com/QuadrateOrg/core/x/dex/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"
)
func CmdShowPool() *cobra.Command {
cmd := &cobra.Command{
Use: "show-pool '[pair-id]' [tick-index] [fee]",
Short: "shows a pool. Make sure to wrap your pair-id in quotes otherwise the shell will interpret <> as a separator token",
Example: "show-pool 'tokenA<>tokenB' [-5] 1",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
argPairID := args[0]
if strings.HasPrefix(args[1], "[") && strings.HasSuffix(args[1], "]") {
args[1] = strings.TrimPrefix(args[1], "[")
args[1] = strings.TrimSuffix(args[1], "]")
}
argTickIndex := args[1]
argFee := args[2]
argFeeInt, err := strconv.ParseUint(argFee, 10, 0)
if err != nil {
return err
}
argTickIndexInt, err := strconv.ParseInt(argTickIndex, 10, 0)
if err != nil {
return err
}
params := &types.QueryPoolRequest{
PairID: argPairID,
TickIndex: argTickIndexInt,
Fee: argFeeInt,
}
res, err := queryClient.Pool(context.Background(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
func CmdShowPoolByID() *cobra.Command {
cmd := &cobra.Command{
Use: "show-pool-by-id [poolID]",
Short: "shows a pool by poolID",
Example: "show-pool-by-id 5",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
argPoolID, err := strconv.ParseUint(args[0], 10, 0)
if err != nil {
return err
}
params := &types.QueryPoolByIDRequest{
PoolID: argPoolID,
}
res, err := queryClient.PoolByID(context.Background(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}