implement locking requirement to bid

master
michael 2022-09-07 23:49:51 +00:00
parent c85bbaca1f
commit 5158b96c96
2 changed files with 19 additions and 1 deletions

View File

@ -59,5 +59,7 @@ func (k msgServer) LockFunds(goCtx context.Context, msg *types.MsgLockFunds) (*t
lockedUsers.Users[msg.Creator] = totalAfterPay.String() lockedUsers.Users[msg.Creator] = totalAfterPay.String()
k.Keeper.SetLockedUsers(ctx, lockedUsers)
return &types.MsgLockFundsResponse{}, nil return &types.MsgLockFundsResponse{}, nil
} }

View File

@ -2,10 +2,12 @@ package keeper
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"math/big" "math/big"
"reflect" "reflect"
"colinear/x/colinearcore/auctionconfig"
"colinear/x/colinearcore/memdb" "colinear/x/colinearcore/memdb"
"colinear/x/colinearcore/types" "colinear/x/colinearcore/types"
@ -15,6 +17,21 @@ 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)
lockedUsers, ok := k.Keeper.GetLockedUsers(ctx)
if !ok {
return nil, errors.New("unable to read locked providers (uninitialized)")
}
if lockedAmtStr, ok := lockedUsers.Users[msg.Creator]; !ok {
return nil, fmt.Errorf("provider has not locked CLR tokens (min: %d uCLR)", auctionconfig.ProviderMinLockedUClr)
} else {
lockedAmt := new(big.Int)
lockedAmt.SetString(lockedAmtStr, 10)
required := big.NewInt(auctionconfig.ProviderMinLockedUClr)
if lockedAmt.Cmp(required) == -1 {
return nil, fmt.Errorf("provider has not locked enough CLR tokens (min: %d uCLR, locked: %s)", auctionconfig.ProviderMinLockedUClr, lockedAmt.String())
}
}
auction, found := k.Keeper.GetAuction(ctx, msg.AuctionIndex) auction, 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,7 +45,6 @@ func (k msgServer) NewBid(goCtx context.Context, msg *types.MsgNewBid) (*types.M
return nil, fmt.Errorf("auction %s is expired", msg.AuctionIndex) return nil, fmt.Errorf("auction %s is expired", msg.AuctionIndex)
} }
ok := false
amt := new(big.Int) amt := new(big.Int)
amt, ok = amt.SetString(msg.Amount, 10) amt, ok = amt.SetString(msg.Amount, 10)
if !ok { if !ok {