0g-chain/x/auction/client/cli/tx.go
Denali Marsh d286f53053
R4R: cli auction clean up (#310)
* kvcli q auction params

* reset go.sum

* Updated QueryGetAuctionsCmd naming to match conventions

* clean up: tx auctions placebid

* requested changes
2020-01-16 18:52:29 +01:00

64 lines
1.7 KiB
Go

package cli
import (
"fmt"
"strconv"
"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 placing bids on auctions
func GetCmdPlaceBid(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "placebid [auction-id] [amount]",
Short: "place a bid on an auction",
Args: cobra.MinimumNArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
id, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
fmt.Printf("invalid auction id - %s \n", string(args[0]))
return err
}
amt, err := sdk.ParseCoin(args[2])
if err != nil {
fmt.Printf("invalid amount - %s \n", string(args[2]))
return err
}
msg := types.NewMsgPlaceBid(id, cliCtx.GetFromAddress(), amt)
err = msg.ValidateBasic()
if err != nil {
return err
}
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
}