mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 18:15:19 +00:00
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
|
package cli
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/spf13/cobra"
|
||
|
|
||
|
"github.com/cosmos/cosmos-sdk/client"
|
||
|
"github.com/cosmos/cosmos-sdk/client/context"
|
||
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
||
|
"github.com/cosmos/cosmos-sdk/codec"
|
||
|
|
||
|
"github.com/kava-labs/kava/x/swap/types"
|
||
|
)
|
||
|
|
||
|
// GetQueryCmd returns the cli query commands for the module
|
||
|
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||
|
swapQueryCmd := &cobra.Command{
|
||
|
Use: types.ModuleName,
|
||
|
Short: "Querying commands for the swap module",
|
||
|
DisableFlagParsing: true,
|
||
|
SuggestionsMinimumDistance: 2,
|
||
|
RunE: client.ValidateCmd,
|
||
|
}
|
||
|
|
||
|
swapQueryCmd.AddCommand(flags.GetCommands(
|
||
|
queryParamsCmd(queryRoute, cdc),
|
||
|
)...)
|
||
|
|
||
|
return swapQueryCmd
|
||
|
}
|
||
|
|
||
|
func queryParamsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||
|
return &cobra.Command{
|
||
|
Use: "params",
|
||
|
Short: "get the swap module parameters",
|
||
|
Long: "Get the current global swap module parameters.",
|
||
|
Args: cobra.NoArgs,
|
||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||
|
|
||
|
// Query
|
||
|
route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryGetParams)
|
||
|
res, height, err := cliCtx.QueryWithData(route, nil)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
cliCtx = cliCtx.WithHeight(height)
|
||
|
|
||
|
// Decode and print results
|
||
|
var params types.Params
|
||
|
if err := cdc.UnmarshalJSON(res, ¶ms); err != nil {
|
||
|
return fmt.Errorf("failed to unmarshal params: %w", err)
|
||
|
}
|
||
|
return cliCtx.PrintOutput(params)
|
||
|
},
|
||
|
}
|
||
|
}
|