correct price check to be for for auction ceiling

master
michael 2022-09-01 06:55:14 +00:00
parent f67118ebf6
commit ffd2529ccb
5 changed files with 17 additions and 25 deletions

View File

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

1
go.mod
View File

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

2
go.sum
View File

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

View File

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

View File

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