Add service provider auctions #59
@ -6,6 +6,7 @@ import (
|
||||
|
||||
"cosmossdk.io/math"
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
integrationTest "git.vdb.to/cerc-io/laconicd/tests/integration"
|
||||
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
|
||||
}
|
||||
|
||||
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 {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
@ -132,9 +132,9 @@ func GetCmdRevealBid() *cobra.Command {
|
||||
|
||||
func GetCmdCreateAuction() *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.",
|
||||
Args: cobra.ExactArgs(5),
|
||||
Args: cobra.ExactArgs(7),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
@ -166,14 +166,23 @@ func GetCmdCreateAuction() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
params := auctiontypes.Params{
|
||||
CommitsDuration: commitsDuration,
|
||||
RevealsDuration: revealsDuration,
|
||||
CommitFee: commitFee,
|
||||
RevealFee: revealFee,
|
||||
MinimumBid: minimumBid,
|
||||
maximumBid, err := sdk.ParseCoinNormalized(args[5])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg := auctiontypes.NewMsgCreateAuction(params, clientCtx.GetFromAddress())
|
||||
|
||||
kind := args[6]
|
||||
|
||||
msg := auctiontypes.NewMsgCreateAuction(
|
||||
commitsDuration,
|
||||
revealsDuration,
|
||||
commitFee,
|
||||
revealFee,
|
||||
minimumBid,
|
||||
maximumBid,
|
||||
kind,
|
||||
clientCtx.GetFromAddress(),
|
||||
)
|
||||
err = msg.ValidateBasic()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -1,6 +1,9 @@
|
||||
package auction
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
time "time"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
@ -13,13 +16,25 @@ var (
|
||||
)
|
||||
|
||||
// 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{
|
||||
CommitsDuration: params.CommitsDuration,
|
||||
RevealsDuration: params.RevealsDuration,
|
||||
CommitFee: params.CommitFee,
|
||||
RevealFee: params.RevealFee,
|
||||
MinimumBid: params.MinimumBid,
|
||||
CommitsDuration: commitsDuration,
|
||||
RevealsDuration: revealsDuration,
|
||||
CommitFee: commitFee,
|
||||
RevealFee: revealFee,
|
||||
MinimumBid: minimumBid,
|
||||
MaxPrice: maxPrice,
|
||||
Kind: kind,
|
||||
Signer: signer.String(),
|
||||
}
|
||||
}
|
||||
@ -47,10 +62,14 @@ func (msg MsgCreateAuction) ValidateBasic() error {
|
||||
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.")
|
||||
}
|
||||
|
||||
if msg.Kind == AuctionKindServiceProvider && !msg.MaxPrice.IsPositive() {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "maximum price should be greater than zero.")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
|
||||
"cosmossdk.io/collections"
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
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.
|
||||
authority.BondId = ""
|
||||
|
||||
params := auctiontypes.Params{
|
||||
CommitsDuration: moduleParams.AuthorityAuctionCommitsDuration,
|
||||
RevealsDuration: moduleParams.AuthorityAuctionRevealsDuration,
|
||||
CommitFee: moduleParams.AuthorityAuctionCommitFee,
|
||||
RevealFee: moduleParams.AuthorityAuctionRevealFee,
|
||||
MinimumBid: moduleParams.AuthorityAuctionMinimumBid,
|
||||
}
|
||||
|
||||
// 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)
|
||||
if sdkErr != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user