2024-02-15 06:56:18 +00:00
|
|
|
package auction
|
|
|
|
|
|
|
|
import (
|
|
|
|
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.
|
|
|
|
func NewMsgCreateAuction(params Params, signer sdk.AccAddress) MsgCreateAuction {
|
|
|
|
return MsgCreateAuction{
|
|
|
|
CommitsDuration: params.CommitsDuration,
|
|
|
|
RevealsDuration: params.RevealsDuration,
|
|
|
|
CommitFee: params.CommitFee,
|
|
|
|
RevealFee: params.RevealFee,
|
|
|
|
MinimumBid: params.MinimumBid,
|
|
|
|
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-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)
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg.CommitsDuration <= 0 {
|
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "commit phase duration invalid.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg.RevealsDuration <= 0 {
|
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "reveal phase duration invalid.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !msg.MinimumBid.IsPositive() {
|
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "minimum bid should be greater than zero.")
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|