mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-25 15:55:18 +00:00
R4R: cli auction clean up (#310)
* kvcli q auction params * reset go.sum * Updated QueryGetAuctionsCmd naming to match conventions * clean up: tx auctions placebid * requested changes
This commit is contained in:
parent
c5043ffabe
commit
d286f53053
@ -20,20 +20,21 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auctionQueryCmd.AddCommand(client.GetCommands(
|
auctionQueryCmd.AddCommand(client.GetCommands(
|
||||||
GetCmdGetAuctions(queryRoute, cdc),
|
QueryGetAuctionsCmd(queryRoute, cdc),
|
||||||
|
QueryParamsCmd(queryRoute, cdc),
|
||||||
)...)
|
)...)
|
||||||
|
|
||||||
return auctionQueryCmd
|
return auctionQueryCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCmdGetAuctions queries the auctions in the store
|
// QueryGetAuctionsCmd queries the auctions in the store
|
||||||
func GetCmdGetAuctions(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
func QueryGetAuctionsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "getauctions",
|
Use: "auctions",
|
||||||
Short: "get a list of active auctions",
|
Short: "get a list of active auctions",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||||
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/getauctions", queryRoute), nil)
|
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/auctions", queryRoute), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("error when getting auctions - %s", err)
|
fmt.Printf("error when getting auctions - %s", err)
|
||||||
return nil
|
return nil
|
||||||
@ -47,3 +48,28 @@ func GetCmdGetAuctions(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -30,10 +30,10 @@ func GetTxCmd(cdc *codec.Codec) *cobra.Command {
|
|||||||
return auctionTxCmd
|
return auctionTxCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCmdPlaceBid cli command for creating and modifying cdps.
|
// GetCmdPlaceBid cli command for placing bids on auctions
|
||||||
func GetCmdPlaceBid(cdc *codec.Codec) *cobra.Command {
|
func GetCmdPlaceBid(cdc *codec.Codec) *cobra.Command {
|
||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "placebid [auctionID] [amount]",
|
Use: "placebid [auction-id] [amount]",
|
||||||
Short: "place a bid on an auction",
|
Short: "place a bid on an auction",
|
||||||
Args: cobra.MinimumNArgs(2),
|
Args: cobra.MinimumNArgs(2),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
@ -8,13 +8,13 @@ import (
|
|||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client/context"
|
"github.com/cosmos/cosmos-sdk/client/context"
|
||||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||||
)
|
|
||||||
|
|
||||||
// r.HandleFunc(fmt.Sprintf("/auction/bid/{%s}/{%s}/{%s}/{%s}", restAuctionID, restBidder, restBid, restLot), bidHandlerFn(cdc, cliCtx)).Methods("PUT")
|
"github.com/kava-labs/kava/x/auction/types"
|
||||||
|
)
|
||||||
|
|
||||||
func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) {
|
func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) {
|
||||||
r.HandleFunc(fmt.Sprintf("/auction/getauctions"), queryGetAuctionsHandlerFn(cliCtx)).Methods("GET")
|
r.HandleFunc(fmt.Sprintf("/auction/getauctions"), queryGetAuctionsHandlerFn(cliCtx)).Methods("GET")
|
||||||
|
r.HandleFunc("/auction/params", getParamsHandlerFn(cliCtx)).Methods("GET")
|
||||||
}
|
}
|
||||||
|
|
||||||
func queryGetAuctionsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
func queryGetAuctionsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
@ -28,3 +28,17 @@ func queryGetAuctionsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|||||||
rest.PostProcessResponse(w, cliCtx, res)
|
rest.PostProcessResponse(w, cliCtx, res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// Get the params
|
||||||
|
res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/auction/%s", types.QueryGetParams), nil)
|
||||||
|
cliCtx = cliCtx.WithHeight(height)
|
||||||
|
if err != nil {
|
||||||
|
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Return the params
|
||||||
|
rest.PostProcessResponse(w, cliCtx, res)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -13,6 +13,8 @@ func NewQuerier(keeper Keeper) sdk.Querier {
|
|||||||
switch path[0] {
|
switch path[0] {
|
||||||
case types.QueryGetAuction:
|
case types.QueryGetAuction:
|
||||||
return queryAuctions(ctx, req, keeper)
|
return queryAuctions(ctx, req, keeper)
|
||||||
|
case types.QueryGetParams:
|
||||||
|
return queryGetParams(ctx, req, keeper)
|
||||||
default:
|
default:
|
||||||
return nil, sdk.ErrUnknownRequest("unknown auction query endpoint")
|
return nil, sdk.ErrUnknownRequest("unknown auction query endpoint")
|
||||||
}
|
}
|
||||||
@ -34,3 +36,16 @@ func queryAuctions(ctx sdk.Context, req abci.RequestQuery, keeper Keeper) (res [
|
|||||||
|
|
||||||
return bz, nil
|
return bz, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// query params in the auction store
|
||||||
|
func queryGetParams(ctx sdk.Context, req abci.RequestQuery, keeper Keeper) ([]byte, sdk.Error) {
|
||||||
|
// Get params
|
||||||
|
params := keeper.GetParams(ctx)
|
||||||
|
|
||||||
|
// Encode results
|
||||||
|
bz, err := codec.MarshalJSONIndent(keeper.cdc, params)
|
||||||
|
if err != nil {
|
||||||
|
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err.Error()))
|
||||||
|
}
|
||||||
|
return bz, nil
|
||||||
|
}
|
||||||
|
@ -6,7 +6,8 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// QueryGetAuction command for getting the information about a particular auction
|
// QueryGetAuction command for getting the information about a particular auction
|
||||||
QueryGetAuction = "getauctions"
|
QueryGetAuction = "auctions"
|
||||||
|
QueryGetParams = "params"
|
||||||
)
|
)
|
||||||
|
|
||||||
// QueryResAuctions Result Payload for an auctions query
|
// QueryResAuctions Result Payload for an auctions query
|
||||||
|
Loading…
Reference in New Issue
Block a user