Documentation ¶
Overview ¶
Package appmodule defines the functionality for registering Cosmos SDK app modules that are assembled using the github.com/verzth/cosmos-sdk/depinject dependency injection system and the declarative app configuration format handled by the appconfig package.
Index ¶
- func Register(msg proto.Message, options ...Option)
- func RegisterEventListener[E protoiface.MessageV1](registrar *EventListenerRegistrar, listener func(context.Context, E) error)
- type AppModule
- type EventListenerRegistrar
- type GenesisSource
- type GenesisTarget
- type HasBeginBlocker
- type HasEndBlocker
- type HasEventListeners
- type HasGenesis
- type HasServices
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Register ¶
Register registers a module with the global module registry. The provided protobuf message is used only to uniquely identify the protobuf module config type. The instance of the protobuf message used in the actual configuration will be injected into the container and can be requested by a provider function. All module initialization should be handled by the provided options.
Protobuf message types used for module configuration should define the cosmos.app.v1alpha.module option and must explicitly specify go_package to make debugging easier for users.
func RegisterEventListener ¶
func RegisterEventListener[E protoiface.MessageV1](registrar *EventListenerRegistrar, listener func(context.Context, E) error)
RegisterEventListener registers an event listener for event type E. If a non-nil error is returned by the listener, it will cause the process which emitted the event to fail.
Types ¶
type AppModule ¶
type AppModule interface { depinject.OnePerModuleType // IsAppModule is a dummy method to tag a struct as implementing an AppModule. IsAppModule() }
AppModule is a tag interface for app module implementations to use as a basis for extension interfaces. It provides no functionality itself, but is the type that all valid app modules should provide so that they can be identified by other modules (usually via depinject) as app modules.
type EventListenerRegistrar ¶
type EventListenerRegistrar struct {
// contains filtered or unexported fields
}
EventListenerRegistrar allows registering event listeners.
func (*EventListenerRegistrar) GetListeners ¶
func (e *EventListenerRegistrar) GetListeners() []any
GetListeners gets the event listeners that have been registered
type GenesisSource ¶
type GenesisSource = func(field string) (io.ReadCloser, error)
GenesisSource is a source for genesis data in JSON format. It may abstract over a single JSON object or separate files for each field in a JSON object that can be streamed over. Modules should open a separate io.ReadCloser for each field that is required. When fields represent arrays they can efficiently be streamed over. If there is no data for a field, this function should return nil, nil. It is important that the caller closes the reader when done with it.
type GenesisTarget ¶
type GenesisTarget = func(field string) (io.WriteCloser, error)
GenesisTarget is a target for writing genesis data in JSON format. It may abstract over a single JSON object or JSON in separate files that can be streamed over. Modules should open a separate io.WriteCloser for each field and should prefer writing fields as arrays when possible to support efficient iteration. It is important the caller closers the writer AND checks the error when done with it. It is expected that a stream of JSON data is written to the writer.
type HasBeginBlocker ¶
type HasBeginBlocker interface { AppModule // BeginBlock is a method that will be run before transactions are processed in // a block. BeginBlock(context.Context) error }
HasBeginBlocker is the extension interface that modules should implement to run custom logic before transaction processing in a block.
type HasEndBlocker ¶
type HasEndBlocker interface { AppModule // EndBlock is a method that will be run after transactions are processed in // a block. EndBlock(context.Context) error }
HasEndBlocker is the extension interface that modules should implement to run custom logic after transaction processing in a block.
type HasEventListeners ¶
type HasEventListeners interface { AppModule // RegisterEventListeners registers the module's events listeners. RegisterEventListeners(registrar *EventListenerRegistrar) }
HasEventListeners is the extension interface that modules should implement to register event listeners.
type HasGenesis ¶
type HasGenesis interface { AppModule // DefaultGenesis writes the default genesis for this module to the target. DefaultGenesis(GenesisTarget) error // ValidateGenesis validates the genesis data read from the source. ValidateGenesis(GenesisSource) error // InitGenesis initializes module state from the genesis source. InitGenesis(context.Context, GenesisSource) error // ExportGenesis exports module state to the genesis target. ExportGenesis(context.Context, GenesisTarget) error }
HasGenesis is the extension interface that modules should implement to handle genesis data and state initialization.
type HasServices ¶
type HasServices interface { AppModule // RegisterServices registers the module's services with the app's service // registrar. // // Two types of services are currently supported: // - read-only gRPC query services, which are the default. // - transaction message services, which must have the protobuf service // option "cosmos.msg.v1.service" (defined in "cosmos/msg/v1/service.proto") // set to true. // // The service registrar will figure out which type of service you are // implementing based on the presence (or absence) of protobuf options. You // do not need to specify this in golang code. RegisterServices(grpc.ServiceRegistrar) error }
HasServices is the extension interface that modules should implement to register implementations of services defined in .proto files.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is a functional option for implementing modules.
func Invoke ¶
func Invoke(invokers ...interface{}) Option
Invoke registers invokers to run with depinject. Each invoker will be called at the end of dependency graph configuration in the order in which it was defined. Invokers may not define output parameters, although they may return an error, and all of their input parameters will be marked as optional so that invokers impose no additional constraints on the dependency graph. Invoker functions should nil-check all inputs.