2022-08-27 14:19:03 -07:00
|
|
|
package keeper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-08-27 19:48:00 -07:00
|
|
|
"errors"
|
|
|
|
"strconv"
|
2022-08-27 14:19:03 -07:00
|
|
|
|
|
|
|
"cosmos-test/x/cosmostest/types"
|
2022-08-27 19:48:00 -07:00
|
|
|
|
2022-08-27 14:19:03 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (k msgServer) NewAuction(goCtx context.Context, msg *types.MsgNewAuction) (*types.MsgNewAuctionResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
|
|
|
2022-08-27 19:48:00 -07:00
|
|
|
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,
|
|
|
|
Bids: []*types.Bid{},
|
|
|
|
}
|
|
|
|
|
|
|
|
k.Keeper.SetAuction(ctx, auction)
|
|
|
|
next.AuctionId++
|
|
|
|
|
|
|
|
k.Keeper.SetNextAuction(ctx, types.NextAuction{next.AuctionId})
|
2022-08-27 14:19:03 -07:00
|
|
|
|
2022-08-27 19:48:00 -07:00
|
|
|
return &types.MsgNewAuctionResponse{
|
|
|
|
AuctionId: strconv.FormatUint(next.AuctionId, 10),
|
|
|
|
}, nil
|
2022-08-27 14:19:03 -07:00
|
|
|
}
|