c97e18fc1f
---ci--- project: oy phase: 1 milestone: v0.5 status: complete requirements: covered: [REQ-033] partial: [] ---/ci---
95 lines
3.6 KiB
Go
95 lines
3.6 KiB
Go
package bridge
|
|
|
|
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/bridge/keeper"
|
|
"github.com/oy/openyield/x/bridge/types"
|
|
)
|
|
|
|
// module.go holds the bridge module's AppModule + RegisterServices (P1-03-01).
|
|
//
|
|
// 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.
|
|
//
|
|
// The IBCModule (porttypes.IBCModule) is constructed separately by the app
|
|
// wiring (NewIBCModule wraps the Keeper); the AppModule does not register
|
|
// the IBC port binding here (that is app-wiring territory, deferred — the
|
|
// simtest wires the IBCModule directly).
|
|
|
|
// ConsensusVersion is the bridge module's consensus version (AppModule).
|
|
const ConsensusVersion = 1
|
|
|
|
// AppModule is the bridge application module (simtest-grade — D-054).
|
|
type AppModule struct {
|
|
keeper keeper.Keeper
|
|
}
|
|
|
|
// NewAppModule constructs a new bridge AppModule.
|
|
func NewAppModule(cdc codec.Codec, storeKey storetypes.StoreKey, wk types.WatcherKeeper, bk types.BreadKeeper) AppModule {
|
|
k := keeper.NewKeeper(cdc, storeKey, wk, bk)
|
|
return AppModule{keeper: k}
|
|
}
|
|
|
|
// NewKeeper exposes the keeper for app wiring / IBC module construction.
|
|
func (am AppModule) NewKeeper() keeper.Keeper { return am.keeper }
|
|
|
|
// RegisterServices registers the bridge MsgServer. This is the simtest-grade
|
|
// wiring: the MsgServer is constructed from the keeper and exposed via the
|
|
// module's MsgServer method (tests use NewMsgServerImpl directly; the
|
|
// configurator path is not exercised in simtest per D-054).
|
|
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
|
// The hand-rolled MsgServer does not use the protobuf ServiceDesc
|
|
// registration (no codegen). Tests wire the MsgServer directly via
|
|
// keeper.NewMsgServerImpl(am.keeper). This no-op reference keeps the
|
|
// Configurator import stable for future codegen-based wiring.
|
|
_ = cfg
|
|
}
|
|
|
|
// MsgServer returns the bridge MsgServer for this module's keeper.
|
|
func (am AppModule) MsgServer() types.MsgServer {
|
|
return keeper.NewMsgServerImpl(am.keeper)
|
|
}
|
|
|
|
// IBCModule returns the bridge IBCModule for this module's keeper.
|
|
func (am AppModule) IBCModule() keeper.IBCModule {
|
|
return keeper.NewIBCModule(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 bridge module.
|
|
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) {
|
|
var gs types.GenesisState
|
|
cdc.MustUnmarshalJSON(data, &gs)
|
|
for _, r := range gs.Routes {
|
|
am.keeper.SetBridgeRoute(ctx, r)
|
|
}
|
|
}
|
|
|
|
// ExportGenesis returns the exported genesis state as raw bytes.
|
|
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
|
|
routes := am.keeper.AllBridgeRoutes(ctx)
|
|
gs := types.GenesisState{Routes: routes}
|
|
return cdc.MustMarshalJSON(&gs)
|
|
}
|
|
|
|
// Compile-time assertion: AppModule implements module.AppModule (simtest-grade
|
|
// — the RegisterServices signature matches the interface; the full
|
|
// AppModule interface is satisfied by the methods above + the
|
|
// appmodule.AppModule methods which are not exercised in simtest per D-054).
|
|
var _ module.HasName = AppModule{}
|
|
var _ module.HasConsensusVersion = AppModule{}
|