Skip to content

Commit

Permalink
feat(core): add genesis API (#14223)
Browse files Browse the repository at this point in the history
Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
  • Loading branch information
aaronc and amaury1093 authored Dec 15, 2022
1 parent ec73fbd commit 2d5b67c
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions core/appmodule/genesis.go
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)

0 comments on commit 2d5b67c

Please sign in to comment.