Skip to content

Commit

Permalink
Revert "feat: Apply autocli"
Browse files Browse the repository at this point in the history
This reverts commit fad4908.
  • Loading branch information
dudong2 committed May 13, 2024
1 parent e2b7df2 commit 37b9b93
Show file tree
Hide file tree
Showing 28 changed files with 1,867 additions and 378 deletions.
84 changes: 0 additions & 84 deletions x/coinswap/autocli.go

This file was deleted.

155 changes: 155 additions & 0 deletions x/coinswap/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package cli

import (
"fmt"
"strings"

"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/Canto-Network/Canto/v7/x/coinswap/types"
)

// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

cmd.AddCommand(
NewQueryParamsCmd(),
GetCmdQueryLiquidityPools(),
GetCmdQueryLiquidityPool(),
)

return cmd
}

// NewQueryParamsCmd implements the params query command.
func NewQueryParamsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Args: cobra.NoArgs,
Short: "Query the current coinswap parameters information",
Long: strings.TrimSpace(
fmt.Sprintf(`Query values set as coinswap parameters.
Example:
$ %s query %s params
`,
version.AppName, types.ModuleName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

resp, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(&resp.Params)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

func GetCmdQueryLiquidityPools() *cobra.Command {
cmd := &cobra.Command{
Use: "liquidity-pools",
Short: "query all liquidity pools",
Long: strings.TrimSpace(
fmt.Sprintf(`Query all liquidity pools.
Example:
$ %s query %s liquidity-pools
`,
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
}
queryClient := types.NewQueryClient(clientCtx)

pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}
res, err := queryClient.LiquidityPools(cmd.Context(), &types.QueryLiquidityPoolsRequest{
Pagination: pageReq,
})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "liquidity-pools")

return cmd
}

func GetCmdQueryLiquidityPool() *cobra.Command {
cmd := &cobra.Command{
Use: "liquidity-pool [liquidity pool denom]",
Short: "query a specific liquidity pool",
Long: strings.TrimSpace(
fmt.Sprintf(`Query details of a liquidity pool .
Example:
$ %s query %s liquidity-pool
`,
version.AppName, types.ModuleName,
),
),
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)

lptDenom := args[0]
if err := sdk.ValidateDenom(lptDenom); err != nil {
return err
}

res, err := queryClient.LiquidityPool(cmd.Context(), &types.QueryLiquidityPoolRequest{
LptDenom: lptDenom,
})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
Loading

0 comments on commit 37b9b93

Please sign in to comment.