diff --git a/modules/coinswap/depinject.go b/modules/coinswap/depinject.go index fd027d9d..33b167a9 100644 --- a/modules/coinswap/depinject.go +++ b/modules/coinswap/depinject.go @@ -21,6 +21,7 @@ func init() { ) } +// ProvideKeyTable provides module's KVStore keys func ProvideKeyTable() types.KeyTable { return types.ParamKeyTable() } @@ -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 @@ -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 != "" { @@ -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} } diff --git a/modules/farm/depinject.go b/modules/farm/depinject.go index bfb7655c..7a9a97c1 100644 --- a/modules/farm/depinject.go +++ b/modules/farm/depinject.go @@ -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() } @@ -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 @@ -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 != "" { @@ -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} } diff --git a/modules/htlc/depinject.go b/modules/htlc/depinject.go index 1b0ac44b..409471c9 100644 --- a/modules/htlc/depinject.go +++ b/modules/htlc/depinject.go @@ -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() } @@ -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 @@ -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 != "" { @@ -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} } diff --git a/modules/mt/depinject.go b/modules/mt/depinject.go index 97b43709..8dbe8687 100644 --- a/modules/mt/depinject.go +++ b/modules/mt/depinject.go @@ -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 @@ -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} } diff --git a/modules/nft/depinject.go b/modules/nft/depinject.go index 70fa1403..bfe83971 100644 --- a/modules/nft/depinject.go +++ b/modules/nft/depinject.go @@ -1,4 +1,4 @@ -package module +package nft import ( "cosmossdk.io/core/appmodule" @@ -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 @@ -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, @@ -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} } diff --git a/modules/nft/module.go b/modules/nft/module.go index 6aa350fb..da5a507e 100644 --- a/modules/nft/module.go +++ b/modules/nft/module.go @@ -1,4 +1,4 @@ -package module +package nft import ( "context" diff --git a/modules/oracle/depinject.go b/modules/oracle/depinject.go index 04a494ea..75a4d1a8 100644 --- a/modules/oracle/depinject.go +++ b/modules/oracle/depinject.go @@ -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 @@ -38,14 +39,22 @@ 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, @@ -53,5 +62,5 @@ func ProvideModule(in OracleInputs) OracleOutputs { ) m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper) - return OracleOutputs{OracleKeeper: keeper, Module: m} + return Outputs{OracleKeeper: keeper, Module: m} } diff --git a/modules/random/depinject.go b/modules/random/depinject.go index de9c2471..14e160a2 100644 --- a/modules/random/depinject.go +++ b/modules/random/depinject.go @@ -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 @@ -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, @@ -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} } diff --git a/modules/random/handler.go b/modules/random/handler.go deleted file mode 100644 index f619193c..00000000 --- a/modules/random/handler.go +++ /dev/null @@ -1,28 +0,0 @@ -package random - -import ( - errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - - "mods.irisnet.org/modules/random/keeper" - "mods.irisnet.org/modules/random/types" -) - -// NewHandler returns a handler for all random msgs -func NewHandler(k keeper.Keeper) sdk.Handler { - msgServer := keeper.NewMsgServerImpl(k) - - return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { - ctx = ctx.WithEventManager(sdk.NewEventManager()) - - switch msg := msg.(type) { - case *types.MsgRequestRandom: - res, err := msgServer.RequestRandom(sdk.WrapSDKContext(ctx), msg) - return sdk.WrapServiceResult(ctx, res, err) - - default: - return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg) - } - } -} diff --git a/modules/record/depinject.go b/modules/record/depinject.go index 97a11e61..0c7f83d4 100644 --- a/modules/record/depinject.go +++ b/modules/record/depinject.go @@ -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 @@ -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} } diff --git a/modules/service/depinject.go b/modules/service/depinject.go index 6a7909e3..a067540f 100644 --- a/modules/service/depinject.go +++ b/modules/service/depinject.go @@ -21,6 +21,13 @@ func init() { ) } +// ProvideKeyTable returns the KeyTable for the service module. +// +// It calls the ParamKeyTable function from the types package to retrieve the KeyTable. +// The KeyTable is used to register parameter sets for the service module. +// +// Returns: +// - types.KeyTable: The KeyTable for the service module. func ProvideKeyTable() types.KeyTable { return types.ParamKeyTable() } @@ -33,7 +40,8 @@ func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -type ServiceInputs struct { +// Inputs define the module inputs for the depinject. +type Inputs struct { depinject.In Config *modulev1.Module @@ -47,14 +55,19 @@ type ServiceInputs struct { LegacySubspace types.Subspace `optional:"true"` } -type ServiceOutputs struct { +// Outputs define the module outputs for the depinject. +type Outputs struct { depinject.Out ServiceKeeper keeper.Keeper Module appmodule.AppModule } -func ProvideModule(in ServiceInputs) ServiceOutputs { +// 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 != "" { @@ -71,5 +84,5 @@ func ProvideModule(in ServiceInputs) ServiceOutputs { ) m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper, in.LegacySubspace) - return ServiceOutputs{ServiceKeeper: keeper, Module: m} + return Outputs{ServiceKeeper: keeper, Module: m} } diff --git a/modules/token/depinject.go b/modules/token/depinject.go index 2f3b81a3..5c1bde07 100644 --- a/modules/token/depinject.go +++ b/modules/token/depinject.go @@ -35,8 +35,8 @@ func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -// TokenInputs is the input of the Token module -type TokenInputs struct { +// Inputs is the input of the Token module +type Inputs struct { depinject.In Config *modulev1.Module @@ -52,8 +52,8 @@ type TokenInputs struct { LegacySubspace types.Subspace `optional:"true"` } -// TokenOutputs is the output of the Token module -type TokenOutputs struct { +// Outputs is the output of the Token module +type Outputs struct { depinject.Out TokenKeeper keeper.Keeper @@ -63,7 +63,7 @@ type TokenOutputs struct { // ProvideModule provides a module for the token with the given inputs and returns the token keeper and module. // // Takes TokenInputs as input parameters and returns TokenOutputs. -func ProvideModule(in TokenInputs) TokenOutputs { +func ProvideModule(in Inputs) Outputs { // default to governance authority if not provided authority := authtypes.NewModuleAddress(govtypes.ModuleName) if in.Config.Authority != "" { @@ -82,5 +82,5 @@ func ProvideModule(in TokenInputs) TokenOutputs { ) m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper, in.LegacySubspace) - return TokenOutputs{TokenKeeper: keeper, Module: m} + return Outputs{TokenKeeper: keeper, Module: m} } diff --git a/modules/token/genesis_test.go b/modules/token/genesis_test.go deleted file mode 100644 index fdb5fea5..00000000 --- a/modules/token/genesis_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package token_test - -// import ( -// "testing" - -// "github.com/stretchr/testify/require" - -// "github.com/cometbft/cometbft/crypto/tmhash" -// tmproto "github.com/cometbft/cometbft/proto/tendermint/types" - -// sdk "github.com/cosmos/cosmos-sdk/types" - -// "mods.irisnet.org/modules/token" -// "mods.irisnet.org/simapp" -// v1 "mods.irisnet.org/modules/token/types/v1" -// ) - -// func TestExportGenesis(t *testing.T) { -// app := simapp.Setup(t, false) - -// ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - -// // export genesis -// genesisState := token.ExportGenesis(ctx, app.TokenKeeper) - -// require.Equal(t, v1.DefaultParams(), genesisState.Params) -// for _, token := range genesisState.Tokens { -// require.Equal(t, token, v1.GetNativeToken()) -// } -// } - -// func TestInitGenesis(t *testing.T) { -// app := simapp.Setup(t, false) - -// ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - -// // add token -// addr := sdk.AccAddress(tmhash.SumTruncated([]byte("addr1"))) -// ft := v1.NewToken("btc", "Bitcoin Network", "satoshi", 1, 1, 1, true, addr) - -// burnCoins := []sdk.Coin{ -// {Denom: ft.MinUnit, Amount: sdk.NewInt(1000)}, -// } -// genesis := v1.GenesisState{ -// Params: v1.DefaultParams(), -// Tokens: []v1.Token{ft}, -// BurnedCoins: burnCoins, -// } - -// // initialize genesis -// token.InitGenesis(ctx, app.TokenKeeper, genesis) - -// // query all tokens -// var tokens = app.TokenKeeper.GetTokens(ctx, nil) -// require.Equal(t, len(tokens), 2) -// require.Equal(t, tokens[0], &ft) - -// var coins = app.TokenKeeper.GetAllBurnCoin(ctx) -// require.Equal(t, burnCoins, coins) -// }