package bearers import ( "encoding/json" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/oy/openyield/x/bearers/keeper" "github.com/oy/openyield/x/bearers/types" ) // module.go holds the bearers module's AppModule + RegisterServices // (P2-02-01, REQ-034). // // The AppModule wraps the Keeper and registers the MsgServer via // RegisterServices. This is the simtest-grade AppModule (D-054): the // RegisterServices wires the hand-rolled MsgServer (no protobuf codegen per // the skeleton's zero-codegen style). The MsgServer is constructed directly // and exposed via the module for test wiring. // ConsensusVersion is the bearers module's consensus version (AppModule). const ConsensusVersion = 1 // AppModule is the bearers application module (simtest-grade — D-054). type AppModule struct { keeper keeper.Keeper } // NewAppModule constructs a new bearers AppModule. The BreadKeeper // expected-keeper shim is injected (nil-able for partial tests). func NewAppModule(cdc codec.Codec, storeKey storetypes.StoreKey, bk types.BreadKeeper) AppModule { k := keeper.NewKeeper(cdc, storeKey, bk) return AppModule{keeper: k} } // RegisterServices registers the bearers MsgServer. Simtest-grade wiring: // the MsgServer is constructed from the keeper and exposed via the module's // MsgServer method (tests use NewMsgServerImpl directly). func (am AppModule) RegisterServices(cfg module.Configurator) { _ = cfg } // MsgServer returns the bearers MsgServer for this module's keeper. func (am AppModule) MsgServer() types.MsgServer { return keeper.NewMsgServerImpl(am.keeper) } // Name returns the module name. func (AppModule) Name() string { return types.ModuleName } // ConsensusVersion implements AppModule.ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } // InitGenesis performs genesis initialization for the bearers module. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { var gs types.GenesisState cdc.MustUnmarshalJSON(data, &gs) for _, s := range gs.Sessions { am.keeper.SetSession(ctx, s) } for _, q := range gs.QRs { am.keeper.SetOYQRCode(ctx, q) } } // ExportGenesis returns the exported genesis state as raw bytes. func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { sessions := am.keeper.AllSessions(ctx) qrs := am.keeper.AllOYQRCodes(ctx) gs := types.GenesisState{Sessions: sessions, QRs: qrs} return cdc.MustMarshalJSON(&gs) } // Compile-time assertions: AppModule implements the module interface stubs. var _ module.HasName = AppModule{} var _ module.HasConsensusVersion = AppModule{}