forked from cerc-io/laconicd
Create skeleton for onboarding module (#2)
* Add proto files for onboarding module * Add general files for onboarding module * Add keeper files for onboarding module * Add module files for onboarding module * Update proto files * Add generated proto bindings * Use Keeper pointer in depinject * Fix lint errors
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package module
|
||||
|
||||
import (
|
||||
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
|
||||
)
|
||||
|
||||
// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface.
|
||||
func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
|
||||
return &autocliv1.ModuleOptions{
|
||||
Query: nil,
|
||||
Tx: nil,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package module
|
||||
|
||||
import (
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/core/store"
|
||||
"cosmossdk.io/depinject"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
|
||||
modulev1 "git.vdb.to/cerc-io/laconicd/api/cerc/onboarding/module/v1"
|
||||
"git.vdb.to/cerc-io/laconicd/x/onboarding/keeper"
|
||||
)
|
||||
|
||||
var _ appmodule.AppModule = AppModule{}
|
||||
|
||||
// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
|
||||
func (am AppModule) IsOnePerModuleType() {}
|
||||
|
||||
// IsAppModule implements the appmodule.AppModule interface.
|
||||
func (am AppModule) IsAppModule() {}
|
||||
|
||||
func init() {
|
||||
appmodule.Register(
|
||||
&modulev1.Module{},
|
||||
appmodule.Provide(ProvideModule),
|
||||
)
|
||||
}
|
||||
|
||||
type ModuleInputs struct {
|
||||
depinject.In
|
||||
|
||||
Cdc codec.Codec
|
||||
StoreService store.KVStoreService
|
||||
AddressCodec address.Codec
|
||||
|
||||
Config *modulev1.Module
|
||||
}
|
||||
|
||||
type ModuleOutputs struct {
|
||||
depinject.Out
|
||||
|
||||
Module appmodule.AppModule
|
||||
Keeper *keeper.Keeper
|
||||
}
|
||||
|
||||
func ProvideModule(in ModuleInputs) ModuleOutputs {
|
||||
// default to governance as authority if not provided
|
||||
authority := authtypes.NewModuleAddress("gov")
|
||||
if in.Config.Authority != "" {
|
||||
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
|
||||
}
|
||||
|
||||
k := keeper.NewKeeper(in.Cdc, in.AddressCodec, in.StoreService, authority.String())
|
||||
m := NewAppModule(in.Cdc, k)
|
||||
|
||||
return ModuleOutputs{Module: m, Keeper: k}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package module
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"cosmossdk.io/core/appmodule"
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
|
||||
"git.vdb.to/cerc-io/laconicd/x/onboarding"
|
||||
"git.vdb.to/cerc-io/laconicd/x/onboarding/keeper"
|
||||
)
|
||||
|
||||
var (
|
||||
_ module.AppModuleBasic = AppModule{}
|
||||
_ module.HasGenesis = AppModule{}
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
)
|
||||
|
||||
// ConsensusVersion defines the current module consensus version.
|
||||
const ConsensusVersion = 1
|
||||
|
||||
type AppModule struct {
|
||||
cdc codec.Codec
|
||||
keeper *keeper.Keeper
|
||||
}
|
||||
|
||||
// NewAppModule creates a new AppModule object
|
||||
func NewAppModule(cdc codec.Codec, keeper *keeper.Keeper) AppModule {
|
||||
return AppModule{
|
||||
cdc: cdc,
|
||||
keeper: keeper,
|
||||
}
|
||||
}
|
||||
|
||||
func NewAppModuleBasic(m AppModule) module.AppModuleBasic {
|
||||
return module.CoreAppModuleBasicAdaptor(m.Name(), m)
|
||||
}
|
||||
|
||||
// Name returns the onboarding module's name.
|
||||
func (AppModule) Name() string { return onboarding.ModuleName }
|
||||
|
||||
// RegisterLegacyAminoCodec registers the onboarding module's types on the LegacyAmino codec.
|
||||
// New modules do not need to support Amino.
|
||||
func (AppModule) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {}
|
||||
|
||||
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the onboarding module.
|
||||
func (AppModule) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) {
|
||||
// TODO: Implement
|
||||
// if err := onboarding.RegisterQueryHandlerClient(context.Background(), mux, onboarding.NewQueryClient(clientCtx)); err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
}
|
||||
|
||||
// RegisterInterfaces registers interfaces and implementations of the onboarding module.
|
||||
func (AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
||||
onboarding.RegisterInterfaces(registry)
|
||||
}
|
||||
|
||||
// ConsensusVersion implements AppModule/ConsensusVersion.
|
||||
func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }
|
||||
|
||||
// RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries.
|
||||
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
// TODO: Implement
|
||||
// Register servers
|
||||
// onboarding.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
|
||||
// onboarding.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(am.keeper))
|
||||
|
||||
// Register in place module state migration migrations
|
||||
// m := keeper.NewMigrator(am.keeper)
|
||||
// if err := cfg.RegisterMigration(onboarding.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
// panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", onboarding.ModuleName, err))
|
||||
// }
|
||||
}
|
||||
|
||||
// DefaultGenesis returns default genesis state as raw bytes for the module.
|
||||
func (AppModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
|
||||
return cdc.MustMarshalJSON(onboarding.NewGenesisState())
|
||||
}
|
||||
|
||||
// ValidateGenesis performs genesis state validation for the circuit module.
|
||||
func (AppModule) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
|
||||
var data onboarding.GenesisState
|
||||
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
|
||||
return fmt.Errorf("failed to unmarshal %s genesis state: %w", onboarding.ModuleName, err)
|
||||
}
|
||||
|
||||
return data.Validate()
|
||||
}
|
||||
|
||||
// InitGenesis performs genesis initialization for the onboarding module.
|
||||
// It returns no validator updates.
|
||||
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) {
|
||||
var genesisState onboarding.GenesisState
|
||||
cdc.MustUnmarshalJSON(data, &genesisState)
|
||||
|
||||
if err := am.keeper.InitGenesis(ctx, &genesisState); err != nil {
|
||||
panic(fmt.Sprintf("failed to initialize %s genesis state: %v", onboarding.ModuleName, err))
|
||||
}
|
||||
}
|
||||
|
||||
// ExportGenesis returns the exported genesis state as raw bytes for the circuit
|
||||
// module.
|
||||
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
|
||||
gs, err := am.keeper.ExportGenesis(ctx)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to export %s genesis state: %v", onboarding.ModuleName, err))
|
||||
}
|
||||
|
||||
return cdc.MustMarshalJSON(gs)
|
||||
}
|
||||
Reference in New Issue
Block a user