-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
efdb6d4
commit 3fdf9d3
Showing
5 changed files
with
157 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters