Files
openyield/x/council/module.go
T
cloudinit-bot 6c34650a0d
docs-build / go test ./... (lexicon firewall + all x/* tests) (push) Has been cancelled
docs-build / mkdocs build (docs site artifact) (push) Has been cancelled
Merge milestone/v0.5-bearers-runtime into main (v0.5 Bearers Runtime feature milestone release)
v0.5 Bearers Runtime — 7 runtime REQs (REQ-033..039) shipped as feature.
8 modules promoted to runtime (MsgServer + simtest). cosmos-sdk v0.50.8 +
ibc-go v8.2.1 added (G-006 controlled exception). G-003 + locked-const
firewalls intact. 8 keeper packages ≥80% coverage. 5 GRILL decisions
ratified; 8 binding fixes landed; 5 P1+ flagged for v0.6+.

---ci---
project: oy
phase: 8
milestone: v0.5
status: complete
requirements:
  covered: [REQ-033, REQ-034, REQ-035, REQ-036, REQ-037, REQ-038, REQ-039]
  partial: []
---/ci---
2026-08-18 03:42:01 +00:00

102 lines
3.7 KiB
Go

package council
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/council/keeper"
"github.com/oy/openyield/x/council/types"
)
// module.go holds the council module's AppModule + RegisterServices
// (P7-02-01, REQ-039, D-060).
//
// The AppModule wraps the Proposal-lifecycle 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.
//
// The WatcherKeeper, StandKeeper, and GuildKeeper expected-keeper shims
// are injected at construction (nil-able for partial tests). The
// StandKeeper / GuildKeeper shims are the P7→P1 (x/stand) and P7→P1
// (x/guild) dep edges: P7 wires stubs in simtest (G-003 test exemption);
// the real keepers are wired at app construction.
// ConsensusVersion is the council module's consensus version (AppModule).
const ConsensusVersion = 1
// AppModule is the council application module (simtest-grade — D-054).
type AppModule struct {
keeper keeper.Keeper
}
// NewAppModule constructs a new council AppModule. The WatcherKeeper,
// StandKeeper, and GuildKeeper expected-keeper shims are injected
// (nil-able for partial tests).
func NewAppModule(cdc codec.Codec, storeKey storetypes.StoreKey, wk types.WatcherKeeper, sk types.StandKeeper, gk types.GuildKeeper) AppModule {
k := keeper.NewKeeper(cdc, storeKey, wk, sk, gk)
return AppModule{keeper: k}
}
// RegisterServices registers the council 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 council 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 council module's
// Proposal lifecycle. (The v0.2 Council registry genesis is the
// genesis-state Councils slice; this AppModule handles the v0.5 Proposal
// + Vote store.)
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) {
var gs types.GenesisState
cdc.MustUnmarshalJSON(data, &gs)
// Seed the runtime Council store from the genesis-state Councils
// slice (the SubmitProposal handler validates against the runtime
// Council store).
for _, c := range gs.Councils {
am.keeper.SetCouncil(ctx, c)
}
for _, p := range gs.Proposals {
am.keeper.SetProposal(ctx, p)
}
for _, v := range gs.Votes {
am.keeper.SetVote(ctx, v)
}
am.keeper.SetParams(gs.Params)
}
// ExportGenesis returns the exported genesis state as raw bytes.
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
gs := types.DefaultGenesisState()
for _, p := range am.keeper.AllProposals(ctx) {
gs.Proposals = append(gs.Proposals, p)
}
for _, v := range am.keeper.AllVotes(ctx) {
gs.Votes = append(gs.Votes, v)
}
gs.Params = am.keeper.GetParams()
return cdc.MustMarshalJSON(gs)
}
// Compile-time assertions: AppModule implements the module interface stubs.
var _ module.HasName = AppModule{}
var _ module.HasConsensusVersion = AppModule{}