-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_bet.go
193 lines (149 loc) · 4.51 KB
/
query_bet.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package cli
import (
"context"
"strings"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/furynet/furynetwork/x/bet/types"
"github.com/spf13/cobra"
)
// CmdListBet implements a command to return all bets
func CmdListBet() *cobra.Command {
cmd := &cobra.Command{
Use: "bets",
Short: "get list of bets",
Long: "Get list of bets 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.QueryBetsRequest{
Pagination: pageReq,
}
res, err := queryClient.Bets(context.Background(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddPaginationFlagsToCmd(cmd, cmd.Use)
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
// CmdListBetByCreator implements a command to return all bets of a certain creator address
func CmdListBetByCreator() *cobra.Command {
cmd := &cobra.Command{
Use: "bets-by-creator [creator]",
Short: "get list of bets for a creator-address",
Long: "Get list of bets for a creator address in paginated response.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
argCreator := args[0]
pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
params := &types.QueryBetsByCreatorRequest{
Creator: argCreator,
Pagination: pageReq,
}
res, err := queryClient.BetsByCreator(context.Background(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddPaginationFlagsToCmd(cmd, cmd.Use)
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
// CmdListPendingBets implements a command to return all pending bets of a market
func CmdListPendingBets() *cobra.Command {
cmd := &cobra.Command{
Use: "pending-bets [market-uid]",
Short: "get list of pending bets of a market",
Long: "Get list of pending bets of a market in paginated response.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
argMarketUID := args[0]
pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
params := &types.QueryPendingBetsRequest{
MarketUid: argMarketUID,
Pagination: pageReq,
}
res, err := queryClient.PendingBets(context.Background(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddPaginationFlagsToCmd(cmd, cmd.Use)
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
// CmdListBetByUIDs returns command object for querying bets by uid list
func CmdListBetByUIDs() *cobra.Command {
cmd := &cobra.Command{
Use: "bets-by-uids [creator:uid]",
Short: "Query bets list of bettor by creator:UID list",
Long: "Get list of bets creator:UID comma separated list ex: \"address1:uid1,address2:uid2\" .",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
reqItems := strings.Split(args[0], listSeparator)
params := &types.QueryBetsByUIDsRequest{
Items: reqItems,
}
res, err := queryClient.BetsByUIDs(cmd.Context(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
// CmdShowBet implements a command to return a specific bet
func CmdShowBet() *cobra.Command {
cmd := &cobra.Command{
Use: "bet [creator] [uid]",
Short: "bet details by creator-address and uid",
Long: "Get bet details by bet-creator-address address and uid.",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
argCreator := args[0]
argUID := args[1]
params := &types.QueryBetRequest{
Creator: argCreator,
Uid: argUID,
}
res, err := queryClient.Bet(context.Background(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}