module

package
v1.7.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2023 License: Apache-2.0, Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package module contains application module patterns and associated "manager" functionality. The module pattern has been broken down by:

  • independent module functionality (AppModuleBasic)
  • inter-dependent module genesis functionality (AppModuleGenesis)
  • inter-dependent module simulation functionality (AppModuleSimulation)
  • inter-dependent module full functionality (AppModule)

inter-dependent module functionality is module functionality which somehow depends on other modules, typically through the module keeper. Many of the module keepers are dependent on each other, thus in order to access the full set of module functionality we need to define all the keepers/params-store/keys etc. This full set of advanced functionality is defined by the AppModule interface.

Independent module functions are separated to allow for the construction of the basic application structures required early on in the application definition and used to enable the definition of full module functionality later in the process. This separation is necessary, however we still want to allow for a high level pattern for modules to follow - for instance, such that we don't have to manually register all of the codecs for all the modules. This basic procedure as well as other basic patterns are handled through the use of BasicManager.

Lastly the interface for genesis functionality (AppModuleGenesis) has been separated out from full module functionality (AppModule) so that modules which are only used for genesis can take advantage of the Module patterns without needlessly defining many placeholder functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppModule

type AppModule interface {
	AppModuleGenesis

	// registers
	RegisterInvariants(sdk.InvariantRegistry)

	// routes
	Route() string
	NewHandler() sdk.Handler
	QuerierRoute() string
	NewQuerierHandler() sdk.Querier

	// ABCI
	BeginBlock(sdk.Context, abci.RequestBeginBlock)
	EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate
}

AppModule is the standard form for an application module

func NewGenesisOnlyAppModule

func NewGenesisOnlyAppModule(amg AppModuleGenesis) AppModule

NewGenesisOnlyAppModule creates a new GenesisOnlyAppModule object

type AppModuleAdapter added in v1.3.0

type AppModuleAdapter interface {
	AppModule
	AppModuleGenesisAdapter
	// registers
	RegisterInvariants(sdk.InvariantRegistry)
	// RegisterServices allows a module to register services
	RegisterServices(Configurator)
}

AppModule is the standard form for an application module

type AppModuleBasic

type AppModuleBasic interface {
	Name() string
	RegisterCodec(*codec.Codec)

	// genesis
	DefaultGenesis() json.RawMessage
	ValidateGenesis(json.RawMessage) error

	// client functionality
	RegisterRESTRoutes(context.CLIContext, *mux.Router)
	GetTxCmd(*codec.Codec) *cobra.Command
	GetQueryCmd(*codec.Codec) *cobra.Command
}

AppModuleBasic is the standard form for basic non-dependant elements of an application module.

type AppModuleBasicAdapter added in v1.3.0

type AppModuleBasicAdapter interface {
	AppModuleBasic
	RegisterInterfaces(codectypes.InterfaceRegistry)
	// client functionality
	RegisterGRPCGatewayRoutes(clictx.CLIContext, *runtime.ServeMux)
	GetTxCmdV2(cdc *codec.CodecProxy, reg codectypes.InterfaceRegistry) *cobra.Command
	GetQueryCmdV2(cdc *codec.CodecProxy, reg codectypes.InterfaceRegistry) *cobra.Command

	RegisterRouterForGRPC(cliCtx clictx.CLIContext, r *mux.Router)
}

AppModuleBasic is the standard form for basic non-dependant elements of an application module.

type AppModuleGenesis

type AppModuleGenesis interface {
	AppModuleBasic
	InitGenesis(sdk.Context, json.RawMessage) []abci.ValidatorUpdate
	ExportGenesis(sdk.Context) json.RawMessage
}

AppModuleGenesis is the standard form for an application module genesis functions

type AppModuleGenesisAdapter added in v1.3.0

type AppModuleGenesisAdapter interface {
	AppModuleGenesis
	AppModuleBasicAdapter
}

AppModuleGenesis is the standard form for an application module genesis functions

type AppModuleSimulation

type AppModuleSimulation interface {
	// randomized genesis states
	GenerateGenesisState(input *SimulationState)

	// content functions used to simulate governance proposals
	ProposalContents(simState SimulationState) []simulation.WeightedProposalContent

	// randomized module parameters for param change proposals
	RandomizedParams(r *rand.Rand) []simulation.ParamChange

	// register a func to decode the each module's defined types from their corresponding store key
	RegisterStoreDecoder(sdk.StoreDecoderRegistry)

	// simulation operations (i.e msgs) with their respective weight
	WeightedOperations(simState SimulationState) []simulation.WeightedOperation
}

AppModuleSimulation defines the standard functions that every module should expose for the SDK blockchain simulator

type BasicManager

type BasicManager map[string]AppModuleBasic

BasicManager is a collection of AppModuleBasic

func NewBasicManager

func NewBasicManager(modules ...AppModuleBasic) BasicManager

NewBasicManager creates a new BasicManager object

func (BasicManager) AddQueryCommands

func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command, cdc *codec.Codec)

AddQueryCommands adds all query commands to the rootQueryCmd

func (BasicManager) AddQueryCommandsV2 added in v1.3.0

func (bm BasicManager) AddQueryCommandsV2(rootQueryCmd *cobra.Command, proxy *codec.CodecProxy, reg interfacetypes.InterfaceRegistry)

func (BasicManager) AddTxCommands

func (bm BasicManager) AddTxCommands(rootTxCmd *cobra.Command, cdc *codec.Codec)

AddTxCommands adds all tx commands to the rootTxCmd

func (BasicManager) AddTxCommandsV2 added in v1.3.0

func (bm BasicManager) AddTxCommandsV2(rootTxCmd *cobra.Command, proxy *codec.CodecProxy, reg interfacetypes.InterfaceRegistry)

func (BasicManager) DefaultGenesis

func (bm BasicManager) DefaultGenesis() map[string]json.RawMessage

DefaultGenesis provides default genesis information for all modules

func (BasicManager) RegisterCodec

func (bm BasicManager) RegisterCodec(cdc *codec.Codec)

RegisterCodec registers all module codecs

func (BasicManager) RegisterGRPCGatewayRoutes added in v1.3.0

func (bm BasicManager) RegisterGRPCGatewayRoutes(clientCtx clientCtx.CLIContext, rtr *runtime.ServeMux)

RegisterGRPCGatewayRoutes registers all module rest routes

func (BasicManager) RegisterInterfaces added in v1.3.0

func (bm BasicManager) RegisterInterfaces(registry codectypes.InterfaceRegistry)

RegisterInterfaces registers all module interface types

func (BasicManager) RegisterRESTRoutes

func (bm BasicManager) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router)

RegisterRESTRoutes registers all module rest routes

func (BasicManager) RegisterRPCRouterForGRPC added in v1.3.0

func (bm BasicManager) RegisterRPCRouterForGRPC(clientCtx clientCtx.CLIContext, rtr *mux.Router)

func (BasicManager) ValidateGenesis

func (bm BasicManager) ValidateGenesis(genesis map[string]json.RawMessage) error

ValidateGenesis performs genesis state validation for all modules

type Configurator added in v1.3.0

type Configurator interface {
	// MsgServer returns a grpc.Server instance which allows registering services
	// that will handle TxBody.messages in transactions. These Msg's WILL NOT
	// be exposed as gRPC services.
	MsgServer() grpc.Server

	// QueryServer returns a grpc.Server instance which allows registering services
	// that will be exposed as gRPC services as well as ABCI query handlers.
	QueryServer() grpc.Server
}

Configurator provides the hooks to allow modules to configure and register their services in the RegisterServices method. It is designed to eventually support module object capabilities isolation as described in https://github.com/cosmos/cosmos-sdk/issues/7093

func NewConfigurator added in v1.3.0

func NewConfigurator(cdc *codec.Codec, msgServer grpc.Server, queryServer grpc.Server) Configurator

NewConfigurator returns a new Configurator instance

type GenesisOnlyAppModule

type GenesisOnlyAppModule struct {
	AppModuleGenesis
}

GenesisOnlyAppModule is an AppModule that only has import/export functionality

func (GenesisOnlyAppModule) BeginBlock

func (gam GenesisOnlyAppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock)

BeginBlock returns an empty module begin-block

func (GenesisOnlyAppModule) EndBlock

EndBlock returns an empty module end-block

func (GenesisOnlyAppModule) NewHandler

func (GenesisOnlyAppModule) NewHandler() sdk.Handler

NewHandler returns an empty module handler

func (GenesisOnlyAppModule) NewQuerierHandler

func (gam GenesisOnlyAppModule) NewQuerierHandler() sdk.Querier

NewQuerierHandler returns an empty module querier

func (GenesisOnlyAppModule) QuerierRoute

func (GenesisOnlyAppModule) QuerierRoute() string

QuerierRoute returns an empty module querier route

func (GenesisOnlyAppModule) RegisterInvariants

func (GenesisOnlyAppModule) RegisterInvariants(_ sdk.InvariantRegistry)

RegisterInvariants is a placeholder function register no invariants

func (GenesisOnlyAppModule) Route

func (GenesisOnlyAppModule) Route() string

Route empty module message route

type Manager

type Manager struct {
	Modules            map[string]AppModule
	OrderInitGenesis   []string
	OrderExportGenesis []string
	OrderBeginBlockers []string
	OrderEndBlockers   []string
}

Manager defines a module manager that provides the high level utility for managing and executing operations for a group of modules

func NewManager

func NewManager(modules ...AppModule) *Manager

NewManager creates a new Manager object

func (*Manager) BeginBlock

BeginBlock performs begin block functionality for all modules. It creates a child context with an event manager to aggregate events emitted from all modules.

func (*Manager) EndBlock

EndBlock performs end block functionality for all modules. It creates a child context with an event manager to aggregate events emitted from all modules.

func (*Manager) ExportGenesis

func (m *Manager) ExportGenesis(ctx sdk.Context) map[string]json.RawMessage

ExportGenesis performs export genesis functionality for modules

func (*Manager) InitGenesis

func (m *Manager) InitGenesis(ctx sdk.Context, genesisData map[string]json.RawMessage) abci.ResponseInitChain

InitGenesis performs init genesis functionality for modules

func (*Manager) RegisterInvariants

func (m *Manager) RegisterInvariants(ir sdk.InvariantRegistry)

RegisterInvariants registers all module routes and module querier routes

func (*Manager) RegisterRoutes

func (m *Manager) RegisterRoutes(router sdk.Router, queryRouter sdk.QueryRouter)

RegisterRoutes registers all module routes and module querier routes

func (*Manager) RegisterServices added in v1.3.0

func (m *Manager) RegisterServices(cfg Configurator)

RegisterServices registers all module services

func (*Manager) SetOrderBeginBlockers

func (m *Manager) SetOrderBeginBlockers(moduleNames ...string)

SetOrderBeginBlockers sets the order of set begin-blocker calls

func (*Manager) SetOrderEndBlockers

func (m *Manager) SetOrderEndBlockers(moduleNames ...string)

SetOrderEndBlockers sets the order of set end-blocker calls

func (*Manager) SetOrderExportGenesis

func (m *Manager) SetOrderExportGenesis(moduleNames ...string)

SetOrderExportGenesis sets the order of export genesis calls

func (*Manager) SetOrderInitGenesis

func (m *Manager) SetOrderInitGenesis(moduleNames ...string)

SetOrderInitGenesis sets the order of init genesis calls

type MigrationHandler added in v1.3.0

type MigrationHandler func(sdk.Context) error

type SimulationManager

type SimulationManager struct {
	Modules       []AppModuleSimulation    // array of app modules; we use an array for deterministic simulation tests
	StoreDecoders sdk.StoreDecoderRegistry // functions to decode the key-value pairs from each module's store
}

SimulationManager defines a simulation manager that provides the high level utility for managing and executing simulation functionalities for a group of modules

func NewSimulationManager

func NewSimulationManager(modules ...AppModuleSimulation) *SimulationManager

NewSimulationManager creates a new SimulationManager object

CONTRACT: All the modules provided must be also registered on the module Manager

func (*SimulationManager) GenerateGenesisStates

func (sm *SimulationManager) GenerateGenesisStates(simState *SimulationState)

GenerateGenesisStates generates a randomized GenesisState for each of the registered modules

func (*SimulationManager) GenerateParamChanges

func (sm *SimulationManager) GenerateParamChanges(seed int64) (paramChanges []simulation.ParamChange)

GenerateParamChanges generates randomized contents for creating params change proposal transactions

func (*SimulationManager) GetProposalContents

func (sm *SimulationManager) GetProposalContents(simState SimulationState) []simulation.WeightedProposalContent

GetProposalContents returns each module's proposal content generator function with their default operation weight and key.

func (*SimulationManager) RegisterStoreDecoders

func (sm *SimulationManager) RegisterStoreDecoders()

RegisterStoreDecoders registers each of the modules' store decoders into a map

func (*SimulationManager) WeightedOperations

func (sm *SimulationManager) WeightedOperations(simState SimulationState) []simulation.WeightedOperation

WeightedOperations returns all the modules' weighted operations of an application

type SimulationState

type SimulationState struct {
	AppParams    simulation.AppParams
	Cdc          *codec.Codec                         // application codec
	Rand         *rand.Rand                           // random number
	GenState     map[string]json.RawMessage           // genesis state
	Accounts     []simulation.Account                 // simulation accounts
	InitialStake int64                                // initial coins per account
	NumBonded    int64                                // number of initially bonded accounts
	GenTimestamp time.Time                            // genesis timestamp
	UnbondTime   time.Duration                        // staking unbond time stored to use it as the slashing maximum evidence duration
	ParamChanges []simulation.ParamChange             // simulated parameter changes from modules
	Contents     []simulation.WeightedProposalContent // proposal content generator functions with their default weight and app sim key
}

SimulationState is the input parameters used on each of the module's randomized GenesisState generator function

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL