2019-11-25 19:46:02 +00:00
|
|
|
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/codec"
|
|
|
|
"github.com/kava-labs/kava/x/auction/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetQueryCmd returns the cli query commands for this module
|
|
|
|
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|
|
|
// Group nameservice queries under a subcommand
|
|
|
|
auctionQueryCmd := &cobra.Command{
|
|
|
|
Use: "auction",
|
|
|
|
Short: "Querying commands for the auction module",
|
|
|
|
}
|
|
|
|
|
|
|
|
auctionQueryCmd.AddCommand(client.GetCommands(
|
2020-01-16 17:52:29 +00:00
|
|
|
QueryGetAuctionsCmd(queryRoute, cdc),
|
|
|
|
QueryParamsCmd(queryRoute, cdc),
|
2019-11-25 19:46:02 +00:00
|
|
|
)...)
|
|
|
|
|
|
|
|
return auctionQueryCmd
|
|
|
|
}
|
|
|
|
|
2020-01-16 17:52:29 +00:00
|
|
|
// QueryGetAuctionsCmd queries the auctions in the store
|
|
|
|
func QueryGetAuctionsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
2019-11-25 19:46:02 +00:00
|
|
|
return &cobra.Command{
|
2020-01-16 17:52:29 +00:00
|
|
|
Use: "auctions",
|
2019-11-25 19:46:02 +00:00
|
|
|
Short: "get a list of active auctions",
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
2020-01-16 17:52:29 +00:00
|
|
|
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/auctions", queryRoute), nil)
|
2019-11-25 19:46:02 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("error when getting auctions - %s", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var out types.QueryResAuctions
|
|
|
|
cdc.MustUnmarshalJSON(res, &out)
|
|
|
|
if len(out) == 0 {
|
|
|
|
out = append(out, "There are currently no auctions")
|
|
|
|
}
|
|
|
|
return cliCtx.PrintOutput(out)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2020-01-16 17:52:29 +00:00
|
|
|
|
|
|
|
// QueryParamsCmd queries the auction module parameters
|
|
|
|
func QueryParamsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|
|
|
return &cobra.Command{
|
|
|
|
Use: "params",
|
|
|
|
Short: "get the auction module parameters",
|
|
|
|
Long: "Get the current global auction 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, _, err := cliCtx.QueryWithData(route, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decode and print results
|
|
|
|
var out types.Params
|
|
|
|
cdc.MustUnmarshalJSON(res, &out)
|
|
|
|
return cliCtx.PrintOutput(out)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|