gpu-compute-chain/x/cosmostest/keeper/msg_server_new_auction.go

40 lines
936 B
Go

package keeper
import (
"context"
"errors"
"strconv"
"cosmos-test/x/cosmostest/auctionconfig"
"cosmos-test/x/cosmostest/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func (k msgServer) NewAuction(goCtx context.Context, msg *types.MsgNewAuction) (*types.MsgNewAuctionResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
next, found := k.Keeper.GetNextAuction(ctx)
if !found {
return nil, errors.New("Auction not found")
}
index := strconv.FormatUint(next.AuctionId, 10)
auction := types.Auction{
Index: index,
Name: msg.Name,
Description: msg.Description,
TopBid: new(types.Bid),
Deadline: uint64(ctx.BlockHeight()) + auctionconfig.AuctionTime,
}
k.Keeper.SetAuction(ctx, auction)
next.AuctionId++
k.Keeper.SetNextAuction(ctx, types.NextAuction{AuctionId: next.AuctionId})
return &types.MsgNewAuctionResponse{
AuctionId: strconv.FormatUint(next.AuctionId, 10),
}, nil
}