0g-chain/x/auction/client/cli/tx.go

72 lines
1.8 KiB
Go
Raw Normal View History

2019-11-25 19:46:02 +00:00
package cli
import (
"fmt"
"strconv"
2019-11-25 19:46:02 +00:00
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
2019-11-25 19:46:02 +00:00
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/kava-labs/kava/x/auction/types"
2019-11-25 19:46:02 +00:00
)
// GetTxCmd returns the transaction cli commands for this module
func GetTxCmd() *cobra.Command {
txCmd := &cobra.Command{
Use: types.ModuleName,
Short: "transaction commands for the auction module",
2019-11-25 19:46:02 +00:00
}
cmds := []*cobra.Command{
GetCmdPlaceBid(),
}
for _, cmd := range cmds {
flags.AddTxFlagsToCmd(cmd)
}
txCmd.AddCommand(cmds...)
return txCmd
2019-11-25 19:46:02 +00:00
}
// GetCmdPlaceBid cli command for placing bids on auctions
func GetCmdPlaceBid() *cobra.Command {
2019-11-25 19:46:02 +00:00
return &cobra.Command{
Use: "bid [auction-id] [amount]",
Short: "place a bid on an auction",
Long: "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: fmt.Sprintf(" $ %s tx %s bid 34 1000usdx --from myKeyName", version.AppName, types.ModuleName),
Args: cobra.ExactArgs(2),
2019-11-25 19:46:02 +00:00
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
2019-11-25 19:46:02 +00:00
id, err := strconv.ParseUint(args[0], 10, 64)
2019-11-25 19:46:02 +00:00
if err != nil {
return fmt.Errorf("auction-id '%s' not a valid uint", args[0])
2019-11-25 19:46:02 +00:00
}
amt, err := sdk.ParseCoinNormalized(args[1])
2019-11-25 19:46:02 +00:00
if err != nil {
return err
}
msg := types.NewMsgPlaceBid(id, clientCtx.GetFromAddress().String(), amt)
2019-11-25 19:46:02 +00:00
err = msg.ValidateBasic()
if err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
2019-11-25 19:46:02 +00:00
},
}
}