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

64 lines
1.7 KiB
Go
Raw Normal View History

2019-11-25 19:46:02 +00:00
package cli
import (
"fmt"
2020-01-01 14:11:19 +00:00
"strconv"
2019-11-25 19:46:02 +00:00
"github.com/kava-labs/kava/x/auction/types"
"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"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
)
// GetTxCmd returns the transaction commands for this module
// TODO: Tests, see: https://github.com/cosmos/cosmos-sdk/blob/18de630d0ae1887113e266982b51c2bf1f662edb/x/staking/client/cli/tx_test.go
func GetTxCmd(cdc *codec.Codec) *cobra.Command {
auctionTxCmd := &cobra.Command{
Use: "auction",
Short: "auction transactions subcommands",
}
auctionTxCmd.AddCommand(client.PostCommands(
GetCmdPlaceBid(cdc),
)...)
return auctionTxCmd
}
// GetCmdPlaceBid cli command for creating and modifying cdps.
func GetCmdPlaceBid(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "placebid [auctionID] [amount]",
2019-11-25 19:46:02 +00:00
Short: "place a bid on an auction",
Args: cobra.MinimumNArgs(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-01 14:11:19 +00:00
id, err := strconv.ParseUint(args[0], 10, 64)
2019-11-25 19:46:02 +00:00
if err != nil {
fmt.Printf("invalid auction id - %s \n", string(args[0]))
return err
}
amt, err := sdk.ParseCoin(args[2])
2019-11-25 19:46:02 +00:00
if err != nil {
fmt.Printf("invalid amount - %s \n", string(args[2]))
2019-11-25 19:46:02 +00:00
return err
}
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})
},
}
}