-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_withdrawal.go
67 lines (55 loc) · 1.67 KB
/
query_withdrawal.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
package cli
import (
"fmt"
"strings"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/merlin-network/fury/x/house/types"
"github.com/spf13/cobra"
)
// GetCmdQueryDepositorWithdrawals implements the command to query all the withdrawals made from one depositor.
func GetCmdQueryDepositorWithdrawals() *cobra.Command {
bech32PrefixAccAddr := sdk.GetConfig().GetBech32AccountAddrPrefix()
cmd := &cobra.Command{
Use: "depositor-withdrawals [depositor-addr]",
Short: "Query all withdrawals made by one depositor",
Long: strings.TrimSpace(
fmt.Sprintf(`Query withdrawals for an individual depositor on all houses.
Example:
$ %s query house depositor-withdrawals %s1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p
`,
version.AppName, bech32PrefixAccAddr,
),
),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
depAddr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}
pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}
params := &types.QueryDepositorWithdrawalsRequest{
DepositorAddress: depAddr.String(),
Pagination: pageReq,
}
res, err := queryClient.DepositorWithdrawals(cmd.Context(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "withdrawals")
return cmd
}