From d32e37355260ee1f91418a7ebc0f2856d2b47727 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 15 May 2024 00:03:25 +0200 Subject: [PATCH 1/2] feat(auction): add cli --- x/auction/client/cli/query.go | 90 +++++++++++++++++++++++++++++++++++ x/auction/client/cli/tx.go | 62 ++++++++++++++++++++++++ x/auction/module/module.go | 8 ++-- x/uibc/client/cli/query.go | 1 + x/uibc/client/cli/tx.go | 1 + 5 files changed, 157 insertions(+), 5 deletions(-) create mode 100644 x/auction/client/cli/query.go create mode 100644 x/auction/client/cli/tx.go diff --git a/x/auction/client/cli/query.go b/x/auction/client/cli/query.go new file mode 100644 index 0000000000..6113037869 --- /dev/null +++ b/x/auction/client/cli/query.go @@ -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 +} diff --git a/x/auction/client/cli/tx.go b/x/auction/client/cli/tx.go new file mode 100644 index 0000000000..4cfd09d09a --- /dev/null +++ b/x/auction/client/cli/tx.go @@ -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 rewords 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 +} diff --git a/x/auction/module/module.go b/x/auction/module/module.go index 30f662d410..6bb6a4ff9b 100644 --- a/x/auction/module/module.go +++ b/x/auction/module/module.go @@ -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 ( @@ -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. diff --git a/x/uibc/client/cli/query.go b/x/uibc/client/cli/query.go index 183d3b4f88..0cdcba50a2 100644 --- a/x/uibc/client/cli/query.go +++ b/x/uibc/client/cli/query.go @@ -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" ) diff --git a/x/uibc/client/cli/tx.go b/x/uibc/client/cli/tx.go index 54624bf9e2..f82fa0a88c 100644 --- a/x/uibc/client/cli/tx.go +++ b/x/uibc/client/cli/tx.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" + "github.com/umee-network/umee/v6/x/uibc" ) From 411ae096a71579b2f5c417deeddd672fc8d02440 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 15 May 2024 00:11:09 +0200 Subject: [PATCH 2/2] Update x/auction/client/cli/tx.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- x/auction/client/cli/tx.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/auction/client/cli/tx.go b/x/auction/client/cli/tx.go index 4cfd09d09a..c39fbab9c5 100644 --- a/x/auction/client/cli/tx.go +++ b/x/auction/client/cli/tx.go @@ -34,7 +34,7 @@ func RewardsBid() *cobra.Command { cmd := &cobra.Command{ Use: "rewards-bid [auction-id] [uumee-amount]", Args: cobra.ExactArgs(2), - Short: "Places a bid for a rewords auction, auction-id must be an ID of the current auction", + 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)