switch bid tracking to in-memory

master
michael 2022-08-30 19:30:17 +00:00
parent 820b506fe6
commit 87e29c3dcc
4 changed files with 14 additions and 23 deletions

View File

@ -20244,16 +20244,6 @@ paths:
in: query
required: false
type: boolean
- name: pagination.reverse
description: >-
reverse is set to true if results are to be returned in the
descending order.
Since: cosmos-sdk 0.43
in: query
required: false
type: boolean
tags:
- Query
'/cosmos-test/cosmostest/auction/{index}':

1
go.mod
View File

@ -86,7 +86,6 @@ require (
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect

3
go.sum
View File

@ -602,7 +602,6 @@ github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzw
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang-sql/sqlexp v0.0.0-20170517235910-f1bb20e5a188/go.mod h1:vXjM/+wXQnTPR4KqTKDgJukSZ6amVRtWMPEjE6sQoK8=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ=
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
@ -735,8 +734,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 h1:lLT7ZLSzGLI08vc9cpd+tYmNWjdKDqyr/2L+f6U12Fk=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3/go.mod h1:o//XUCC/F+yRGJoPO/VU0GSB0f8Nhgmxx0VIRUvaC0w=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s=

View File

@ -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
}