2019-11-25 19:46:02 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-01-12 15:12:22 +00:00
|
|
|
"strconv"
|
2020-01-21 17:41:37 +00:00
|
|
|
"strings"
|
2019-11-25 19:46:02 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-01-21 17:41:37 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/version"
|
2019-11-25 19:46:02 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
|
2020-01-21 17:41:37 +00:00
|
|
|
|
|
|
|
"github.com/kava-labs/kava/x/auction/types"
|
2019-11-25 19:46:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// GetTxCmd returns the transaction commands for this module
|
|
|
|
func GetTxCmd(cdc *codec.Codec) *cobra.Command {
|
|
|
|
auctionTxCmd := &cobra.Command{
|
|
|
|
Use: "auction",
|
|
|
|
Short: "auction transactions subcommands",
|
|
|
|
}
|
|
|
|
|
|
|
|
auctionTxCmd.AddCommand(client.PostCommands(
|
|
|
|
GetCmdPlaceBid(cdc),
|
|
|
|
)...)
|
|
|
|
|
|
|
|
return auctionTxCmd
|
|
|
|
}
|
|
|
|
|
2020-01-16 17:52:29 +00:00
|
|
|
// GetCmdPlaceBid cli command for placing bids on auctions
|
2019-11-25 19:46:02 +00:00
|
|
|
func GetCmdPlaceBid(cdc *codec.Codec) *cobra.Command {
|
|
|
|
return &cobra.Command{
|
2020-01-21 17:41:37 +00:00
|
|
|
Use: "bid [auction-id] [amount]",
|
2019-11-25 19:46:02 +00:00
|
|
|
Short: "place a bid on an auction",
|
2020-01-21 17:41:37 +00:00
|
|
|
Long: strings.TrimSpace(
|
|
|
|
fmt.Sprintf(`Place a bid on any type of auction, updating the latest bid amount to [amount]. Collateral auctions must be bid up to their maxbid before entering reverse phase.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
$ %s tx %s bid 34 1000usdx --from myKeyName
|
|
|
|
`, version.ClientName, types.ModuleName)),
|
|
|
|
Args: cobra.ExactArgs(2),
|
2019-11-25 19:46:02 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
|
|
|
|
|
2020-01-12 15:12:22 +00:00
|
|
|
id, err := strconv.ParseUint(args[0], 10, 64)
|
2019-11-25 19:46:02 +00:00
|
|
|
if err != nil {
|
2020-01-21 17:41:37 +00:00
|
|
|
return fmt.Errorf("auction-id '%s' not a valid uint", args[0])
|
2019-11-25 19:46:02 +00:00
|
|
|
}
|
|
|
|
|
2020-01-21 17:41:37 +00:00
|
|
|
amt, err := sdk.ParseCoin(args[1])
|
2019-11-25 19:46:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-01-12 15:12:22 +00:00
|
|
|
msg := types.NewMsgPlaceBid(id, cliCtx.GetFromAddress(), amt)
|
2019-11-25 19:46:02 +00:00
|
|
|
err = msg.ValidateBasic()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|