0g-chain/x/auction/client/cli/query.go
2019-11-25 14:46:02 -05:00

50 lines
1.3 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/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(
GetCmdGetAuctions(queryRoute, cdc),
)...)
return auctionQueryCmd
}
// GetCmdGetAuctions queries the auctions in the store
func GetCmdGetAuctions(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "getauctions",
Short: "get a list of active auctions",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/getauctions", queryRoute), nil)
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)
},
}
}