2024-02-15 06:56:18 +00:00
|
|
|
package auction
|
|
|
|
|
|
|
|
import (
|
2024-09-25 12:38:49 +00:00
|
|
|
"fmt"
|
|
|
|
time "time"
|
|
|
|
|
2024-02-15 06:56:18 +00:00
|
|
|
errorsmod "cosmossdk.io/errors"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
|
|
)
|
|
|
|
|
2024-02-26 05:42:36 +00:00
|
|
|
var (
|
|
|
|
_ sdk.Msg = &MsgCreateAuction{}
|
|
|
|
_ sdk.Msg = &MsgCommitBid{}
|
|
|
|
_ sdk.Msg = &MsgRevealBid{}
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewMsgCreateAuction is the constructor function for MsgCreateAuction.
|
2024-09-25 12:38:49 +00:00
|
|
|
func NewMsgCreateAuction(
|
|
|
|
kind string,
|
|
|
|
commitsDuration time.Duration,
|
|
|
|
revealsDuration time.Duration,
|
|
|
|
commitFee sdk.Coin,
|
|
|
|
revealFee sdk.Coin,
|
|
|
|
minimumBid sdk.Coin,
|
|
|
|
maxPrice sdk.Coin,
|
|
|
|
numProviders int32,
|
|
|
|
signer sdk.AccAddress,
|
|
|
|
) MsgCreateAuction {
|
2024-02-26 05:42:36 +00:00
|
|
|
return MsgCreateAuction{
|
2024-09-25 12:38:49 +00:00
|
|
|
CommitsDuration: commitsDuration,
|
|
|
|
RevealsDuration: revealsDuration,
|
|
|
|
CommitFee: commitFee,
|
|
|
|
RevealFee: revealFee,
|
|
|
|
MinimumBid: minimumBid,
|
|
|
|
MaxPrice: maxPrice,
|
|
|
|
Kind: kind,
|
|
|
|
NumProviders: numProviders,
|
2024-02-26 05:42:36 +00:00
|
|
|
Signer: signer.String(),
|
|
|
|
}
|
|
|
|
}
|
2024-02-15 06:56:18 +00:00
|
|
|
|
|
|
|
// NewMsgCommitBid is the constructor function for MsgCommitBid.
|
2024-02-28 04:34:58 +00:00
|
|
|
func NewMsgCommitBid(auctionId string, commitHash string, signer sdk.AccAddress) MsgCommitBid {
|
2024-02-15 06:56:18 +00:00
|
|
|
return MsgCommitBid{
|
2024-02-28 04:34:58 +00:00
|
|
|
AuctionId: auctionId,
|
2024-02-15 06:56:18 +00:00
|
|
|
CommitHash: commitHash,
|
|
|
|
Signer: signer.String(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-25 12:38:49 +00:00
|
|
|
// NewMsgRevealBid is the constructor function for MsgRevealBid.
|
|
|
|
func NewMsgRevealBid(auctionId string, reveal string, signer sdk.AccAddress) MsgRevealBid {
|
|
|
|
return MsgRevealBid{
|
|
|
|
AuctionId: auctionId,
|
|
|
|
Reveal: reveal,
|
|
|
|
Signer: signer.String(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewMsgReleaseFunds is the constructor function for MsgReleaseFunds.
|
|
|
|
func NewMsgReleaseFunds(auctionId string, signer sdk.AccAddress) MsgReleaseFunds {
|
|
|
|
return MsgReleaseFunds{
|
|
|
|
AuctionId: auctionId,
|
|
|
|
Signer: signer.String(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-04 11:16:09 +00:00
|
|
|
// ValidateBasic Implements Msg.
|
|
|
|
func (msg MsgCreateAuction) ValidateBasic() error {
|
|
|
|
if msg.Signer == "" {
|
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
|
|
|
|
}
|
|
|
|
|
2024-09-25 12:38:49 +00:00
|
|
|
if msg.Kind != AuctionKindVickrey && msg.Kind != AuctionKindProvider {
|
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("auction kind should be one of %s | %s", AuctionKindVickrey, AuctionKindProvider))
|
|
|
|
}
|
|
|
|
|
2024-03-04 11:16:09 +00:00
|
|
|
if msg.CommitsDuration <= 0 {
|
2024-09-25 12:38:49 +00:00
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "commit phase duration invalid")
|
2024-03-04 11:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if msg.RevealsDuration <= 0 {
|
2024-09-25 12:38:49 +00:00
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "reveal phase duration invalid")
|
2024-03-04 11:16:09 +00:00
|
|
|
}
|
|
|
|
|
2024-09-25 12:38:49 +00:00
|
|
|
if msg.Kind == AuctionKindVickrey && !msg.MinimumBid.IsPositive() {
|
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("minimum bid should be greater than zero for %s auction", AuctionKindVickrey))
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg.Kind == AuctionKindProvider {
|
|
|
|
if !msg.MaxPrice.IsPositive() {
|
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("max price should be greater than zero for %s auction", AuctionKindProvider))
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg.NumProviders <= 0 {
|
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("num providers should be greater than zero for %s auction", AuctionKindProvider))
|
|
|
|
}
|
2024-03-04 11:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-02-15 06:56:18 +00:00
|
|
|
// ValidateBasic Implements Msg.
|
|
|
|
func (msg MsgCommitBid) ValidateBasic() error {
|
|
|
|
if msg.Signer == "" {
|
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer address")
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg.AuctionId == "" {
|
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "invalid auction id")
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg.CommitHash == "" {
|
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "invalid commit hash")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ValidateBasic Implements Msg.
|
|
|
|
func (msg MsgRevealBid) ValidateBasic() error {
|
|
|
|
if msg.Signer == "" {
|
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer address")
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg.AuctionId == "" {
|
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "invalid auction id")
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg.Reveal == "" {
|
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "invalid reveal data")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2024-09-25 12:38:49 +00:00
|
|
|
|
|
|
|
// ValidateBasic Implements Msg.
|
|
|
|
func (msg MsgReleaseFunds) ValidateBasic() error {
|
|
|
|
if msg.Signer == "" {
|
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer address")
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg.AuctionId == "" {
|
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "invalid auction id")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|