-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add begin/end block extension interfaces (#14604)
(cherry picked from commit fa7ff32) # Conflicts: # core/appmodule/module.go
- Loading branch information
1 parent
7c82d64
commit 3201417
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package appmodule | ||
|
||
import ( | ||
"context" | ||
|
||
"cosmossdk.io/depinject" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
// 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 AppModule interface { | ||
depinject.OnePerModuleType | ||
|
||
// IsAppModule is a dummy method to tag a struct as implementing an AppModule. | ||
IsAppModule() | ||
} | ||
|
||
// HasServices is the extension interface that modules should implement to register | ||
// implementations of services defined in .proto files. | ||
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) | ||
} | ||
|
||
// HasBeginBlocker is the extension interface that modules should implement to run | ||
// custom logic before transaction processing in a block. | ||
type HasBeginBlocker interface { | ||
AppModule | ||
|
||
// BeginBlock is a method that will be run before transactions are processed in | ||
// a block. | ||
BeginBlock(context.Context) error | ||
} | ||
|
||
// HasEndBlocker is the extension interface that modules should implement to run | ||
// custom logic after transaction processing in a block. | ||
type HasEndBlocker interface { | ||
AppModule | ||
|
||
// EndBlock is a method that will be run after transactions are processed in | ||
// a block. | ||
EndBlock(context.Context) error | ||
} |