update module permissions to make escrow possible + more fixes
parent
5617f5aa2a
commit
7f37e69011
|
@ -170,6 +170,8 @@ var (
|
||||||
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
|
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
|
||||||
govtypes.ModuleName: {authtypes.Burner},
|
govtypes.ModuleName: {authtypes.Burner},
|
||||||
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
|
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
|
||||||
|
// auction module will only need escrow perms, not minting or burning
|
||||||
|
cosmostestmoduletypes.ModuleName: nil,
|
||||||
// this line is used by starport scaffolding # stargate/app/maccPerms
|
// this line is used by starport scaffolding # stargate/app/maccPerms
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,4 +2,10 @@ package auctionconfig
|
||||||
|
|
||||||
// Length of the auction in blocks-- currently 10.
|
// Length of the auction in blocks-- currently 10.
|
||||||
// Assuming a block time of 3sec, this should be ~30sec.
|
// Assuming a block time of 3sec, this should be ~30sec.
|
||||||
const AuctionTime = 100
|
const (
|
||||||
|
// Times
|
||||||
|
AuctionTime = 10
|
||||||
|
|
||||||
|
// Gas Fees
|
||||||
|
AuctionGas = 10
|
||||||
|
)
|
||||||
|
|
|
@ -3,15 +3,16 @@ package keeper
|
||||||
import (
|
import (
|
||||||
"cosmos-test/x/cosmostest/math"
|
"cosmos-test/x/cosmostest/math"
|
||||||
"cosmos-test/x/cosmostest/memdb"
|
"cosmos-test/x/cosmostest/memdb"
|
||||||
|
"cosmos-test/x/cosmostest/types"
|
||||||
|
"log"
|
||||||
"math/big"
|
"math/big"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/types"
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (k *Keeper) AuctionIsExpired(ctx types.Context, auctionId string) (bool, error) {
|
func (k *Keeper) AuctionIsExpired(ctx sdk.Context, auctionId string) (bool, error) {
|
||||||
auction, found := k.GetAuction(ctx, auctionId)
|
auction, found := k.GetAuction(ctx, auctionId)
|
||||||
|
|
||||||
// make sure the auction exists on-chain
|
// make sure the auction exists on-chain
|
||||||
|
@ -22,7 +23,7 @@ func (k *Keeper) AuctionIsExpired(ctx types.Context, auctionId string) (bool, er
|
||||||
return uint64(ctx.BlockHeight()) >= auction.Deadline, nil
|
return uint64(ctx.BlockHeight()) >= auction.Deadline, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *Keeper) FinalizeExpiredAuctions(ctx types.Context) {
|
func (k *Keeper) FinalizeExpiredAuctions(ctx sdk.Context) {
|
||||||
memdb.BidDB.ForEachAuction(func(auctionId string) error {
|
memdb.BidDB.ForEachAuction(func(auctionId string) error {
|
||||||
auction, found := k.GetAuction(ctx, auctionId)
|
auction, found := k.GetAuction(ctx, auctionId)
|
||||||
// make sure the auction exists on-chain
|
// make sure the auction exists on-chain
|
||||||
|
@ -56,7 +57,9 @@ func (k *Keeper) FinalizeExpiredAuctions(ctx types.Context) {
|
||||||
Amount: sdk.NewIntFromBigInt(amtRemaining),
|
Amount: sdk.NewIntFromBigInt(amtRemaining),
|
||||||
Denom: auction.Denom,
|
Denom: auction.Denom,
|
||||||
})
|
})
|
||||||
k.bank.SendCoinsFromModuleToAccount(ctx, "cosmostest", sdk.AccAddress(auction.Owner), coins)
|
if err := k.bank.SendCoinsFromModuleToAccount(ctx, types.ModuleName, sdk.AccAddress(auction.Owner), coins); err != nil {
|
||||||
|
log.Printf("Failed to send coins from module: %s\n", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// end auction
|
// end auction
|
||||||
|
@ -67,7 +70,7 @@ func (k *Keeper) FinalizeExpiredAuctions(ctx types.Context) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *Keeper) PayAuctionAmountDue(ctx types.Context, auctionId string) error {
|
func (k *Keeper) PayAuctionAmountDue(ctx sdk.Context, auctionId string) error {
|
||||||
auction, found := k.GetAuction(ctx, auctionId)
|
auction, found := k.GetAuction(ctx, auctionId)
|
||||||
if !found {
|
if !found {
|
||||||
return errors.Errorf("auction %s not found", auctionId)
|
return errors.Errorf("auction %s not found", auctionId)
|
||||||
|
|
|
@ -51,11 +51,11 @@ func (k msgServer) NewAuction(goCtx context.Context, msg *types.MsgNewAuction) (
|
||||||
}
|
}
|
||||||
|
|
||||||
coins := sdk.NewCoins(sdk.Coin{
|
coins := sdk.NewCoins(sdk.Coin{
|
||||||
Amount: spendable.AmountOf(auction.Ceiling),
|
Amount: sdk.NewIntFromBigInt(ceiling),
|
||||||
Denom: auction.Denom,
|
Denom: auction.Denom,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err := k.bank.SendCoinsFromAccountToModule(ctx, senderAddr, "cosmostest", coins); err != nil {
|
if err := k.bank.SendCoinsFromAccountToModule(ctx, senderAddr, types.ModuleName, coins); err != nil {
|
||||||
return nil, fmt.Errorf("failed to transfer %s%s", auction.Ceiling, auction.Denom)
|
return nil, fmt.Errorf("failed to transfer %s%s", auction.Ceiling, auction.Denom)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue