switch bid tracking to in-memory
parent
820b506fe6
commit
87e29c3dcc
|
@ -20244,16 +20244,6 @@ paths:
|
||||||
in: query
|
in: query
|
||||||
required: false
|
required: false
|
||||||
type: boolean
|
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:
|
tags:
|
||||||
- Query
|
- Query
|
||||||
'/cosmos-test/cosmostest/auction/{index}':
|
'/cosmos-test/cosmostest/auction/{index}':
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -86,7 +86,6 @@ require (
|
||||||
github.com/gorilla/handlers v1.5.1 // indirect
|
github.com/gorilla/handlers v1.5.1 // indirect
|
||||||
github.com/gorilla/websocket v1.5.0 // indirect
|
github.com/gorilla/websocket v1.5.0 // indirect
|
||||||
github.com/grpc-ecosystem/go-grpc-middleware v1.3.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/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
|
||||||
github.com/gtank/merlin v0.1.1 // indirect
|
github.com/gtank/merlin v0.1.1 // indirect
|
||||||
github.com/gtank/ristretto255 v0.1.2 // indirect
|
github.com/gtank/ristretto255 v0.1.2 // indirect
|
||||||
|
|
3
go.sum
3
go.sum
|
@ -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/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-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/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 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 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ=
|
||||||
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
|
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.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 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
|
||||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
|
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 h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
|
||||||
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
|
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=
|
github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s=
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
|
"cosmos-test/x/cosmostest/memdb"
|
||||||
"cosmos-test/x/cosmostest/types"
|
"cosmos-test/x/cosmostest/types"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/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) {
|
func (k msgServer) NewBid(goCtx context.Context, msg *types.MsgNewBid) (*types.MsgNewBidResponse, error) {
|
||||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||||
|
|
||||||
auction, found := k.Keeper.GetAuction(ctx, msg.AuctionIndex)
|
_, found := k.Keeper.GetAuction(ctx, msg.AuctionIndex)
|
||||||
if !found {
|
if !found {
|
||||||
return nil, fmt.Errorf("didn't find auction of index %s", msg.AuctionIndex)
|
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")
|
return nil, fmt.Errorf("bid amount must be greater than 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
amtPrev := big.NewInt(0)
|
highestBid, err := memdb.BidDB.GetHighestBid(msg.AuctionIndex)
|
||||||
if len(auction.Bids) > 0 {
|
if err != nil {
|
||||||
// shouldn't need to check validity, because we assume it's checked
|
return nil, fmt.Errorf("failed to get highest bid: %s", err)
|
||||||
// before approving & inserting the bid
|
}
|
||||||
latestBid := auction.Bids[len(auction.Bids)-1]
|
amtPrev := new(big.Int)
|
||||||
amtPrev, _ = amtPrev.SetString(latestBid.Amount, 10)
|
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 {
|
if amt.Cmp(amtPrev) < 1 {
|
||||||
|
@ -44,9 +47,11 @@ func (k msgServer) NewBid(goCtx context.Context, msg *types.MsgNewBid) (*types.M
|
||||||
Amount: msg.Amount,
|
Amount: msg.Amount,
|
||||||
Owner: msg.Creator,
|
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
|
return &types.MsgNewBidResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue