laconicd/x/auction/msgs.go
Prathamesh Musale 52e8d322fa
Some checks failed
Integration Tests / test-integration (push) Successful in 2m29s
E2E Tests / test-e2e (push) Successful in 4m6s
Unit Tests / test-unit (push) Successful in 2m3s
SDK Tests / sdk_tests_authority_auctions (push) Failing after 6m31s
SDK Tests / sdk_tests_nameservice_expiry (push) Successful in 9m11s
SDK Tests / sdk_tests (push) Failing after 10m14s
Add service provider auctions (#59)
Part of [Service provider auctions](https://www.notion.so/Service-provider-auctions-a7b63697d818479493ec145ea6ea3c1c)

- Add a new type of auction for service providers
  - Add a command to release provider auction funds
- Remove unused auction module params

Co-authored-by: IshaVenikar <ishavenikar7@gmail.com>
Co-authored-by: Isha Venikar <ishavenikar@Ishas-MacBook-Air.local>
Reviewed-on: #59
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
2024-09-25 12:38:49 +00:00

150 lines
4.0 KiB
Go

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"
)
var (
_ sdk.Msg = &MsgCreateAuction{}
_ sdk.Msg = &MsgCommitBid{}
_ sdk.Msg = &MsgRevealBid{}
)
// NewMsgCreateAuction is the constructor function for MsgCreateAuction.
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 {
return MsgCreateAuction{
CommitsDuration: commitsDuration,
RevealsDuration: revealsDuration,
CommitFee: commitFee,
RevealFee: revealFee,
MinimumBid: minimumBid,
MaxPrice: maxPrice,
Kind: kind,
NumProviders: numProviders,
Signer: signer.String(),
}
}
// NewMsgCommitBid is the constructor function for MsgCommitBid.
func NewMsgCommitBid(auctionId string, commitHash string, signer sdk.AccAddress) MsgCommitBid {
return MsgCommitBid{
AuctionId: auctionId,
CommitHash: commitHash,
Signer: signer.String(),
}
}
// 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(),
}
}
// ValidateBasic Implements Msg.
func (msg MsgCreateAuction) ValidateBasic() error {
if msg.Signer == "" {
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
}
if msg.Kind != AuctionKindVickrey && msg.Kind != AuctionKindProvider {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("auction kind should be one of %s | %s", AuctionKindVickrey, AuctionKindProvider))
}
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.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))
}
}
return nil
}
// 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
}
// 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
}