Prathamesh Musale
e63f51cacd
All checks were successful
Integration Tests / test-integration (push) Successful in 2m13s
E2E Tests / test-e2e (push) Successful in 3m21s
Lint / Run golangci-lint (push) Successful in 5m5s
SDK Tests / sdk_tests_nameservice_expiry (push) Successful in 6m51s
Unit Tests / test-unit (push) Successful in 1m45s
SDK Tests / sdk_tests (push) Successful in 7m43s
SDK Tests / sdk_tests_auctions (push) Successful in 12m18s
Part of [Create an external fixturenet-laconicd stack](https://www.notion.so/Create-an-external-fixturenet-laconicd-stack-3b33cc2317444f4da209c4472f4244ed) Reviewed-on: cerc-io/laconic2d#30 Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com> Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
131 lines
3.7 KiB
Go
131 lines
3.7 KiB
Go
package keeper
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.vdb.to/cerc-io/laconicd/utils"
|
|
auctiontypes "git.vdb.to/cerc-io/laconicd/x/auction"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
var _ auctiontypes.MsgServer = msgServer{}
|
|
|
|
type msgServer struct {
|
|
k *Keeper
|
|
}
|
|
|
|
// NewMsgServerImpl returns an implementation of the module MsgServer interface.
|
|
func NewMsgServerImpl(keeper *Keeper) auctiontypes.MsgServer {
|
|
return &msgServer{k: keeper}
|
|
}
|
|
|
|
func (ms msgServer) CreateAuction(c context.Context, msg *auctiontypes.MsgCreateAuction) (*auctiontypes.MsgCreateAuctionResponse, error) {
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
|
|
|
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()),
|
|
),
|
|
})
|
|
|
|
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "CreateAuction")
|
|
|
|
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) {
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
|
|
|
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,
|
|
sdk.NewAttribute(auctiontypes.AttributeKeyAuctionId, msg.AuctionId),
|
|
sdk.NewAttribute(auctiontypes.AttributeKeyCommitHash, msg.CommitHash),
|
|
),
|
|
sdk.NewEvent(
|
|
sdk.EventTypeMessage,
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, auctiontypes.AttributeValueCategory),
|
|
sdk.NewAttribute(auctiontypes.AttributeKeySigner, signerAddress.String()),
|
|
),
|
|
})
|
|
|
|
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "CommitBid")
|
|
|
|
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) {
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
|
|
|
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,
|
|
sdk.NewAttribute(auctiontypes.AttributeKeyAuctionId, msg.AuctionId),
|
|
sdk.NewAttribute(auctiontypes.AttributeKeyReveal, msg.Reveal),
|
|
),
|
|
sdk.NewEvent(
|
|
sdk.EventTypeMessage,
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, auctiontypes.AttributeValueCategory),
|
|
sdk.NewAttribute(auctiontypes.AttributeKeySigner, signerAddress.String()),
|
|
),
|
|
})
|
|
|
|
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "RevealBid")
|
|
|
|
return &auctiontypes.MsgRevealBidResponse{Auction: resp}, nil
|
|
}
|