mirror of
https://github.com/colinear-labs/chain.git
synced 2026-03-06 03:04:26 -08:00
WIP type updates
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"cosmos-test/x/cosmostest/math"
|
||||
"cosmos-test/x/cosmostest/memdb"
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -25,7 +27,7 @@ func (k *Keeper) FinalizeExpiredAuctions(ctx types.Context) {
|
||||
auction, found := k.GetAuction(ctx, auctionId)
|
||||
// make sure the auction exists on-chain
|
||||
if !found {
|
||||
return errors.Errorf("auction %s not found on-chain", auctionId)
|
||||
return errors.Errorf("auction %s not found", auctionId)
|
||||
}
|
||||
|
||||
if uint64(ctx.BlockHeight()) >= auction.Deadline {
|
||||
@@ -35,6 +37,9 @@ func (k *Keeper) FinalizeExpiredAuctions(ctx types.Context) {
|
||||
return errors.Errorf("could not get highest bid for auction %s: %s", auctionId, err)
|
||||
}
|
||||
|
||||
// Remainig Unpaid: Full bid amount
|
||||
auction.Remaining = auction.Best.Amount
|
||||
|
||||
// clear auction
|
||||
memdb.BidDB.ClearAuction(auctionId)
|
||||
|
||||
@@ -62,6 +67,34 @@ func (k *Keeper) FinalizeExpiredAuctions(ctx types.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func (k *Keeper) VestAuctionPayments(ctx types.Context) {
|
||||
func (k *Keeper) PayAuctionAmountDue(ctx types.Context, auctionId string) error {
|
||||
auction, found := k.GetAuction(ctx, auctionId)
|
||||
if !found {
|
||||
return errors.Errorf("auction %s not found", auctionId)
|
||||
}
|
||||
|
||||
blockTime := ctx.BlockTime()
|
||||
deadline := time.Unix(int64(auction.Deadline), 0)
|
||||
|
||||
if blockTime.After(deadline) {
|
||||
return nil
|
||||
} else {
|
||||
amtTotal := new(big.Int)
|
||||
amtTotal.SetString(auction.Best.Amount, 10)
|
||||
amtRemaining := new(big.Int)
|
||||
amtTotal.SetString(auction.Remaining, 10)
|
||||
amt, err := math.CalcAmountVestableLinear(
|
||||
amtTotal,
|
||||
amtRemaining,
|
||||
ctx.BlockTime(),
|
||||
time.Unix(int64(auction.LeaseStart), 0),
|
||||
time.Unix(int64(auction.LeaseEnd), 0),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
coins := sdk.NewCoins(sdk.NewCoin(auction.Denom, sdk.NewIntFromBigInt(amt)))
|
||||
err = k.bank.SendCoinsFromModuleToAccount(ctx, "cosmostest", sdk.AccAddress(auction.Best.Owner), coins)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,10 +27,14 @@ func (k msgServer) NewAuction(goCtx context.Context, msg *types.MsgNewAuction) (
|
||||
Name: msg.Name,
|
||||
Description: msg.Description,
|
||||
// Best: new(types.Bid),
|
||||
Deadline: uint64(ctx.BlockHeight()) + auctionconfig.AuctionTime,
|
||||
Denom: msg.Denom,
|
||||
Owner: msg.Creator,
|
||||
Ceiling: msg.Ceiling,
|
||||
Deadline: uint64(ctx.BlockHeight()) + auctionconfig.AuctionTime,
|
||||
Denom: msg.Denom,
|
||||
Owner: msg.Creator,
|
||||
Ceiling: msg.Ceiling,
|
||||
LeaseStart: uint64(ctx.BlockTime().Unix()),
|
||||
LeaseEnd: msg.LeaseEnd,
|
||||
Closed: false,
|
||||
Remaining: "0",
|
||||
}
|
||||
|
||||
senderAddr, err := sdk.AccAddressFromBech32(msg.Creator)
|
||||
|
||||
Reference in New Issue
Block a user