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:
2024-02-28 04:34:58 +00:00
committed by ashwin
parent ba7a127d7f
commit c79b7bea7d
33 changed files with 495 additions and 2683 deletions
+1 -1
View File
@@ -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)
+30 -1
View File
@@ -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
}
+2 -4
View File
@@ -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,