From ffd2529ccb0326c7851bcaf153a593dd780924c5 Mon Sep 17 00:00:00 2001 From: turtlebasket Date: Thu, 1 Sep 2022 06:55:14 +0000 Subject: [PATCH] correct price check to be for for auction ceiling --- docs/static/openapi.yml | 10 ---------- go.mod | 1 - go.sum | 2 -- x/cosmostest/keeper/msg_server_new_auction.go | 16 ++++++++++++++++ x/cosmostest/keeper/msg_server_new_bid.go | 13 +------------ 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index 4af0c77..25fff8f 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -20251,16 +20251,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}': diff --git a/go.mod b/go.mod index 9ab26ca..ff93dce 100644 --- a/go.mod +++ b/go.mod @@ -87,7 +87,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 diff --git a/go.sum b/go.sum index ad897ba..07b1083 100644 --- a/go.sum +++ b/go.sum @@ -734,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= diff --git a/x/cosmostest/keeper/msg_server_new_auction.go b/x/cosmostest/keeper/msg_server_new_auction.go index 2bf0733..bae524e 100644 --- a/x/cosmostest/keeper/msg_server_new_auction.go +++ b/x/cosmostest/keeper/msg_server_new_auction.go @@ -3,6 +3,8 @@ package keeper import ( "context" "errors" + "fmt" + "math/big" "strconv" "cosmos-test/x/cosmostest/auctionconfig" @@ -28,6 +30,20 @@ func (k msgServer) NewAuction(goCtx context.Context, msg *types.MsgNewAuction) ( Deadline: uint64(ctx.BlockHeight()) + auctionconfig.AuctionTime, Denom: msg.Denom, Owner: msg.Creator, + Ceiling: msg.Ceiling, + } + + addr, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + return nil, fmt.Errorf("sender address `%s` format invalid (bech32 required)", msg.Creator) + } + + spendable := k.bank.SpendableCoins(ctx, addr) + // if balance does not exceed or equal proposed auction ceiling... + ceiling := new(big.Int) + ceiling.SetString(auction.Ceiling, 10) + if spendable.AmountOf(auction.Denom).BigInt().Cmp(ceiling) == -1 { + return nil, fmt.Errorf("not enough balance to set ceiling %s%s", msg.Ceiling, auction.Denom) } k.Keeper.SetAuction(ctx, auction) diff --git a/x/cosmostest/keeper/msg_server_new_bid.go b/x/cosmostest/keeper/msg_server_new_bid.go index 606f7a2..a0d80f1 100644 --- a/x/cosmostest/keeper/msg_server_new_bid.go +++ b/x/cosmostest/keeper/msg_server_new_bid.go @@ -15,7 +15,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) } @@ -38,17 +38,6 @@ func (k msgServer) NewBid(goCtx context.Context, msg *types.MsgNewBid) (*types.M return nil, fmt.Errorf("bid amount must be greater than 0") } - addr, err := sdk.AccAddressFromBech32(msg.Creator) - if err != nil { - return nil, fmt.Errorf("sender address `%s` format invalid (bech32 required)", msg.Creator) - } - - spendable := k.bank.SpendableCoins(ctx, addr) - // if balance does not exceed or equal proposed bid amount... - if spendable.AmountOf(auction.Denom).BigInt().Cmp(amt) == -1 { - return nil, fmt.Errorf("not enough balance to bid %s%s", msg.Amount, auction.Denom) - } - lowestBid, err := memdb.BidDB.GetLowestBid(msg.AuctionIndex) // we manually handle KeyNotFound in GetHighestBid, so should return (nil, nil) if not found if err != nil {