From 6d15af1affea7c97c8007cfadfb6b59a0fa14439 Mon Sep 17 00:00:00 2001 From: poorphd Date: Fri, 26 Jul 2024 16:52:28 +0900 Subject: [PATCH] feat: implement RegisterStoreDecoder for canto modules --- app/app.go | 8 ++++---- x/coinswap/module.go | 8 +++++++- x/csr/module.go | 13 +++++++++---- x/epochs/module.go | 4 +++- x/erc20/module.go | 11 +++++++++-- x/govshuttle/module.go | 10 ++++++++-- x/govshuttle/module_simulation.go | 4 +++- x/inflation/module.go | 14 +++++++++++--- 8 files changed, 54 insertions(+), 18 deletions(-) diff --git a/app/app.go b/app/app.go index fd82db17..2b86fd0c 100644 --- a/app/app.go +++ b/app/app.go @@ -758,12 +758,12 @@ func NewCanto( feemarket.NewAppModule(app.FeeMarketKeeper, feeMarketSs), // Canto app modules - inflation.NewAppModule(app.InflationKeeper, app.AccountKeeper, *app.StakingKeeper), - erc20.NewAppModule(app.Erc20Keeper, app.AccountKeeper, app.BankKeeper, app.EvmKeeper, app.FeeMarketKeeper, app.AccountKeeper.AddressCodec()), + inflation.NewAppModule(appCodec, app.InflationKeeper, app.AccountKeeper, *app.StakingKeeper), + erc20.NewAppModule(appCodec, app.Erc20Keeper, app.AccountKeeper, app.BankKeeper, app.EvmKeeper, app.FeeMarketKeeper, app.AccountKeeper.AddressCodec()), epochs.NewAppModule(appCodec, app.EpochsKeeper), onboarding.NewAppModule(*app.OnboardingKeeper), - govshuttle.NewAppModule(app.GovshuttleKeeper, app.AccountKeeper, app.AccountKeeper.AddressCodec()), - csr.NewAppModule(app.CSRKeeper, app.AccountKeeper), + govshuttle.NewAppModule(appCodec, app.GovshuttleKeeper, app.AccountKeeper, app.AccountKeeper.AddressCodec()), + csr.NewAppModule(appCodec, app.CSRKeeper, app.AccountKeeper), coinswap.NewAppModule(appCodec, app.CoinswapKeeper, app.AccountKeeper, app.BankKeeper), ) diff --git a/x/coinswap/module.go b/x/coinswap/module.go index bd726022..59916e5c 100644 --- a/x/coinswap/module.go +++ b/x/coinswap/module.go @@ -39,6 +39,11 @@ type AppModuleBasic struct { cdc codec.Codec } +// NewAppModuleBasic return a new AppModuleBasic +func NewAppModuleBasic(cdc codec.Codec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + // Name returns the coinswap module's name. func (AppModuleBasic) Name() string { return types.ModuleName } @@ -99,7 +104,7 @@ type AppModule struct { // NewAppModule creates a new AppModule object func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper) AppModule { return AppModule{ - AppModuleBasic: AppModuleBasic{cdc: cdc}, + AppModuleBasic: NewAppModuleBasic(cdc), keeper: keeper, accountKeeper: accountKeeper, bankKeeper: bankKeeper, @@ -163,6 +168,7 @@ func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.Weight // RegisterStoreDecoder registers a decoder for coinswap module's types func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { + sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) } // WeightedOperations returns the all the coinswap module operations with their respective weights. diff --git a/x/csr/module.go b/x/csr/module.go index 885573a3..7663cdcb 100644 --- a/x/csr/module.go +++ b/x/csr/module.go @@ -7,7 +7,6 @@ import ( // this line is used by starport scaffolding # 1 - "github.com/Canto-Network/Canto/v7/x/coinswap/simulation" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" @@ -23,6 +22,7 @@ import ( "github.com/Canto-Network/Canto/v7/x/csr/client/cli" "github.com/Canto-Network/Canto/v7/x/csr/keeper" + "github.com/Canto-Network/Canto/v7/x/csr/simulation" "github.com/Canto-Network/Canto/v7/x/csr/types" ) @@ -42,10 +42,10 @@ var ( // AppModuleBasic implements the AppModuleBasic interface for the csr module. type AppModuleBasic struct { - cdc codec.BinaryCodec + cdc codec.Codec } -func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { +func NewAppModuleBasic(cdc codec.Codec) AppModuleBasic { return AppModuleBasic{cdc: cdc} } @@ -107,11 +107,12 @@ type AppModule struct { } func NewAppModule( + cdc codec.Codec, keeper keeper.Keeper, acctKeeper authkeeper.AccountKeeper, ) AppModule { return AppModule{ - AppModuleBasic: AppModuleBasic{}, + AppModuleBasic: NewAppModuleBasic(cdc), keeper: keeper, accountKeeper: acctKeeper, } @@ -182,3 +183,7 @@ func (am AppModule) BeginBlock(ctx context.Context) error { func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { return simulation.ProposalMsgs() } + +func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { + sdr[types.ModuleName] = simulation.NewDecodeStore(am.cdc) +} diff --git a/x/epochs/module.go b/x/epochs/module.go index f1fa22d7..7ff2157c 100644 --- a/x/epochs/module.go +++ b/x/epochs/module.go @@ -22,6 +22,7 @@ import ( "github.com/Canto-Network/Canto/v7/x/epochs/client/cli" "github.com/Canto-Network/Canto/v7/x/epochs/keeper" + "github.com/Canto-Network/Canto/v7/x/epochs/simulation" "github.com/Canto-Network/Canto/v7/x/epochs/types" ) @@ -170,8 +171,9 @@ func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.We return []simtypes.WeightedProposalContent{} } -// RegisterStoreDecoder registers a decoder for supply module's types +// RegisterStoreDecoder registers a decoder for epoch module's types func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { + sdr[types.ModuleName] = simulation.NewDecodeStore(am.cdc) } // WeightedOperations returns the all the gov module operations with their respective weights. diff --git a/x/erc20/module.go b/x/erc20/module.go index b023079e..42890467 100644 --- a/x/erc20/module.go +++ b/x/erc20/module.go @@ -37,7 +37,12 @@ var ( // app module Basics object type AppModuleBasic struct { - ac address.Codec + ac address.Codec + cdc codec.Codec +} + +func NewAppModuleBasic(ac address.Codec, cdc codec.Codec) AppModuleBasic { + return AppModuleBasic{ac: ac, cdc: cdc} } func (AppModuleBasic) Name() string { @@ -102,6 +107,7 @@ type AppModule struct { // NewAppModule creates a new AppModule Object func NewAppModule( + cdc codec.Codec, k keeper.Keeper, ak authkeeper.AccountKeeper, bk types.BankKeeper, @@ -110,7 +116,7 @@ func NewAppModule( ac address.Codec, ) AppModule { return AppModule{ - AppModuleBasic: AppModuleBasic{ac: ac}, + AppModuleBasic: AppModuleBasic{ac: ac, cdc: cdc}, keeper: k, ak: ak, bk: bk, @@ -172,6 +178,7 @@ func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes } func (am AppModule) RegisterStoreDecoder(decoderRegistry simtypes.StoreDecoderRegistry) { + decoderRegistry[types.ModuleName] = simulation.NewDecodeStore(am.cdc) } func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { diff --git a/x/govshuttle/module.go b/x/govshuttle/module.go index 60bf666a..a66a84a9 100644 --- a/x/govshuttle/module.go +++ b/x/govshuttle/module.go @@ -42,7 +42,12 @@ var ( // AppModule implements the sdk.AppModuleBasic interface. type AppModuleBasic struct { - ac address.Codec + ac address.Codec + cdc codec.Codec +} + +func NewAppModuleBasic(ac address.Codec, cdc codec.Codec) AppModuleBasic { + return AppModuleBasic{ac: ac, cdc: cdc} } // Name returns the capability module's name. @@ -105,12 +110,13 @@ type AppModule struct { } func NewAppModule( + cdc codec.Codec, k keeper.Keeper, ak authkeeper.AccountKeeper, ac address.Codec, ) AppModule { return AppModule{ - AppModuleBasic: AppModuleBasic{ac: ac}, + AppModuleBasic: AppModuleBasic{ac: ac, cdc: cdc}, keeper: k, accountkeeper: ak, } diff --git a/x/govshuttle/module_simulation.go b/x/govshuttle/module_simulation.go index cfe1bb57..80d8dc8a 100644 --- a/x/govshuttle/module_simulation.go +++ b/x/govshuttle/module_simulation.go @@ -43,7 +43,9 @@ func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedP } // RegisterStoreDecoder registers a decoder -func (am AppModule) RegisterStoreDecoder(_ simtypes.StoreDecoderRegistry) {} +func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { + sdr[types.ModuleName] = govshuttlesimulation.NewDecodeStore(am.cdc) +} // WeightedOperations returns the all the gov module operations with their respective weights. func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { diff --git a/x/inflation/module.go b/x/inflation/module.go index e3564598..e1842acf 100644 --- a/x/inflation/module.go +++ b/x/inflation/module.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" - "github.com/Canto-Network/Canto/v7/x/inflation/simulation" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" @@ -23,6 +22,7 @@ import ( "github.com/Canto-Network/Canto/v7/x/inflation/client/cli" "github.com/Canto-Network/Canto/v7/x/inflation/keeper" + "github.com/Canto-Network/Canto/v7/x/inflation/simulation" "github.com/Canto-Network/Canto/v7/x/inflation/types" ) @@ -37,7 +37,13 @@ var ( ) // app module Basics object -type AppModuleBasic struct{} +type AppModuleBasic struct { + cdc codec.Codec +} + +func NewAppModuleBasic(cdc codec.Codec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} // Name returns the inflation module's name. func (AppModuleBasic) Name() string { @@ -105,12 +111,13 @@ type AppModule struct { // NewAppModule creates a new AppModule Object func NewAppModule( + cdc codec.Codec, k keeper.Keeper, ak authkeeper.AccountKeeper, sk stakingkeeper.Keeper, ) AppModule { return AppModule{ - AppModuleBasic: AppModuleBasic{}, + AppModuleBasic: NewAppModuleBasic(cdc), keeper: k, ak: ak, sk: sk, @@ -186,6 +193,7 @@ func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.Weight // RegisterStoreDecoder registers a decoder for inflation module's types. func (am AppModule) RegisterStoreDecoder(decoderRegistry simtypes.StoreDecoderRegistry) { + decoderRegistry[types.ModuleName] = simulation.NewDecodeStore(am.cdc) } // WeightedOperations doesn't return any inflation module operation.