-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_market.go
113 lines (87 loc) · 2.46 KB
/
query_market.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package cli
import (
"context"
"strings"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/furychain/fury/x/market/types"
"github.com/spf13/cobra"
)
// CmdListMarkets implements a command to return all markets
func CmdListMarkets() *cobra.Command {
cmd := &cobra.Command{
Use: "markets",
Short: "list markets",
Long: "Get list of markets in paginated response.",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
params := &types.QueryMarketsRequest{
Pagination: pageReq,
}
res, err := queryClient.Markets(context.Background(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddPaginationFlagsToCmd(cmd, cmd.Use)
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
// CmdShowMarket implements a command to return a specific market based on its UID
func CmdShowMarket() *cobra.Command {
cmd := &cobra.Command{
Use: "market [uid]",
Short: "get market",
Long: "Get market meta by uid.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
argUID := args[0]
params := &types.QueryMarketRequest{
Uid: argUID,
}
res, err := queryClient.Market(context.Background(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
// CmdListMarketByUIDs returns command object for querying markets by uid list
func CmdListMarketByUIDs() *cobra.Command {
cmd := &cobra.Command{
Use: "markets-by-uids [uid]",
Short: "Query markets list by UIDs",
Long: "Get list of markets by list of uids.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
reqUID := strings.Split(args[0], listSeparator)
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
params := &types.QueryMarketsByUIDsRequest{
Uids: reqUID,
}
res, err := queryClient.MarketsByUIDs(cmd.Context(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}