mirror of
https://github.com/colinear-labs/chain.git
synced 2026-03-05 13:54:25 -08:00
correct price check to be for for auction ceiling
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user