auction creation msg
parent
e33adb1dbf
commit
ac5e2637cb
|
@ -2,16 +2,36 @@ package keeper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"cosmos-test/x/cosmostest/types"
|
"cosmos-test/x/cosmostest/types"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (k msgServer) NewAuction(goCtx context.Context, msg *types.MsgNewAuction) (*types.MsgNewAuctionResponse, error) {
|
func (k msgServer) NewAuction(goCtx context.Context, msg *types.MsgNewAuction) (*types.MsgNewAuctionResponse, error) {
|
||||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||||
|
|
||||||
// TODO: Handling the message
|
next, found := k.Keeper.GetNextAuction(ctx)
|
||||||
_ = ctx
|
if !found {
|
||||||
|
return nil, errors.New("Auction not found")
|
||||||
return &types.MsgNewAuctionResponse{}, nil
|
}
|
||||||
|
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})
|
||||||
|
|
||||||
|
return &types.MsgNewAuctionResponse{
|
||||||
|
AuctionId: strconv.FormatUint(next.AuctionId, 10),
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue