mirror of
https://github.com/colinear-labs/chain.git
synced 2026-03-05 12:14:26 -08:00
switch bid tracking to in-memory
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"cosmos-test/x/cosmostest/memdb"
|
||||
"cosmos-test/x/cosmostest/types"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -13,7 +14,7 @@ import (
|
||||
func (k msgServer) NewBid(goCtx context.Context, msg *types.MsgNewBid) (*types.MsgNewBidResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
|
||||
auction, found := k.Keeper.GetAuction(ctx, msg.AuctionIndex)
|
||||
_, found := k.Keeper.GetAuction(ctx, msg.AuctionIndex)
|
||||
if !found {
|
||||
return nil, fmt.Errorf("didn't find auction of index %s", msg.AuctionIndex)
|
||||
}
|
||||
@@ -28,12 +29,14 @@ func (k msgServer) NewBid(goCtx context.Context, msg *types.MsgNewBid) (*types.M
|
||||
return nil, fmt.Errorf("bid amount must be greater than 0")
|
||||
}
|
||||
|
||||
amtPrev := big.NewInt(0)
|
||||
if len(auction.Bids) > 0 {
|
||||
// shouldn't need to check validity, because we assume it's checked
|
||||
// before approving & inserting the bid
|
||||
latestBid := auction.Bids[len(auction.Bids)-1]
|
||||
amtPrev, _ = amtPrev.SetString(latestBid.Amount, 10)
|
||||
highestBid, err := memdb.BidDB.GetHighestBid(msg.AuctionIndex)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get highest bid: %s", err)
|
||||
}
|
||||
amtPrev := new(big.Int)
|
||||
amtPrev, ok = amtPrev.SetString(highestBid.Amount, 10)
|
||||
if !ok { // this should have been checked before, but whatever
|
||||
return nil, fmt.Errorf("failed to convert max bid (%s) to a large integer", msg.Amount)
|
||||
}
|
||||
|
||||
if amt.Cmp(amtPrev) < 1 {
|
||||
@@ -44,9 +47,11 @@ func (k msgServer) NewBid(goCtx context.Context, msg *types.MsgNewBid) (*types.M
|
||||
Amount: msg.Amount,
|
||||
Owner: msg.Creator,
|
||||
}
|
||||
auction.Bids = append(auction.Bids, bid)
|
||||
|
||||
k.Keeper.SetAuction(ctx, auction)
|
||||
memdb.BidDB.AddBid(msg.AuctionIndex, bid)
|
||||
|
||||
// auction.Bids = append(auction.Bids, bid)
|
||||
// k.Keeper.SetAuction(ctx, auction)
|
||||
|
||||
return &types.MsgNewBidResponse{}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user