-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_deposit.go
110 lines (92 loc) · 2.57 KB
/
query_deposit.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
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/furynet/furynetwork/x/house/types"
"github.com/spf13/cobra"
)
// GetCmdQueryDeposits implements the query deposits command.
func GetCmdQueryDeposits() *cobra.Command {
cmd := &cobra.Command{
Use: "deposits",
Short: "Query for all deposits in the house",
Args: cobra.NoArgs,
Long: strings.TrimSpace(
fmt.Sprintf(`Query details about all deposits on a network.
Example:
$ %s query house deposits
`,
version.AppName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}
result, err := queryClient.Deposits(cmd.Context(), &types.QueryDepositsRequest{
Pagination: pageReq,
})
if err != nil {
return err
}
return clientCtx.PrintProto(result)
},
}
flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "deposits")
return cmd
}
// GetCmdQueryDepositsByAccount implements the command to query all the deposits made from one address.
func GetCmdQueryDepositsByAccount() *cobra.Command {
bech32PrefixAccAddr := sdk.GetConfig().GetBech32AccountAddrPrefix()
cmd := &cobra.Command{
Use: "deposits-by-account [account]",
Short: "Query all deposits made by one account",
Long: strings.TrimSpace(
fmt.Sprintf(`Query deposits for an individual account on all houses.
Example:
$ %s query house deposits-by-account %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.QueryDepositsByAccountRequest{
Address: depAddr.String(),
Pagination: pageReq,
}
res, err := queryClient.DepositsByAccount(cmd.Context(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "deposits")
return cmd
}