Skip to content

Commit

Permalink
feat: implement RegisterStoreDecoder for canto modules
Browse files Browse the repository at this point in the history
  • Loading branch information
poorphd committed Jul 26, 2024
1 parent ed9eef0 commit 6d15af1
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 18 deletions.
8 changes: 4 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)

Expand Down
8 changes: 7 additions & 1 deletion x/coinswap/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
13 changes: 9 additions & 4 deletions x/csr/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)

Expand All @@ -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}
}

Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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)
}
4 changes: 3 additions & 1 deletion x/epochs/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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.
Expand Down
11 changes: 9 additions & 2 deletions x/erc20/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 8 additions & 2 deletions x/govshuttle/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
}
Expand Down
4 changes: 3 additions & 1 deletion x/govshuttle/module_simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 11 additions & 3 deletions x/inflation/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"
)

Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 6d15af1

Please sign in to comment.