forked from cerc-io/laconicd
Setup hooks between laconic modules (#9)
- Implement auction and bond module hooks in registry module - Code cleanup Reviewed-on: deep-stack/laconic2d#9 Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com> Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
This commit is contained in:
+1
-1
@@ -11,7 +11,7 @@ const (
|
||||
AttributeKeyRevealFee = "reveal-fee"
|
||||
AttributeKeyMinimumBid = "minimum-bid"
|
||||
AttributeKeySigner = "signer"
|
||||
AttributeKeyAuctionID = "auction-id"
|
||||
AttributeKeyAuctionId = "auction-id"
|
||||
AttributeKeyCommitHash = "commit-hash"
|
||||
AttributeKeyReveal = "reveal"
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package auction
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// AuctionUsageKeeper keep track of auction usage in other modules.
|
||||
// Used to, for example, prevent deletion of a auction that's in use.
|
||||
type AuctionUsageKeeper interface {
|
||||
ModuleName() string
|
||||
UsesAuction(ctx sdk.Context, auctionId string) bool
|
||||
|
||||
OnAuctionWinnerSelected(ctx sdk.Context, auctionId string)
|
||||
}
|
||||
|
||||
// AuctionHooksWrapper is a wrapper for modules to inject AuctionUsageKeeper using depinject.
|
||||
// Reference: https://github.com/cosmos/cosmos-sdk/tree/v0.50.3/core/appmodule#resolving-circular-dependencies
|
||||
type AuctionHooksWrapper struct{ AuctionUsageKeeper }
|
||||
|
||||
// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
|
||||
func (AuctionHooksWrapper) IsOnePerModuleType() {}
|
||||
+54
-56
@@ -11,6 +11,7 @@ import (
|
||||
"cosmossdk.io/collections/indexes"
|
||||
storetypes "cosmossdk.io/core/store"
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"cosmossdk.io/log"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -62,8 +63,6 @@ func newBidsIndexes(sb *collections.SchemaBuilder) BidsIndexes {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add required methods
|
||||
|
||||
type Keeper struct {
|
||||
// Codecs
|
||||
cdc codec.BinaryCodec
|
||||
@@ -73,7 +72,7 @@ type Keeper struct {
|
||||
bankKeeper bank.Keeper
|
||||
|
||||
// Track auction usage in other cosmos-sdk modules (more like a usage tracker).
|
||||
// usageKeepers []types.AuctionUsageKeeper
|
||||
usageKeepers []auctiontypes.AuctionUsageKeeper
|
||||
|
||||
// state management
|
||||
Schema collections.Schema
|
||||
@@ -88,7 +87,7 @@ func NewKeeper(
|
||||
storeService storetypes.KVStoreService,
|
||||
accountKeeper auth.AccountKeeper,
|
||||
bankKeeper bank.Keeper,
|
||||
) Keeper {
|
||||
) *Keeper {
|
||||
sb := collections.NewSchemaBuilder(storeService)
|
||||
k := Keeper{
|
||||
cdc: cdc,
|
||||
@@ -97,7 +96,7 @@ func NewKeeper(
|
||||
Params: collections.NewItem(sb, auctiontypes.ParamsPrefix, "params", codec.CollValue[auctiontypes.Params](cdc)),
|
||||
Auctions: collections.NewIndexedMap(sb, auctiontypes.AuctionsPrefix, "auctions", collections.StringKey, codec.CollValue[auctiontypes.Auction](cdc), newAuctionIndexes(sb)),
|
||||
Bids: collections.NewIndexedMap(sb, auctiontypes.BidsPrefix, "bids", collections.PairKeyCodec(collections.StringKey, collections.StringKey), codec.CollValue[auctiontypes.Bid](cdc), newBidsIndexes(sb)),
|
||||
// usageKeepers: usageKeepers,
|
||||
usageKeepers: nil,
|
||||
}
|
||||
|
||||
schema, err := sb.Build()
|
||||
@@ -107,22 +106,29 @@ func NewKeeper(
|
||||
|
||||
k.Schema = schema
|
||||
|
||||
return k
|
||||
return &k
|
||||
}
|
||||
|
||||
// func (k *Keeper) SetUsageKeepers(usageKeepers []types.AuctionUsageKeeper) {
|
||||
// k.usageKeepers = usageKeepers
|
||||
// }
|
||||
// Logger returns a module-specific logger.
|
||||
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
|
||||
return logger(ctx)
|
||||
}
|
||||
|
||||
func logger(ctx sdk.Context) log.Logger {
|
||||
return ctx.Logger().With("module", auctiontypes.ModuleName)
|
||||
}
|
||||
|
||||
func (k *Keeper) SetUsageKeepers(usageKeepers []auctiontypes.AuctionUsageKeeper) {
|
||||
if k.usageKeepers != nil {
|
||||
panic("cannot set auction hooks twice")
|
||||
}
|
||||
|
||||
k.usageKeepers = usageKeepers
|
||||
}
|
||||
|
||||
// SaveAuction - saves a auction to the store.
|
||||
func (k Keeper) SaveAuction(ctx sdk.Context, auction *auctiontypes.Auction) error {
|
||||
return k.Auctions.Set(ctx, auction.Id, *auction)
|
||||
|
||||
// // Notify interested parties.
|
||||
// for _, keeper := range k.usageKeepers {
|
||||
// keeper.OnAuction(ctx, auction.Id)
|
||||
// }
|
||||
// return nil
|
||||
}
|
||||
|
||||
// DeleteAuction - deletes the auction.
|
||||
@@ -154,12 +160,6 @@ func (k Keeper) HasAuction(ctx sdk.Context, id string) (bool, error) {
|
||||
func (k Keeper) SaveBid(ctx sdk.Context, bid *auctiontypes.Bid) error {
|
||||
key := collections.Join(bid.AuctionId, bid.BidderAddress)
|
||||
return k.Bids.Set(ctx, key, *bid)
|
||||
|
||||
// // Notify interested parties.
|
||||
// for _, keeper := range k.usageKeepers {
|
||||
// keeper.OnAuctionBid(ctx, bid.AuctionId, bid.BidderAddress)
|
||||
// }
|
||||
// return nil
|
||||
}
|
||||
|
||||
func (k Keeper) DeleteBid(ctx sdk.Context, bid auctiontypes.Bid) error {
|
||||
@@ -191,7 +191,6 @@ func (k Keeper) GetBid(ctx sdk.Context, id string, bidder string) (auctiontypes.
|
||||
func (k Keeper) GetBids(ctx sdk.Context, id string) ([]*auctiontypes.Bid, error) {
|
||||
var bids []*auctiontypes.Bid
|
||||
|
||||
// TODO: Optimize using return by value?
|
||||
err := k.Bids.Walk(ctx, collections.NewPrefixedPairRange[string, string](id), func(key collections.Pair[string, string], value auctiontypes.Bid) (stop bool, err error) {
|
||||
bids = append(bids, &value)
|
||||
return false, nil
|
||||
@@ -463,13 +462,13 @@ func (k Keeper) RevealBid(ctx sdk.Context, msg auctiontypes.MsgRevealBid) (*auct
|
||||
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Reveal JSON unmarshal error.")
|
||||
}
|
||||
|
||||
chainID, err := wnsUtils.GetAttributeAsString(reveal, "chainId")
|
||||
if err != nil || chainID != ctx.ChainID() {
|
||||
chainId, err := wnsUtils.GetAttributeAsString(reveal, "chainId")
|
||||
if err != nil || chainId != ctx.ChainID() {
|
||||
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal chainID.")
|
||||
}
|
||||
|
||||
auctionID, err := wnsUtils.GetAttributeAsString(reveal, "auctionId")
|
||||
if err != nil || auctionID != msg.AuctionId {
|
||||
auctionId, err := wnsUtils.GetAttributeAsString(reveal, "auctionId")
|
||||
if err != nil || auctionId != msg.AuctionId {
|
||||
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal auction Id.")
|
||||
}
|
||||
|
||||
@@ -557,7 +556,7 @@ func (k Keeper) processAuctionPhases(ctx sdk.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx.Logger().Info(fmt.Sprintf("Moved auction %s to reveal phase.", auction.Id))
|
||||
k.Logger(ctx).Info(fmt.Sprintf("Moved auction %s to reveal phase.", auction.Id))
|
||||
}
|
||||
|
||||
// Reveal -> Expired state.
|
||||
@@ -567,7 +566,7 @@ func (k Keeper) processAuctionPhases(ctx sdk.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx.Logger().Info(fmt.Sprintf("Moved auction %s to expired state.", auction.Id))
|
||||
k.Logger(ctx).Info(fmt.Sprintf("Moved auction %s to expired state.", auction.Id))
|
||||
}
|
||||
|
||||
// If auction has expired, pick a winner from revealed bids.
|
||||
@@ -592,7 +591,7 @@ func (k Keeper) deleteCompletedAuctions(ctx sdk.Context) error {
|
||||
}
|
||||
|
||||
for _, auction := range auctions {
|
||||
ctx.Logger().Info(fmt.Sprintf("Deleting completed auction %s after timeout.", auction.Id))
|
||||
k.Logger(ctx).Info(fmt.Sprintf("Deleting completed auction %s after timeout.", auction.Id))
|
||||
if err := k.DeleteAuction(ctx, *auction); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -602,7 +601,7 @@ func (k Keeper) deleteCompletedAuctions(ctx sdk.Context) error {
|
||||
}
|
||||
|
||||
func (k Keeper) pickAuctionWinner(ctx sdk.Context, auction *auctiontypes.Auction) error {
|
||||
ctx.Logger().Info(fmt.Sprintf("Picking auction %s winner.", auction.Id))
|
||||
k.Logger(ctx).Info(fmt.Sprintf("Picking auction %s winner.", auction.Id))
|
||||
|
||||
var highestBid *auctiontypes.Bid
|
||||
var secondHighestBid *auctiontypes.Bid
|
||||
@@ -613,38 +612,38 @@ func (k Keeper) pickAuctionWinner(ctx sdk.Context, auction *auctiontypes.Auction
|
||||
}
|
||||
|
||||
for _, bid := range bids {
|
||||
ctx.Logger().Info(fmt.Sprintf("Processing bid %s %s", bid.BidderAddress, bid.BidAmount.String()))
|
||||
k.Logger(ctx).Info(fmt.Sprintf("Processing bid %s %s", bid.BidderAddress, bid.BidAmount.String()))
|
||||
|
||||
// Only consider revealed bids.
|
||||
if bid.Status != auctiontypes.BidStatusRevealed {
|
||||
ctx.Logger().Info(fmt.Sprintf("Ignoring unrevealed bid %s %s", bid.BidderAddress, bid.BidAmount.String()))
|
||||
k.Logger(ctx).Info(fmt.Sprintf("Ignoring unrevealed bid %s %s", bid.BidderAddress, bid.BidAmount.String()))
|
||||
continue
|
||||
}
|
||||
|
||||
// Init highest bid.
|
||||
if highestBid == nil {
|
||||
highestBid = bid
|
||||
ctx.Logger().Info(fmt.Sprintf("Initializing 1st bid %s %s", bid.BidderAddress, bid.BidAmount.String()))
|
||||
k.Logger(ctx).Info(fmt.Sprintf("Initializing 1st bid %s %s", bid.BidderAddress, bid.BidAmount.String()))
|
||||
continue
|
||||
}
|
||||
|
||||
//nolint: all
|
||||
if highestBid.BidAmount.IsLT(bid.BidAmount) {
|
||||
ctx.Logger().Info(fmt.Sprintf("New highest bid %s %s", bid.BidderAddress, bid.BidAmount.String()))
|
||||
k.Logger(ctx).Info(fmt.Sprintf("New highest bid %s %s", bid.BidderAddress, bid.BidAmount.String()))
|
||||
|
||||
secondHighestBid = highestBid
|
||||
highestBid = bid
|
||||
|
||||
ctx.Logger().Info(fmt.Sprintf("Updated 1st bid %s %s", highestBid.BidderAddress, highestBid.BidAmount.String()))
|
||||
ctx.Logger().Info(fmt.Sprintf("Updated 2nd bid %s %s", secondHighestBid.BidderAddress, secondHighestBid.BidAmount.String()))
|
||||
k.Logger(ctx).Info(fmt.Sprintf("Updated 1st bid %s %s", highestBid.BidderAddress, highestBid.BidAmount.String()))
|
||||
k.Logger(ctx).Info(fmt.Sprintf("Updated 2nd bid %s %s", secondHighestBid.BidderAddress, secondHighestBid.BidAmount.String()))
|
||||
|
||||
} else if secondHighestBid == nil || secondHighestBid.BidAmount.IsLT(bid.BidAmount) {
|
||||
ctx.Logger().Info(fmt.Sprintf("New 2nd highest bid %s %s", bid.BidderAddress, bid.BidAmount.String()))
|
||||
k.Logger(ctx).Info(fmt.Sprintf("New 2nd highest bid %s %s", bid.BidderAddress, bid.BidAmount.String()))
|
||||
|
||||
secondHighestBid = bid
|
||||
ctx.Logger().Info(fmt.Sprintf("Updated 2nd bid %s %s", secondHighestBid.BidderAddress, secondHighestBid.BidAmount.String()))
|
||||
k.Logger(ctx).Info(fmt.Sprintf("Updated 2nd bid %s %s", secondHighestBid.BidderAddress, secondHighestBid.BidAmount.String()))
|
||||
} else {
|
||||
ctx.Logger().Info(fmt.Sprintf("Ignoring bid as it doesn't affect 1st/2nd price %s %s", bid.BidderAddress, bid.BidAmount.String()))
|
||||
k.Logger(ctx).Info(fmt.Sprintf("Ignoring bid as it doesn't affect 1st/2nd price %s %s", bid.BidderAddress, bid.BidAmount.String()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -660,11 +659,11 @@ func (k Keeper) pickAuctionWinner(ctx sdk.Context, auction *auctiontypes.Auction
|
||||
if secondHighestBid != nil {
|
||||
auction.WinningPrice = secondHighestBid.BidAmount
|
||||
}
|
||||
ctx.Logger().Info(fmt.Sprintf("Auction %s winner %s.", auction.Id, auction.WinnerAddress))
|
||||
ctx.Logger().Info(fmt.Sprintf("Auction %s winner bid %s.", auction.Id, auction.WinningBid.String()))
|
||||
ctx.Logger().Info(fmt.Sprintf("Auction %s winner price %s.", auction.Id, auction.WinningPrice.String()))
|
||||
k.Logger(ctx).Info(fmt.Sprintf("Auction %s winner %s.", auction.Id, auction.WinnerAddress))
|
||||
k.Logger(ctx).Info(fmt.Sprintf("Auction %s winner bid %s.", auction.Id, auction.WinningBid.String()))
|
||||
k.Logger(ctx).Info(fmt.Sprintf("Auction %s winner price %s.", auction.Id, auction.WinningPrice.String()))
|
||||
} else {
|
||||
ctx.Logger().Info(fmt.Sprintf("Auction %s has no valid revealed bids (no winner).", auction.Id))
|
||||
k.Logger(ctx).Info(fmt.Sprintf("Auction %s has no valid revealed bids (no winner).", auction.Id))
|
||||
}
|
||||
|
||||
if err := k.SaveAuction(ctx, auction); err != nil {
|
||||
@@ -674,7 +673,7 @@ func (k Keeper) pickAuctionWinner(ctx sdk.Context, auction *auctiontypes.Auction
|
||||
for _, bid := range bids {
|
||||
bidderAddress, err := sdk.AccAddressFromBech32(bid.BidderAddress)
|
||||
if err != nil {
|
||||
ctx.Logger().Error(fmt.Sprintf("Invalid bidderAddress address. %v", err))
|
||||
k.Logger(ctx).Error(fmt.Sprintf("Invalid bidderAddress address. %v", err))
|
||||
panic("Invalid bidder address.")
|
||||
}
|
||||
|
||||
@@ -682,7 +681,7 @@ func (k Keeper) pickAuctionWinner(ctx sdk.Context, auction *auctiontypes.Auction
|
||||
// Send reveal fee back to bidders that've revealed the bid.
|
||||
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, auctiontypes.ModuleName, bidderAddress, sdk.NewCoins(bid.RevealFee))
|
||||
if sdkErr != nil {
|
||||
ctx.Logger().Error(fmt.Sprintf("Auction error returning reveal fee: %v", sdkErr))
|
||||
k.Logger(ctx).Error(fmt.Sprintf("Auction error returning reveal fee: %v", sdkErr))
|
||||
panic(sdkErr)
|
||||
}
|
||||
}
|
||||
@@ -690,7 +689,7 @@ func (k Keeper) pickAuctionWinner(ctx sdk.Context, auction *auctiontypes.Auction
|
||||
// Send back locked bid amount to all bidders.
|
||||
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, auctiontypes.ModuleName, bidderAddress, sdk.NewCoins(bid.BidAmount))
|
||||
if sdkErr != nil {
|
||||
ctx.Logger().Error(fmt.Sprintf("Auction error returning bid amount: %v", sdkErr))
|
||||
k.Logger(ctx).Error(fmt.Sprintf("Auction error returning bid amount: %v", sdkErr))
|
||||
panic(sdkErr)
|
||||
}
|
||||
}
|
||||
@@ -699,39 +698,38 @@ func (k Keeper) pickAuctionWinner(ctx sdk.Context, auction *auctiontypes.Auction
|
||||
if auction.WinnerAddress != "" {
|
||||
winnerAddress, err := sdk.AccAddressFromBech32(auction.WinnerAddress)
|
||||
if err != nil {
|
||||
ctx.Logger().Error(fmt.Sprintf("Invalid winner address. %v", err))
|
||||
k.Logger(ctx).Error(fmt.Sprintf("Invalid winner address. %v", err))
|
||||
panic("Invalid winner address.")
|
||||
}
|
||||
|
||||
// Take 2nd price from winner.
|
||||
sdkErr := k.bankKeeper.SendCoinsFromAccountToModule(ctx, winnerAddress, auctiontypes.ModuleName, sdk.NewCoins(auction.WinningPrice))
|
||||
if sdkErr != nil {
|
||||
ctx.Logger().Error(fmt.Sprintf("Auction error taking funds from winner: %v", sdkErr))
|
||||
k.Logger(ctx).Error(fmt.Sprintf("Auction error taking funds from winner: %v", sdkErr))
|
||||
panic(sdkErr)
|
||||
}
|
||||
|
||||
// Burn anything over the min. bid amount.
|
||||
amountToBurn := auction.WinningPrice.Sub(auction.MinimumBid)
|
||||
if amountToBurn.IsNegative() {
|
||||
ctx.Logger().Error("Auction coins to burn cannot be negative.")
|
||||
k.Logger(ctx).Error("Auction coins to burn cannot be negative.")
|
||||
panic("Auction coins to burn cannot be negative.")
|
||||
}
|
||||
|
||||
// Use auction burn module account instead of actually burning coins to better keep track of supply.
|
||||
sdkErr = k.bankKeeper.SendCoinsFromModuleToModule(ctx, auctiontypes.ModuleName, auctiontypes.AuctionBurnModuleAccountName, sdk.NewCoins(amountToBurn))
|
||||
if sdkErr != nil {
|
||||
ctx.Logger().Error(fmt.Sprintf("Auction error burning coins: %v", sdkErr))
|
||||
k.Logger(ctx).Error(fmt.Sprintf("Auction error burning coins: %v", sdkErr))
|
||||
panic(sdkErr)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO
|
||||
// Notify other modules (hook).
|
||||
// ctx.Logger().Info(fmt.Sprintf("Auction %s notifying %d modules.", auction.Id, len(k.usageKeepers)))
|
||||
// for _, keeper := range k.usageKeepers {
|
||||
// ctx.Logger().Info(fmt.Sprintf("Auction %s notifying module %s.", auction.Id, keeper.ModuleName()))
|
||||
// keeper.OnAuctionWinnerSelected(ctx, auction.Id)
|
||||
// }
|
||||
k.Logger(ctx).Info(fmt.Sprintf("Auction %s notifying %d modules.", auction.Id, len(k.usageKeepers)))
|
||||
for _, keeper := range k.usageKeepers {
|
||||
k.Logger(ctx).Info(fmt.Sprintf("Auction %s notifying module %s.", auction.Id, keeper.ModuleName()))
|
||||
keeper.OnAuctionWinnerSelected(ctx, auction.Id)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -10,11 +10,11 @@ import (
|
||||
var _ auctiontypes.MsgServer = msgServer{}
|
||||
|
||||
type msgServer struct {
|
||||
k Keeper
|
||||
k *Keeper
|
||||
}
|
||||
|
||||
// NewMsgServerImpl returns an implementation of the module MsgServer interface.
|
||||
func NewMsgServerImpl(keeper Keeper) auctiontypes.MsgServer {
|
||||
func NewMsgServerImpl(keeper *Keeper) auctiontypes.MsgServer {
|
||||
return &msgServer{k: keeper}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ func (ms msgServer) CommitBid(c context.Context, msg *auctiontypes.MsgCommitBid)
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
auctiontypes.EventTypeCommitBid,
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyAuctionID, msg.AuctionId),
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyAuctionId, msg.AuctionId),
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyCommitHash, msg.CommitHash),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
@@ -98,7 +98,7 @@ func (ms msgServer) RevealBid(c context.Context, msg *auctiontypes.MsgRevealBid)
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
auctiontypes.EventTypeRevealBid,
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyAuctionID, msg.AuctionId),
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyAuctionId, msg.AuctionId),
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyReveal, msg.Reveal),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
|
||||
@@ -13,11 +13,11 @@ import (
|
||||
var _ auctiontypes.QueryServer = queryServer{}
|
||||
|
||||
type queryServer struct {
|
||||
k Keeper
|
||||
k *Keeper
|
||||
}
|
||||
|
||||
// NewQueryServerImpl returns an implementation of the module QueryServer.
|
||||
func NewQueryServerImpl(k Keeper) auctiontypes.QueryServer {
|
||||
func NewQueryServerImpl(k *Keeper) auctiontypes.QueryServer {
|
||||
return queryServer{k}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
// EndBlocker is called every block
|
||||
func EndBlocker(ctx context.Context, k keeper.Keeper) error {
|
||||
func EndBlocker(ctx context.Context, k *keeper.Keeper) error {
|
||||
sdkCtx := sdk.UnwrapSDKContext(ctx)
|
||||
|
||||
return k.EndBlockerProcessAuctions(sdkCtx)
|
||||
|
||||
@@ -4,12 +4,14 @@ import (
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/core/store"
|
||||
"cosmossdk.io/depinject"
|
||||
"golang.org/x/exp/maps"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
auth "github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
||||
bank "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
||||
|
||||
modulev1 "git.vdb.to/cerc-io/laconic2d/api/cerc/auction/module/v1"
|
||||
"git.vdb.to/cerc-io/laconic2d/x/auction"
|
||||
"git.vdb.to/cerc-io/laconic2d/x/auction/keeper"
|
||||
)
|
||||
|
||||
@@ -25,6 +27,7 @@ func init() {
|
||||
appmodule.Register(
|
||||
&modulev1.Module{},
|
||||
appmodule.Provide(ProvideModule),
|
||||
appmodule.Invoke(InvokeSetAuctionHooks),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -41,7 +44,11 @@ type ModuleInputs struct {
|
||||
type ModuleOutputs struct {
|
||||
depinject.Out
|
||||
|
||||
Keeper keeper.Keeper
|
||||
// Use * as required by InvokeSetAuctionHooks
|
||||
// https://github.com/cosmos/cosmos-sdk/tree/v0.50.3/core/appmodule#invoker-invocation-details
|
||||
// https://github.com/cosmos/cosmos-sdk/tree/v0.50.3/core/appmodule#regular-golang-types
|
||||
Keeper *keeper.Keeper
|
||||
|
||||
Module appmodule.AppModule
|
||||
}
|
||||
|
||||
@@ -51,3 +58,25 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
|
||||
|
||||
return ModuleOutputs{Module: m, Keeper: k}
|
||||
}
|
||||
|
||||
func InvokeSetAuctionHooks(
|
||||
config *modulev1.Module,
|
||||
keeper *keeper.Keeper,
|
||||
auctionHooks map[string]auction.AuctionHooksWrapper,
|
||||
) error {
|
||||
// all arguments to invokers are optional
|
||||
if keeper == nil || config == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var usageKeepers []auction.AuctionUsageKeeper
|
||||
|
||||
for _, modName := range maps.Keys(auctionHooks) {
|
||||
hook := auctionHooks[modName]
|
||||
usageKeepers = append(usageKeepers, hook)
|
||||
}
|
||||
|
||||
keeper.SetUsageKeepers(usageKeepers)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@ import (
|
||||
"git.vdb.to/cerc-io/laconic2d/x/auction/keeper"
|
||||
)
|
||||
|
||||
// TODO: Port remaining AppModule methods
|
||||
|
||||
var (
|
||||
_ module.AppModuleBasic = AppModule{}
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
@@ -36,11 +34,11 @@ const ConsensusVersion = 1
|
||||
|
||||
type AppModule struct {
|
||||
cdc codec.Codec
|
||||
keeper keeper.Keeper
|
||||
keeper *keeper.Keeper
|
||||
}
|
||||
|
||||
// NewAppModule creates a new AppModule object
|
||||
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule {
|
||||
func NewAppModule(cdc codec.Codec, keeper *keeper.Keeper) AppModule {
|
||||
return AppModule{
|
||||
cdc: cdc,
|
||||
keeper: keeper,
|
||||
|
||||
+2
-2
@@ -25,9 +25,9 @@ func NewMsgCreateAuction(params Params, signer sdk.AccAddress) MsgCreateAuction
|
||||
}
|
||||
|
||||
// NewMsgCommitBid is the constructor function for MsgCommitBid.
|
||||
func NewMsgCommitBid(auctionID string, commitHash string, signer sdk.AccAddress) MsgCommitBid {
|
||||
func NewMsgCommitBid(auctionId string, commitHash string, signer sdk.AccAddress) MsgCommitBid {
|
||||
return MsgCommitBid{
|
||||
AuctionId: auctionID,
|
||||
AuctionId: auctionId,
|
||||
CommitHash: commitHash,
|
||||
Signer: signer.String(),
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ func (m *QueryAuctionsResponse) GetPagination() *query.PageRequest {
|
||||
|
||||
// AuctionRequest is the format for querying a specific auction
|
||||
type QueryAuctionRequest struct {
|
||||
// Auction ID
|
||||
// Auction id
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ func (m *QueryAuctionResponse) GetAuction() *Auction {
|
||||
|
||||
// BidRequest is the format for querying a specific bid in an auction
|
||||
type QueryBidRequest struct {
|
||||
// Auction ID
|
||||
// Auction id
|
||||
AuctionId string `protobuf:"bytes,1,opt,name=auction_id,json=auctionId,proto3" json:"auction_id,omitempty"`
|
||||
// Bidder address
|
||||
Bidder string `protobuf:"bytes,2,opt,name=bidder,proto3" json:"bidder,omitempty"`
|
||||
@@ -410,7 +410,7 @@ func (m *QueryBidResponse) GetBid() *Bid {
|
||||
|
||||
// BidsRequest is the format for querying all bids in an auction
|
||||
type QueryBidsRequest struct {
|
||||
// Auction ID
|
||||
// Auction id
|
||||
AuctionId string `protobuf:"bytes,1,opt,name=auction_id,json=auctionId,proto3" json:"auction_id,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -125,7 +125,7 @@ var xxx_messageInfo_MsgCreateAuctionResponse proto.InternalMessageInfo
|
||||
|
||||
// CommitBid defines the message to commit a bid
|
||||
type MsgCommitBid struct {
|
||||
// Auction ID
|
||||
// Auction id
|
||||
AuctionId string `protobuf:"bytes,1,opt,name=auction_id,json=auctionId,proto3" json:"auction_id,omitempty" json:"auction_id" yaml:"auction_id"`
|
||||
// Commit Hash
|
||||
CommitHash string `protobuf:"bytes,2,opt,name=commit_hash,json=commitHash,proto3" json:"commit_hash,omitempty" json:"commit_hash" yaml:"commit_hash"`
|
||||
@@ -207,7 +207,7 @@ var xxx_messageInfo_MsgCommitBidResponse proto.InternalMessageInfo
|
||||
|
||||
// RevealBid defines the message to reveal a bid
|
||||
type MsgRevealBid struct {
|
||||
// Auction ID
|
||||
// Auction id
|
||||
AuctionId string `protobuf:"bytes,1,opt,name=auction_id,json=auctionId,proto3" json:"auction_id,omitempty" json:"auction_id" yaml:"auction_id"`
|
||||
// Commit Hash
|
||||
Reveal string `protobuf:"bytes,2,opt,name=reveal,proto3" json:"reveal,omitempty" json:"reveal" yaml:"reveal"`
|
||||
|
||||
+2
-2
@@ -29,14 +29,14 @@ const (
|
||||
BidStatusRevealed = "reveal"
|
||||
)
|
||||
|
||||
// AuctionId simplifies generation of auction IDs.
|
||||
// AuctionId simplifies generation of auction ids.
|
||||
type AuctionId struct {
|
||||
Address sdk.Address
|
||||
AccNum uint64
|
||||
Sequence uint64
|
||||
}
|
||||
|
||||
// Generate creates the auction ID.
|
||||
// Generate creates the auction id.
|
||||
func (auctionId AuctionId) Generate() string {
|
||||
hasher := sha256.New()
|
||||
str := fmt.Sprintf("%s:%d:%d", auctionId.Address.String(), auctionId.AccNum, auctionId.Sequence)
|
||||
|
||||
Reference in New Issue
Block a user