forked from Canto-Network/Canto
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reverts commit fad4908.
- Loading branch information
Showing
28 changed files
with
1,867 additions
and
378 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.