mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 18:15:19 +00:00
a573625df8
* bump SDK version to v0.38.3 Co-authored-by: Denali Marsh <denali@kava.io> Co-authored-by: Kevin Davis <kjydavis3@gmail.com> Co-authored-by: Kevin Davis <karzak@users.noreply.github.com> Co-authored-by: denalimarsh <denalimarsh@gmail.com> Co-authored-by: rhuairahrighairigh <ruaridh.odonnell@gmail.com>
72 lines
1.9 KiB
Go
72 lines
1.9 KiB
Go
package cli
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/version"
|
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
|
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
|
|
|
|
"github.com/kava-labs/kava/x/auction/types"
|
|
)
|
|
|
|
// 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(flags.PostCommands(
|
|
GetCmdPlaceBid(cdc),
|
|
)...)
|
|
|
|
return auctionTxCmd
|
|
}
|
|
|
|
// GetCmdPlaceBid cli command for placing bids on auctions
|
|
func GetCmdPlaceBid(cdc *codec.Codec) *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "bid [auction-id] [amount]",
|
|
Short: "place a bid on an auction",
|
|
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),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
inBuf := bufio.NewReader(cmd.InOrStdin())
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
|
|
|
|
id, err := strconv.ParseUint(args[0], 10, 64)
|
|
if err != nil {
|
|
return fmt.Errorf("auction-id '%s' not a valid uint", args[0])
|
|
}
|
|
|
|
amt, err := sdk.ParseCoin(args[1])
|
|
if err != nil {
|
|
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})
|
|
},
|
|
}
|
|
}
|