refactor(modules): adopt appmodulev2.Hasgenesis (#19627)

Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
Marko
2024-03-11 10:22:16 +00:00
committed by GitHub
co-authored by Julien Robert
parent d4e52069f7
commit d2e40963ed
72 changed files with 686 additions and 694 deletions
+11 -10
View File
@@ -10,6 +10,7 @@ import (
"google.golang.org/grpc"
"cosmossdk.io/core/appmodule"
appmodulev2 "cosmossdk.io/core/appmodule/v2"
"cosmossdk.io/core/registry"
"cosmossdk.io/x/group"
"cosmossdk.io/x/group/client/cli"
@@ -33,7 +34,7 @@ var (
_ module.HasGRPCGateway = AppModule{}
_ appmodule.HasRegisterInterfaces = AppModule{}
_ module.AppModuleSimulation = AppModule{}
_ module.HasGenesis = AppModule{}
_ appmodulev2.HasGenesis = AppModule{}
_ module.HasInvariants = AppModule{}
_ appmodule.AppModule = AppModule{}
@@ -124,28 +125,28 @@ func (am AppModule) EndBlock(ctx context.Context) error {
}
// DefaultGenesis returns default genesis state as raw bytes for the group module.
func (AppModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(group.NewGenesisState())
func (am AppModule) DefaultGenesis() json.RawMessage {
return am.cdc.MustMarshalJSON(group.NewGenesisState())
}
// ValidateGenesis performs genesis state validation for the group module.
func (AppModule) ValidateGenesis(cdc codec.JSONCodec, config sdkclient.TxEncodingConfig, bz json.RawMessage) error {
func (am AppModule) ValidateGenesis(bz json.RawMessage) error {
var data group.GenesisState
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
if err := am.cdc.UnmarshalJSON(bz, &data); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", group.ModuleName, err)
}
return data.Validate()
}
// InitGenesis performs genesis initialization for the group module.
func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) {
am.keeper.InitGenesis(ctx, cdc, data)
func (am AppModule) InitGenesis(ctx context.Context, data json.RawMessage) error {
return am.keeper.InitGenesis(ctx, am.cdc, data)
}
// ExportGenesis returns the exported genesis state as raw bytes for the group module.
func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage {
gs := am.keeper.ExportGenesis(ctx, cdc)
return cdc.MustMarshalJSON(gs)
func (am AppModule) ExportGenesis(ctx context.Context) (json.RawMessage, error) {
gs := am.keeper.ExportGenesis(ctx, am.cdc)
return am.cdc.MarshalJSON(gs)
}
// GenerateGenesisState creates a randomized GenState of the group module.