Skip to content

Commit

Permalink
feat(auction): add cli (#2521)
Browse files Browse the repository at this point in the history
* feat(auction): add cli

* Update x/auction/client/cli/tx.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
robert-zaremba and coderabbitai[bot] authored May 15, 2024
1 parent efdb6d4 commit 3fdf9d3
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 5 deletions.
90 changes: 90 additions & 0 deletions x/auction/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package cli

import (
"errors"
"fmt"
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"

"github.com/umee-network/umee/v6/util/cli"
"github.com/umee-network/umee/v6/x/auction"
)

// GetQueryCmd returns the CLI query commands for the x/auction module.
func GetQueryCmd() *cobra.Command {
cmd := &cobra.Command{
Use: auction.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", auction.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

cmd.AddCommand(
RewardsParams(),
RewardsAuction(),
)

return cmd
}

func RewardsParams() *cobra.Command {
cmd := &cobra.Command{
Use: "rewards-params",
Args: cobra.NoArgs,
Short: "Query x/auction rewards params",
RunE: func(cmd *cobra.Command, args []string) error {
cctx, q, err := prepareQueryCtx(cmd)
if err != nil {
return err
}

req := &auction.QueryRewardsParams{}
resp, err := q.RewardsParams(cmd.Context(), req)
return cli.PrintOrErr(resp, err, cctx)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

func RewardsAuction() *cobra.Command {
cmd := &cobra.Command{
Use: "rewards-auction [id]",
Args: cobra.MaximumNArgs(1),
Short: "Query rewards auction state",
RunE: func(cmd *cobra.Command, args []string) error {
cctx, q, err := prepareQueryCtx(cmd)
if err != nil {
return err
}

req := auction.QueryRewardsAuction{}
if len(args) > 0 {
id, err := strconv.ParseInt(args[0], 10, 32)
if err != nil || id < 0 {
return errors.New("id argument must be a positive integer")
}
req.Id = uint32(id)
}
resp, err := q.RewardsAuction(cmd.Context(), &req)
return cli.PrintOrErr(resp, err, cctx)
},
}

flags.AddQueryFlagsToCmd(cmd)
return cmd
}

func prepareQueryCtx(cmd *cobra.Command) (client.Context, auction.QueryClient, error) {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return clientCtx, nil, err
}
return clientCtx, auction.NewQueryClient(clientCtx), err
}
62 changes: 62 additions & 0 deletions x/auction/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package cli

import (
"errors"
"fmt"
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/cobra"

"github.com/umee-network/umee/v6/x/auction"
)

// GetTxCmd returns the CLI transaction commands for the x/auction module.
func GetTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: auction.ModuleName,
Short: fmt.Sprintf("Transaction commands for the %s module", auction.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
cmd.AddCommand(
RewardsBid(),
)

return cmd
}

func RewardsBid() *cobra.Command {
cmd := &cobra.Command{
Use: "rewards-bid [auction-id] [uumee-amount]",
Args: cobra.ExactArgs(2),
Short: "Places a bid for a rewards auction, auction-id must be an ID of the current auction",
Example: "rewards-bid 12 10000uumee",
RunE: func(cmd *cobra.Command, args []string) error {
cctx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
id, err := strconv.ParseInt(args[0], 10, 32)
if err != nil || id < 0 {
return errors.New("id argument must be a positive integer")
}
coin, err := sdk.ParseCoinNormalized(args[1])
if err != nil {
return err
}
msg := auction.MsgRewardsBid{
Sender: cctx.GetFromAddress().String(),
Id: uint32(id),
Amount: coin}
return tx.GenerateOrBroadcastTxCLI(cctx, cmd.Flags(), &msg)
},
}

flags.AddTxFlagsToCmd(cmd)
return cmd
}
8 changes: 3 additions & 5 deletions x/auction/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (

"github.com/umee-network/umee/v6/util"
"github.com/umee-network/umee/v6/x/auction"
"github.com/umee-network/umee/v6/x/auction/client/cli"
"github.com/umee-network/umee/v6/x/auction/keeper"
// "github.com/umee-network/umee/v6/x/auction/client/cli"
)

var (
Expand Down Expand Up @@ -81,14 +81,12 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r

// GetTxCmd returns the x/auction module's root tx command.
func (a AppModuleBasic) GetTxCmd() *cobra.Command {
// TODO return cli.GetTxCmd()
return nil
return cli.GetTxCmd()
}

// GetQueryCmd returns the x/auction module's root query command.
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
// TODO return cli.GetQueryCmd()
return nil
return cli.GetQueryCmd()
}

// AppModule implements the AppModule interface for the x/auction module.
Expand Down
1 change: 1 addition & 0 deletions x/uibc/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"

"github.com/umee-network/umee/v6/util/cli"
"github.com/umee-network/umee/v6/x/uibc"
)
Expand Down
1 change: 1 addition & 0 deletions x/uibc/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/cosmos/cosmos-sdk/client"
"github.com/spf13/cobra"

"github.com/umee-network/umee/v6/x/uibc"
)

Expand Down

0 comments on commit 3fdf9d3

Please sign in to comment.