update module permissions to make escrow possible + more fixes

master
michael 2022-09-04 23:36:57 +00:00
parent 5617f5aa2a
commit 7f37e69011
4 changed files with 19 additions and 8 deletions

View File

@ -170,6 +170,8 @@ var (
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {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
}
)

View File

@ -2,4 +2,10 @@ package auctionconfig
// Length of the auction in blocks-- currently 10.
// Assuming a block time of 3sec, this should be ~30sec.
const AuctionTime = 100
const (
// Times
AuctionTime = 10
// Gas Fees
AuctionGas = 10
)

View File

@ -3,15 +3,16 @@ package keeper
import (
"cosmos-test/x/cosmostest/math"
"cosmos-test/x/cosmostest/memdb"
"cosmos-test/x/cosmostest/types"
"log"
"math/big"
"time"
"github.com/cosmos/cosmos-sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"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)
// 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
}
func (k *Keeper) FinalizeExpiredAuctions(ctx types.Context) {
func (k *Keeper) FinalizeExpiredAuctions(ctx sdk.Context) {
memdb.BidDB.ForEachAuction(func(auctionId string) error {
auction, found := k.GetAuction(ctx, auctionId)
// make sure the auction exists on-chain
@ -56,7 +57,9 @@ func (k *Keeper) FinalizeExpiredAuctions(ctx types.Context) {
Amount: sdk.NewIntFromBigInt(amtRemaining),
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
@ -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)
if !found {
return errors.Errorf("auction %s not found", auctionId)

View File

@ -51,11 +51,11 @@ func (k msgServer) NewAuction(goCtx context.Context, msg *types.MsgNewAuction) (
}
coins := sdk.NewCoins(sdk.Coin{
Amount: spendable.AmountOf(auction.Ceiling),
Amount: sdk.NewIntFromBigInt(ceiling),
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)
}