2024-02-09 08:44:45 +00:00
|
|
|
package keeper
|
|
|
|
|
2024-02-12 08:34:40 +00:00
|
|
|
import (
|
|
|
|
"context"
|
2024-02-09 08:44:45 +00:00
|
|
|
|
2024-09-02 05:00:02 +00:00
|
|
|
errorsmod "cosmossdk.io/errors"
|
2024-06-25 06:33:41 +00:00
|
|
|
"git.vdb.to/cerc-io/laconicd/utils"
|
2024-04-01 09:57:26 +00:00
|
|
|
auctiontypes "git.vdb.to/cerc-io/laconicd/x/auction"
|
2024-02-12 08:34:40 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2024-09-02 05:00:02 +00:00
|
|
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
2024-02-12 08:34:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ auctiontypes.MsgServer = msgServer{}
|
2024-02-09 08:44:45 +00:00
|
|
|
|
|
|
|
type msgServer struct {
|
2024-02-28 04:34:58 +00:00
|
|
|
k *Keeper
|
2024-02-09 08:44:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewMsgServerImpl returns an implementation of the module MsgServer interface.
|
2024-02-28 04:34:58 +00:00
|
|
|
func NewMsgServerImpl(keeper *Keeper) auctiontypes.MsgServer {
|
2024-02-12 08:34:40 +00:00
|
|
|
return &msgServer{k: keeper}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms msgServer) CreateAuction(c context.Context, msg *auctiontypes.MsgCreateAuction) (*auctiontypes.MsgCreateAuctionResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
2024-06-25 06:33:41 +00:00
|
|
|
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
2024-02-12 08:34:40 +00:00
|
|
|
|
|
|
|
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := ms.k.CreateAuction(ctx, *msg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
|
|
sdk.NewEvent(
|
|
|
|
auctiontypes.EventTypeCreateAuction,
|
|
|
|
sdk.NewAttribute(auctiontypes.AttributeKeyCommitsDuration, msg.CommitsDuration.String()),
|
|
|
|
sdk.NewAttribute(auctiontypes.AttributeKeyCommitFee, msg.CommitFee.String()),
|
|
|
|
sdk.NewAttribute(auctiontypes.AttributeKeyRevealFee, msg.RevealFee.String()),
|
|
|
|
sdk.NewAttribute(auctiontypes.AttributeKeyMinimumBid, msg.MinimumBid.String()),
|
|
|
|
),
|
|
|
|
sdk.NewEvent(
|
|
|
|
sdk.EventTypeMessage,
|
|
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, auctiontypes.AttributeValueCategory),
|
|
|
|
sdk.NewAttribute(auctiontypes.AttributeKeySigner, signerAddress.String()),
|
|
|
|
),
|
|
|
|
})
|
|
|
|
|
2024-06-25 06:33:41 +00:00
|
|
|
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "CreateAuction")
|
|
|
|
|
2024-02-12 08:34:40 +00:00
|
|
|
return &auctiontypes.MsgCreateAuctionResponse{Auction: resp}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CommitBid is the command for committing a bid
|
|
|
|
// nolint: all
|
|
|
|
func (ms msgServer) CommitBid(c context.Context, msg *auctiontypes.MsgCommitBid) (*auctiontypes.MsgCommitBidResponse, error) {
|
2024-03-06 09:24:15 +00:00
|
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-02-12 08:34:40 +00:00
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
2024-06-25 06:33:41 +00:00
|
|
|
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
2024-02-12 08:34:40 +00:00
|
|
|
|
|
|
|
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := ms.k.CommitBid(ctx, *msg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
|
|
sdk.NewEvent(
|
|
|
|
auctiontypes.EventTypeCommitBid,
|
2024-02-28 04:34:58 +00:00
|
|
|
sdk.NewAttribute(auctiontypes.AttributeKeyAuctionId, msg.AuctionId),
|
2024-02-12 08:34:40 +00:00
|
|
|
sdk.NewAttribute(auctiontypes.AttributeKeyCommitHash, msg.CommitHash),
|
|
|
|
),
|
|
|
|
sdk.NewEvent(
|
|
|
|
sdk.EventTypeMessage,
|
|
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, auctiontypes.AttributeValueCategory),
|
|
|
|
sdk.NewAttribute(auctiontypes.AttributeKeySigner, signerAddress.String()),
|
|
|
|
),
|
|
|
|
})
|
|
|
|
|
2024-06-25 06:33:41 +00:00
|
|
|
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "CommitBid")
|
|
|
|
|
2024-02-12 08:34:40 +00:00
|
|
|
return &auctiontypes.MsgCommitBidResponse{Bid: resp}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// RevealBid is the command for revealing a bid
|
|
|
|
// nolint: all
|
|
|
|
func (ms msgServer) RevealBid(c context.Context, msg *auctiontypes.MsgRevealBid) (*auctiontypes.MsgRevealBidResponse, error) {
|
2024-03-06 09:24:15 +00:00
|
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-02-12 08:34:40 +00:00
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
2024-06-25 06:33:41 +00:00
|
|
|
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
2024-02-12 08:34:40 +00:00
|
|
|
|
|
|
|
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := ms.k.RevealBid(ctx, *msg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
|
|
sdk.NewEvent(
|
|
|
|
auctiontypes.EventTypeRevealBid,
|
2024-02-28 04:34:58 +00:00
|
|
|
sdk.NewAttribute(auctiontypes.AttributeKeyAuctionId, msg.AuctionId),
|
2024-02-12 08:34:40 +00:00
|
|
|
sdk.NewAttribute(auctiontypes.AttributeKeyReveal, msg.Reveal),
|
|
|
|
),
|
|
|
|
sdk.NewEvent(
|
|
|
|
sdk.EventTypeMessage,
|
|
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, auctiontypes.AttributeValueCategory),
|
|
|
|
sdk.NewAttribute(auctiontypes.AttributeKeySigner, signerAddress.String()),
|
|
|
|
),
|
|
|
|
})
|
|
|
|
|
2024-06-25 06:33:41 +00:00
|
|
|
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "RevealBid")
|
|
|
|
|
2024-02-12 08:34:40 +00:00
|
|
|
return &auctiontypes.MsgRevealBidResponse{Auction: resp}, nil
|
|
|
|
}
|
2024-09-02 05:00:02 +00:00
|
|
|
|
|
|
|
// UpdateParams defines a method to perform updation of module params.
|
|
|
|
func (ms msgServer) UpdateParams(c context.Context, msg *auctiontypes.MsgUpdateParams) (*auctiontypes.MsgUpdateParamsResponse, error) {
|
|
|
|
if ms.k.authority != msg.Authority {
|
|
|
|
return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", ms.k.authority, msg.Authority)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := msg.Params.Validate(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
|
|
|
|
if err := ms.k.SetParams(ctx, msg.Params); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &auctiontypes.MsgUpdateParamsResponse{}, nil
|
|
|
|
}
|