2019-11-25 19:46:02 +00:00
package cli
import (
"fmt"
2020-01-12 15:12:22 +00:00
"strconv"
2019-11-25 19:46:02 +00:00
"github.com/spf13/cobra"
2022-01-08 00:39:27 +00:00
"github.com/cosmos/cosmos-sdk/client"
2020-04-23 16:35:58 +00:00
"github.com/cosmos/cosmos-sdk/client/flags"
2022-01-08 00:39:27 +00:00
"github.com/cosmos/cosmos-sdk/client/tx"
2019-11-25 19:46:02 +00:00
sdk "github.com/cosmos/cosmos-sdk/types"
2020-01-21 17:41:37 +00:00
"github.com/cosmos/cosmos-sdk/version"
"github.com/kava-labs/kava/x/auction/types"
2019-11-25 19:46:02 +00:00
)
2022-01-08 00:39:27 +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
}
2022-01-08 00:39:27 +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
}
2020-01-16 17:52:29 +00:00
// GetCmdPlaceBid cli command for placing bids on auctions
2022-01-08 00:39:27 +00:00
func GetCmdPlaceBid ( ) * cobra . Command {
2019-11-25 19:46:02 +00:00
return & cobra . Command {
2022-01-08 00:39:27 +00:00
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 {
2022-01-08 00:39:27 +00:00
clientCtx , err := client . GetClientTxContext ( cmd )
if err != nil {
return err
}
2019-11-25 19:46:02 +00:00
2020-01-12 15:12:22 +00:00
id , err := strconv . ParseUint ( args [ 0 ] , 10 , 64 )
2019-11-25 19:46:02 +00:00
if err != nil {
2020-01-21 17:41:37 +00:00
return fmt . Errorf ( "auction-id '%s' not a valid uint" , args [ 0 ] )
2019-11-25 19:46:02 +00:00
}
2022-01-08 00:39:27 +00:00
amt , err := sdk . ParseCoinNormalized ( args [ 1 ] )
2019-11-25 19:46:02 +00:00
if err != nil {
return err
}
2022-01-08 00:39:27 +00:00
msg := types . NewMsgPlaceBid ( id , clientCtx . GetFromAddress ( ) . String ( ) , amt )
2019-11-25 19:46:02 +00:00
err = msg . ValidateBasic ( )
if err != nil {
return err
}
2022-01-08 00:39:27 +00:00
return tx . GenerateOrBroadcastTxCLI ( clientCtx , cmd . Flags ( ) , & msg )
2019-11-25 19:46:02 +00:00
} ,
}
}