Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer-zq committed Jul 2, 2024
1 parent f865273 commit 272cb15
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 132 deletions.
15 changes: 11 additions & 4 deletions modules/coinswap/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func init() {
)
}

// ProvideKeyTable provides module's KVStore keys
func ProvideKeyTable() types.KeyTable {
return types.ParamKeyTable()
}
Expand All @@ -33,7 +34,8 @@ func (am AppModule) IsOnePerModuleType() {}
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}

type CoinswapInputs struct {
// Inputs define the module inputs for the depinject.
type Inputs struct {
depinject.In

Config *modulev1.Module
Expand All @@ -47,14 +49,19 @@ type CoinswapInputs struct {
LegacySubspace types.Subspace `optional:"true"`
}

type CoinswapOutputs struct {
// Outputs define the module outputs for the depinject.
type Outputs struct {
depinject.Out

CoinswapKeeper keeper.Keeper
Module appmodule.AppModule
}

func ProvideModule(in CoinswapInputs) CoinswapOutputs {
// ProvideModule creates and returns the coinswap module with the specified inputs.
//
// It takes Inputs as the parameter, which includes the configuration, codec, key, account keeper, bank keeper, and legacy subspace.
// It returns Outputs containing the coinswap keeper and the app module.
func ProvideModule(in Inputs) Outputs {
// default to governance authority if not provided
authority := authtypes.NewModuleAddress(govtypes.ModuleName)
if in.Config.Authority != "" {
Expand All @@ -71,5 +78,5 @@ func ProvideModule(in CoinswapInputs) CoinswapOutputs {
)
m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper, in.LegacySubspace)

return CoinswapOutputs{CoinswapKeeper: keeper, Module: m}
return Outputs{CoinswapKeeper: keeper, Module: m}
}
18 changes: 14 additions & 4 deletions modules/farm/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func init() {
)
}

// ProvideKeyTable returns the KeyTable for the farm module's parameters.
//
// No parameters.
// Returns a types.KeyTable.
func ProvideKeyTable() types.KeyTable {
return types.ParamKeyTable()
}
Expand All @@ -33,7 +37,8 @@ func (am AppModule) IsOnePerModuleType() {}
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}

type FarmInputs struct {
// Inputs define the module inputs for the depinject.
type Inputs struct {
depinject.In

Config *modulev1.Module
Expand All @@ -50,14 +55,19 @@ type FarmInputs struct {
LegacySubspace types.Subspace `optional:"true"`
}

type FarmOutputs struct {
// Outputs define the module outputs for the depinject.
type Outputs struct {
depinject.Out

FarmKeeper keeper.Keeper
Module appmodule.AppModule
}

func ProvideModule(in FarmInputs) FarmOutputs {
// ProvideModule creates and returns the farm module with the specified inputs.
//
// It takes Inputs as the parameter, which includes the configuration, codec, key, account keeper, bank keeper, governance keeper, coinswap keeper, and legacy subspace.
// It returns Outputs containing the farm keeper and the app module.
func ProvideModule(in Inputs) Outputs {
// default to governance authority if not provided
authority := authtypes.NewModuleAddress(govtypes.ModuleName)
if in.Config.Authority != "" {
Expand All @@ -78,5 +88,5 @@ func ProvideModule(in FarmInputs) FarmOutputs {
)
m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper, in.LegacySubspace)

return FarmOutputs{FarmKeeper: keeper, Module: m}
return Outputs{FarmKeeper: keeper, Module: m}
}
18 changes: 14 additions & 4 deletions modules/htlc/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func init() {
)
}

// ProvideKeyTable returns the key table for the htlc module.
//
// No parameters.
// Returns a types.KeyTable.
func ProvideKeyTable() types.KeyTable {
return types.ParamKeyTable()
}
Expand All @@ -32,7 +36,8 @@ func (am AppModule) IsOnePerModuleType() {}
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}

type HTLCInputs struct {
// Inputs define the module inputs for the depinject.
type Inputs struct {
depinject.In

Config *modulev1.Module
Expand All @@ -46,14 +51,19 @@ type HTLCInputs struct {
LegacySubspace types.Subspace `optional:"true"`
}

type HTLCOutputs struct {
// Outputs define the module outputs for the depinject.
type Outputs struct {
depinject.Out

HTLCKeeper keeper.Keeper
Module appmodule.AppModule
}

func ProvideModule(in HTLCInputs) HTLCOutputs {
// ProvideModule creates and returns the HTLC module with the specified inputs.
//
// It takes Inputs as the parameter, which includes the configuration, codec, key, account keeper, and bank keeper.
// It returns Outputs containing the HTLC keeper and the app module.
func ProvideModule(in Inputs) Outputs {
// default to governance authority if not provided
authority := authtypes.NewModuleAddress(govtypes.ModuleName)
if in.Config.Authority != "" {
Expand All @@ -69,5 +79,5 @@ func ProvideModule(in HTLCInputs) HTLCOutputs {
)
m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper, in.LegacySubspace)

return HTLCOutputs{HTLCKeeper: keeper, Module: m}
return Outputs{HTLCKeeper: keeper, Module: m}
}
17 changes: 13 additions & 4 deletions modules/mt/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func (am AppModule) IsOnePerModuleType() {}
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}

type MTInputs struct {
// Inputs define the module inputs for the depinject.
type Inputs struct {
depinject.In

Config *modulev1.Module
Expand All @@ -37,19 +38,27 @@ type MTInputs struct {
BankKeeper types.BankKeeper
}

type MTOutputs struct {
// Outputs define the module outputs for the depinject.
type Outputs struct {
depinject.Out

MTKeeper keeper.Keeper
Module appmodule.AppModule
}

func ProvideModule(in MTInputs) MTOutputs {
// ProvideModule creates a new MTKeeper and AppModule using the provided inputs and returns the Outputs.
//
// Parameters:
// - in: the Inputs struct containing the necessary dependencies for creating the MTKeeper and AppModule.
//
// Returns:
// - Outputs: the struct containing the MTKeeper and AppModule.
func ProvideModule(in Inputs) Outputs {
keeper := keeper.NewKeeper(
in.Cdc,
in.Key,
)
m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper)

return MTOutputs{MTKeeper: keeper, Module: m}
return Outputs{MTKeeper: keeper, Module: m}
}
15 changes: 10 additions & 5 deletions modules/nft/depinject.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package module
package nft

import (
"cosmossdk.io/core/appmodule"
Expand Down Expand Up @@ -26,7 +26,8 @@ func (am AppModule) IsOnePerModuleType() {}
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}

type NFTInputs struct {
// Inputs define the arguments used to instantiate an app module.
type Inputs struct {
depinject.In

Config *modulev1.Module
Expand All @@ -37,14 +38,18 @@ type NFTInputs struct {
BankKeeper types.BankKeeper
}

type NFTOutputs struct {
// Outputs define the read-only arguments return by depinject.
type Outputs struct {
depinject.Out

NFTKeeper keeper.Keeper
Module appmodule.AppModule
}

func ProvideModule(in NFTInputs) NFTOutputs {
// ProvideModule provides a module for the NFT with the given inputs and returns the NFT keeper and module.
//
// Takes Inputs as input parameters and returns Outputs.
func ProvideModule(in Inputs) Outputs {
keeper := keeper.NewKeeper(
in.Cdc,
in.Key,
Expand All @@ -53,5 +58,5 @@ func ProvideModule(in NFTInputs) NFTOutputs {
)
m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper)

return NFTOutputs{NFTKeeper: keeper, Module: m}
return Outputs{NFTKeeper: keeper, Module: m}
}
2 changes: 1 addition & 1 deletion modules/nft/module.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package module
package nft

import (
"context"
Expand Down
17 changes: 13 additions & 4 deletions modules/oracle/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func (am AppModule) IsOnePerModuleType() {}
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}

type OracleInputs struct {
// Inputs define the module inputs for the depinject.
type Inputs struct {
depinject.In

Config *modulev1.Module
Expand All @@ -38,20 +39,28 @@ type OracleInputs struct {
ServiceKeeper types.ServiceKeeper
}

type OracleOutputs struct {
// Outputs define the module outputs for the depinject.
type Outputs struct {
depinject.Out

OracleKeeper keeper.Keeper
Module appmodule.AppModule
}

func ProvideModule(in OracleInputs) OracleOutputs {
// ProvideModule creates a new OracleKeeper and AppModule using the provided inputs and returns the Outputs.
//
// Parameters:
// - in: the Inputs struct containing the necessary dependencies for creating the OracleKeeper and AppModule.
//
// Returns:
// - Outputs: the struct containing the OracleKeeper and AppModule.
func ProvideModule(in Inputs) Outputs {
keeper := keeper.NewKeeper(
in.Cdc,
in.Key,
in.ServiceKeeper,
)
m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper)

return OracleOutputs{OracleKeeper: keeper, Module: m}
return Outputs{OracleKeeper: keeper, Module: m}
}
15 changes: 11 additions & 4 deletions modules/random/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func (am AppModule) IsOnePerModuleType() {}
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}

type RandomInputs struct {
// Inputs define the module inputs for the depinject.
type Inputs struct {
depinject.In

Config *modulev1.Module
Expand All @@ -38,14 +39,20 @@ type RandomInputs struct {
ServiceKeeper types.ServiceKeeper
}

type RandomOutputs struct {
// Outputs define the module outputs for the depinject.
type Outputs struct {
depinject.Out

RandomKeeper keeper.Keeper
Module appmodule.AppModule
}

func ProvideModule(in RandomInputs) RandomOutputs {
// ProvideModule creates a new AppModule and returns the Outputs.
//
// - in: the Inputs struct containing the necessary dependencies for creating the AppModule.
// Returns:
// - Outputs: the struct containing the RandomKeeper and AppModule.
func ProvideModule(in Inputs) Outputs {
keeper := keeper.NewKeeper(
in.Cdc,
in.Key,
Expand All @@ -54,5 +61,5 @@ func ProvideModule(in RandomInputs) RandomOutputs {
)
m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper)

return RandomOutputs{RandomKeeper: keeper, Module: m}
return Outputs{RandomKeeper: keeper, Module: m}
}
28 changes: 0 additions & 28 deletions modules/random/handler.go

This file was deleted.

14 changes: 10 additions & 4 deletions modules/record/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func (am AppModule) IsOnePerModuleType() {}
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}

type RecordInputs struct {
// Inputs define the module inputs for the depinject.
type Inputs struct {
depinject.In

Config *modulev1.Module
Expand All @@ -37,19 +38,24 @@ type RecordInputs struct {
BankKeeper types.BankKeeper
}

type RecordOutputs struct {
// Outputs define the module outputs for the depinject.
type Outputs struct {
depinject.Out

RecordKeeper keeper.Keeper
Module appmodule.AppModule
}

func ProvideModule(in RecordInputs) RecordOutputs {
// ProvideModule creates and returns the record module with the specified inputs.
//
// Takes Inputs as the parameter, which includes the codec, key, account keeper, and bank keeper.
// Returns Outputs containing the record keeper and the app module.
func ProvideModule(in Inputs) Outputs {
keeper := keeper.NewKeeper(
in.Cdc,
in.Key,
)
m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper)

return RecordOutputs{RecordKeeper: keeper, Module: m}
return Outputs{RecordKeeper: keeper, Module: m}
}
Loading

0 comments on commit 272cb15

Please sign in to comment.