|
| 1 | +// Package module implements the Cosmos SDK AppModule interface for x/attestation. |
| 2 | +package module |
| 3 | + |
| 4 | +import ( |
| 5 | + "context" |
| 6 | + "encoding/json" |
| 7 | + "fmt" |
| 8 | + |
| 9 | + "github.com/grpc-ecosystem/grpc-gateway/runtime" |
| 10 | + "github.com/spf13/cobra" |
| 11 | + |
| 12 | + "cosmossdk.io/core/appmodule" |
| 13 | + "github.com/cosmos/cosmos-sdk/client" |
| 14 | + "github.com/cosmos/cosmos-sdk/codec" |
| 15 | + codectypes "github.com/cosmos/cosmos-sdk/codec/types" |
| 16 | + sdk "github.com/cosmos/cosmos-sdk/types" |
| 17 | + "github.com/cosmos/cosmos-sdk/types/module" |
| 18 | + |
| 19 | + "rampage/x/attestation/keeper" |
| 20 | + "rampage/x/attestation/types" |
| 21 | +) |
| 22 | + |
| 23 | +const ConsensusVersion = 1 |
| 24 | + |
| 25 | +var ( |
| 26 | + _ module.AppModuleBasic = AppModule{} |
| 27 | + _ appmodule.AppModule = AppModule{} |
| 28 | +) |
| 29 | + |
| 30 | +// AppModule implements the attestation module. |
| 31 | +type AppModule struct { |
| 32 | + cdc codec.Codec |
| 33 | + keeper keeper.Keeper |
| 34 | +} |
| 35 | + |
| 36 | +// NewAppModule creates a new AppModule for x/attestation. |
| 37 | +func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { |
| 38 | + return AppModule{cdc: cdc, keeper: keeper} |
| 39 | +} |
| 40 | + |
| 41 | +// Name returns the module name. |
| 42 | +func (AppModule) Name() string { return types.ModuleName } |
| 43 | + |
| 44 | +// RegisterLegacyAminoCodec registers amino codec (required by SDK). |
| 45 | +func (AppModule) RegisterLegacyAminoCodec(_ *codec.LegacyAmino) {} |
| 46 | + |
| 47 | +// RegisterInterfaces registers the module's interface types. |
| 48 | +func (AppModule) RegisterInterfaces(_ codectypes.InterfaceRegistry) {} |
| 49 | + |
| 50 | +// RegisterGRPCGatewayRoutes registers gRPC gateway routes. |
| 51 | +func (AppModule) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) {} |
| 52 | + |
| 53 | +// GetTxCmd returns the root tx command for x/attestation. |
| 54 | +func (AppModule) GetTxCmd() *cobra.Command { return nil } |
| 55 | + |
| 56 | +// GetQueryCmd returns the root query command for x/attestation. |
| 57 | +func (AppModule) GetQueryCmd() *cobra.Command { return nil } |
| 58 | + |
| 59 | +// DefaultGenesis returns the default genesis state as raw JSON. |
| 60 | +func (am AppModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { |
| 61 | + return cdc.MustMarshalJSON(types.DefaultGenesis()) |
| 62 | +} |
| 63 | + |
| 64 | +// ValidateGenesis validates the genesis state. |
| 65 | +func (am AppModule) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { |
| 66 | + var gs types.GenesisState |
| 67 | + if err := cdc.UnmarshalJSON(bz, &gs); err != nil { |
| 68 | + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) |
| 69 | + } |
| 70 | + return gs.Validate() |
| 71 | +} |
| 72 | + |
| 73 | +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. |
| 74 | +func (AppModule) IsOnePerModuleType() {} |
| 75 | + |
| 76 | +// IsAppModule implements the appmodule.AppModule interface. |
| 77 | +func (AppModule) IsAppModule() {} |
| 78 | + |
| 79 | +// ConsensusVersion implements AppModule/HasConsensusVersion. |
| 80 | +func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } |
| 81 | + |
| 82 | +// InitGenesis initializes the module's state from a genesis state. |
| 83 | +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) { |
| 84 | + var gs types.GenesisState |
| 85 | + cdc.MustUnmarshalJSON(bz, &gs) |
| 86 | + // TODO: apply genesis state to keeper (oracle node registrations, initial params) |
| 87 | + _ = gs |
| 88 | +} |
| 89 | + |
| 90 | +// ExportGenesis returns the module's genesis state as raw JSON. |
| 91 | +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { |
| 92 | + gs := types.GenesisState{ |
| 93 | + Params: am.keeper.GetParams(ctx), |
| 94 | + } |
| 95 | + return cdc.MustMarshalJSON(&gs) |
| 96 | +} |
| 97 | + |
| 98 | +// RegisterServices registers gRPC services. |
| 99 | +func (am AppModule) RegisterServices(cfg module.Configurator) { |
| 100 | + // TODO: register MsgServer and QueryServer once proto-generated stubs exist |
| 101 | + _ = cfg |
| 102 | +} |
| 103 | + |
| 104 | +// EndBlock executes all ABCI EndBlock logic for the attestation module. |
| 105 | +func (am AppModule) EndBlock(_ context.Context) error { |
| 106 | + // No periodic EndBlock logic required for attestation at this time. |
| 107 | + return nil |
| 108 | +} |
0 commit comments