0g-chain/x/auction/client/cli/tx.go
Ruaridh e1c11d411a Update Auction Module (#276)
* rough auction type refactor

* replace endTime type

* split keeper file up

* update store methods

* move store methods to keeper.go

* move nextAuctionID from params to genState

* simplify auction type to not use pointers

* add basic auction tests

* update endblocker test

* add payout to depositors feature

* add more tests

* move index updates to Get/Set for more safety

* remove slightly unecessary ID type

* remove unused message types

* feat: add spec, update redundant type names

* stop sending zero coins

* use only one coins field in MsgPlaceBid

* remove uncessary Auction interface methods

* give auction types more accurate names

* remove vuepress comments from spec

* minor spec updates

* update doc comments

* add params validation

* code cleanup, address review comments

* resolve minor TODOs

* sync spec with code

Co-authored-by: Kevin Davis <karzak@users.noreply.github.com>
2020-01-12 16:12:22 +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 creating and modifying cdps.
func GetCmdPlaceBid(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "placebid [auctionID] [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})
},
}
}