Update create auction CLI command
This commit is contained in:
parent
0defde75ee
commit
3d237f6447
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"cosmossdk.io/math"
|
"cosmossdk.io/math"
|
||||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
|
||||||
integrationTest "git.vdb.to/cerc-io/laconicd/tests/integration"
|
integrationTest "git.vdb.to/cerc-io/laconicd/tests/integration"
|
||||||
types "git.vdb.to/cerc-io/laconicd/x/auction"
|
types "git.vdb.to/cerc-io/laconicd/x/auction"
|
||||||
@ -331,7 +332,19 @@ func (kts *KeeperTestSuite) createAuctionAndCommitBid(commitBid bool) (*types.Au
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
auction, err := k.CreateAuction(ctx, types.NewMsgCreateAuction(*params, accounts[0]))
|
auction, err := k.CreateAuction(
|
||||||
|
ctx,
|
||||||
|
types.NewMsgCreateAuction(
|
||||||
|
params.CommitsDuration,
|
||||||
|
params.RevealsDuration,
|
||||||
|
params.CommitFee,
|
||||||
|
params.RevealFee,
|
||||||
|
params.MinimumBid,
|
||||||
|
sdk.Coin{},
|
||||||
|
types.AuctionKindVickrey,
|
||||||
|
accounts[0],
|
||||||
|
),
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -132,9 +132,9 @@ func GetCmdRevealBid() *cobra.Command {
|
|||||||
|
|
||||||
func GetCmdCreateAuction() *cobra.Command {
|
func GetCmdCreateAuction() *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "create [commits-duration] [reveals-duration] [commit-fee] [reveal-fee] [minimum-bid]",
|
Use: "create [commits-duration] [reveals-duration] [commit-fee] [reveal-fee] [minimum-bid] [maximum-bid] [reverse]",
|
||||||
Short: "Create auction.",
|
Short: "Create auction.",
|
||||||
Args: cobra.ExactArgs(5),
|
Args: cobra.ExactArgs(7),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
clientCtx, err := client.GetClientTxContext(cmd)
|
clientCtx, err := client.GetClientTxContext(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -166,14 +166,23 @@ func GetCmdCreateAuction() *cobra.Command {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
params := auctiontypes.Params{
|
maximumBid, err := sdk.ParseCoinNormalized(args[5])
|
||||||
CommitsDuration: commitsDuration,
|
if err != nil {
|
||||||
RevealsDuration: revealsDuration,
|
return err
|
||||||
CommitFee: commitFee,
|
|
||||||
RevealFee: revealFee,
|
|
||||||
MinimumBid: minimumBid,
|
|
||||||
}
|
}
|
||||||
msg := auctiontypes.NewMsgCreateAuction(params, clientCtx.GetFromAddress())
|
|
||||||
|
kind := args[6]
|
||||||
|
|
||||||
|
msg := auctiontypes.NewMsgCreateAuction(
|
||||||
|
commitsDuration,
|
||||||
|
revealsDuration,
|
||||||
|
commitFee,
|
||||||
|
revealFee,
|
||||||
|
minimumBid,
|
||||||
|
maximumBid,
|
||||||
|
kind,
|
||||||
|
clientCtx.GetFromAddress(),
|
||||||
|
)
|
||||||
err = msg.ValidateBasic()
|
err = msg.ValidateBasic()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package auction
|
package auction
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
time "time"
|
||||||
|
|
||||||
errorsmod "cosmossdk.io/errors"
|
errorsmod "cosmossdk.io/errors"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
@ -13,13 +16,25 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// NewMsgCreateAuction is the constructor function for MsgCreateAuction.
|
// NewMsgCreateAuction is the constructor function for MsgCreateAuction.
|
||||||
func NewMsgCreateAuction(params Params, signer sdk.AccAddress) MsgCreateAuction {
|
func NewMsgCreateAuction(
|
||||||
|
commitsDuration time.Duration,
|
||||||
|
revealsDuration time.Duration,
|
||||||
|
commitFee sdk.Coin,
|
||||||
|
revealFee sdk.Coin,
|
||||||
|
minimumBid sdk.Coin,
|
||||||
|
maxPrice sdk.Coin,
|
||||||
|
kind string,
|
||||||
|
signer sdk.AccAddress,
|
||||||
|
) MsgCreateAuction {
|
||||||
|
fmt.Print(signer.String())
|
||||||
return MsgCreateAuction{
|
return MsgCreateAuction{
|
||||||
CommitsDuration: params.CommitsDuration,
|
CommitsDuration: commitsDuration,
|
||||||
RevealsDuration: params.RevealsDuration,
|
RevealsDuration: revealsDuration,
|
||||||
CommitFee: params.CommitFee,
|
CommitFee: commitFee,
|
||||||
RevealFee: params.RevealFee,
|
RevealFee: revealFee,
|
||||||
MinimumBid: params.MinimumBid,
|
MinimumBid: minimumBid,
|
||||||
|
MaxPrice: maxPrice,
|
||||||
|
Kind: kind,
|
||||||
Signer: signer.String(),
|
Signer: signer.String(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,10 +62,14 @@ func (msg MsgCreateAuction) ValidateBasic() error {
|
|||||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "reveal phase duration invalid.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "reveal phase duration invalid.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !msg.MinimumBid.IsPositive() {
|
if msg.Kind == AuctionKindVickrey && !msg.MinimumBid.IsPositive() {
|
||||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "minimum bid should be greater than zero.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "minimum bid should be greater than zero.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if msg.Kind == AuctionKindServiceProvider && !msg.MaxPrice.IsPositive() {
|
||||||
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "maximum price should be greater than zero.")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"cosmossdk.io/math"
|
||||||
|
|
||||||
"cosmossdk.io/collections"
|
"cosmossdk.io/collections"
|
||||||
errorsmod "cosmossdk.io/errors"
|
errorsmod "cosmossdk.io/errors"
|
||||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||||
@ -285,16 +287,17 @@ func (k Keeper) createAuthority(ctx sdk.Context, name string, owner string, isRo
|
|||||||
// Reset bond ID if required.
|
// Reset bond ID if required.
|
||||||
authority.BondId = ""
|
authority.BondId = ""
|
||||||
|
|
||||||
params := auctiontypes.Params{
|
|
||||||
CommitsDuration: moduleParams.AuthorityAuctionCommitsDuration,
|
|
||||||
RevealsDuration: moduleParams.AuthorityAuctionRevealsDuration,
|
|
||||||
CommitFee: moduleParams.AuthorityAuctionCommitFee,
|
|
||||||
RevealFee: moduleParams.AuthorityAuctionRevealFee,
|
|
||||||
MinimumBid: moduleParams.AuthorityAuctionMinimumBid,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create an auction.
|
// Create an auction.
|
||||||
msg := auctiontypes.NewMsgCreateAuction(params, ownerAddress)
|
msg := auctiontypes.NewMsgCreateAuction(
|
||||||
|
moduleParams.AuthorityAuctionCommitsDuration,
|
||||||
|
moduleParams.AuthorityAuctionRevealsDuration,
|
||||||
|
moduleParams.AuthorityAuctionCommitFee,
|
||||||
|
moduleParams.AuthorityAuctionRevealFee,
|
||||||
|
moduleParams.AuthorityAuctionMinimumBid,
|
||||||
|
sdk.NewCoin("alnt", math.NewInt(0)),
|
||||||
|
auctiontypes.AuctionKindVickrey,
|
||||||
|
ownerAddress,
|
||||||
|
)
|
||||||
|
|
||||||
auction, sdkErr := k.auctionKeeper.CreateAuction(ctx, msg)
|
auction, sdkErr := k.auctionKeeper.CreateAuction(ctx, msg)
|
||||||
if sdkErr != nil {
|
if sdkErr != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user