-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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 genesis API (#14223)
Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
- Loading branch information
1 parent
ec73fbd
commit 2d5b67c
Showing
1 changed file
with
41 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,41 @@ | ||
package appmodule | ||
|
||
import ( | ||
"context" | ||
"io" | ||
) | ||
|
||
// HasGenesis is the extension interface that modules should implement to handle | ||
// genesis data and state initialization. | ||
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 | ||
} | ||
|
||
// 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 GenesisSource = func(field string) (io.ReadCloser, 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 GenesisTarget = func(field string) (io.WriteCloser, error) |