mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 18:15:19 +00:00
f0fa2e1253
* module files * proto types * types and generated proto types * keeper * client scaffold * add savings module to app * remove placeholder types file * implement rest and add to module * update proto types * validation for supported denoms * generate updates proto types * update comments * update comments * remove unused imports from proto files * regenerate proto files * update proto types * client * deposit type and generated proto types * deposit keeper methods + tests * update savings module file * update app.go + test common * query proto types * query types + generated proto types * keeper logic for deposits queries * cli/rest querier updates * remove abci * remove refs to other modules * remove endblocker call * genesis init test for module account * update genesis test with params * add get/set params test * fix up keeper test * use params getter * simplify if/else statement * remove querier.go and rest/query * update query deposit description * remove legacy querier * register querier * revisions
133 lines
3.2 KiB
Go
133 lines
3.2 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"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/kava-labs/kava/x/savings/types"
|
|
)
|
|
|
|
// flags for cli queries
|
|
const (
|
|
flagDenom = "denom"
|
|
flagOwner = "owner"
|
|
)
|
|
|
|
// GetQueryCmd returns the cli query commands for this module
|
|
func GetQueryCmd() *cobra.Command {
|
|
savingsQueryCmd := &cobra.Command{
|
|
Use: types.ModuleName,
|
|
Short: "Querying commands for the savings module",
|
|
DisableFlagParsing: true,
|
|
SuggestionsMinimumDistance: 2,
|
|
RunE: client.ValidateCmd,
|
|
}
|
|
|
|
cmds := []*cobra.Command{
|
|
GetCmdQueryParams(),
|
|
queryDepositsCmd(),
|
|
}
|
|
|
|
for _, cmd := range cmds {
|
|
flags.AddQueryFlagsToCmd(cmd)
|
|
}
|
|
|
|
savingsQueryCmd.AddCommand(cmds...)
|
|
|
|
return savingsQueryCmd
|
|
}
|
|
|
|
// GetCmdQueryParams queries the savings module parameters
|
|
func GetCmdQueryParams() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "params",
|
|
Short: "get the savings module parameters",
|
|
Long: "Get the current global savings module parameters.",
|
|
Args: cobra.NoArgs,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
clientCtx, err := client.GetClientQueryContext(cmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
queryClient := types.NewQueryClient(clientCtx)
|
|
|
|
res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return clientCtx.PrintProto(&res.Params)
|
|
},
|
|
}
|
|
}
|
|
|
|
func queryDepositsCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "deposits",
|
|
Short: "query savings module deposits with optional filters",
|
|
Long: "query for all savings module deposits or a specific deposit using flags",
|
|
Example: fmt.Sprintf(`%[1]s q %[2]s deposits
|
|
%[1]s q %[2]s deposits --owner kava1l0xsq2z7gqd7yly0g40y5836g0appumark77ny --denom bnb
|
|
%[1]s q %[2]s deposits --denom ukava
|
|
%[1]s q %[2]s deposits --denom btcb`, version.AppName, types.ModuleName),
|
|
Args: cobra.NoArgs,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
clientCtx, err := client.GetClientQueryContext(cmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
ownerBech, err := cmd.Flags().GetString(flagOwner)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
denom, err := cmd.Flags().GetString(flagDenom)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
pageReq, err := client.ReadPageRequest(cmd.Flags())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
req := &types.QueryDepositsRequest{
|
|
Denom: denom,
|
|
Pagination: pageReq,
|
|
}
|
|
|
|
if len(ownerBech) != 0 {
|
|
depositOwner, err := sdk.AccAddressFromBech32(ownerBech)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
req.Owner = depositOwner.String()
|
|
}
|
|
|
|
queryClient := types.NewQueryClient(clientCtx)
|
|
|
|
res, err := queryClient.Deposits(context.Background(), req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return clientCtx.PrintProto(res)
|
|
},
|
|
}
|
|
|
|
flags.AddPaginationFlagsToCmd(cmd, "deposits")
|
|
|
|
cmd.Flags().String(flagOwner, "", "(optional) filter for deposits by owner address")
|
|
cmd.Flags().String(flagDenom, "", "(optional) filter for deposits by denom")
|
|
|
|
return cmd
|
|
}
|