Export specific height

This commit is contained in:
Christopher Goes 2018-11-13 16:14:09 +01:00 committed by Jack Zampolin
parent 21795672c4
commit 17b9afaaa7
6 changed files with 21 additions and 6 deletions

View File

@ -324,6 +324,11 @@ func (app *GaiaApp) ExportAppStateAndValidators() (appState json.RawMessage, val
return appState, validators, nil
}
// load a particular height
func (app *GaiaApp) LoadHeight(height int64) {
app.LoadVersion(height, app.keyMain)
}
//______________________________________________________________________________________________
// Combined Staking Hooks

View File

@ -64,8 +64,11 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer) abci.Application
}
func exportAppStateAndTMValidators(
logger log.Logger, db dbm.DB, traceStore io.Writer,
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64,
) (json.RawMessage, []tmtypes.GenesisValidator, error) {
gApp := app.NewGaiaApp(logger, db, traceStore)
if height != -1 {
gApp.LoadHeight(height)
}
return gApp.ExportAppStateAndValidators()
}

View File

@ -126,7 +126,7 @@ func newApp(logger log.Logger, db dbm.DB, storeTracer io.Writer) abci.Applicatio
return app.NewBasecoinApp(logger, db, baseapp.SetPruning(viper.GetString("pruning")))
}
func exportAppStateAndTMValidators(logger log.Logger, db dbm.DB, storeTracer io.Writer) (
func exportAppStateAndTMValidators(logger log.Logger, db dbm.DB, storeTracer io.Writer, _ int64) (
json.RawMessage, []tmtypes.GenesisValidator, error) {
bapp := app.NewBasecoinApp(logger, db)
return bapp.ExportAppStateAndValidators()

View File

@ -133,7 +133,7 @@ func newApp(logger log.Logger, db dbm.DB, _ io.Writer) abci.Application {
return app.NewDemocoinApp(logger, db)
}
func exportAppStateAndTMValidators(logger log.Logger, db dbm.DB, _ io.Writer) (
func exportAppStateAndTMValidators(logger log.Logger, db dbm.DB, _ io.Writer, _ int64) (
json.RawMessage, []tmtypes.GenesisValidator, error) {
dapp := app.NewDemocoinApp(logger, db)
return dapp.ExportAppStateAndValidators()

View File

@ -19,7 +19,7 @@ type (
// AppExporter is a function that dumps all app state to
// JSON-serializable structure and returns the current validator set.
AppExporter func(log.Logger, dbm.DB, io.Writer) (json.RawMessage, []tmtypes.GenesisValidator, error)
AppExporter func(log.Logger, dbm.DB, io.Writer, int64) (json.RawMessage, []tmtypes.GenesisValidator, error)
)
func openDB(rootDir string) (dbm.DB, error) {

View File

@ -13,9 +13,13 @@ import (
"path"
)
const (
flagHeight = "height"
)
// ExportCmd dumps app state to JSON.
func ExportCmd(ctx *Context, cdc *codec.Codec, appExporter AppExporter) *cobra.Command {
return &cobra.Command{
cmd := &cobra.Command{
Use: "export",
Short: "Export state to JSON",
RunE: func(cmd *cobra.Command, args []string) error {
@ -45,7 +49,8 @@ func ExportCmd(ctx *Context, cdc *codec.Codec, appExporter AppExporter) *cobra.C
if err != nil {
return err
}
appState, validators, err := appExporter(ctx.Logger, db, traceWriter)
height := viper.GetInt64(flagHeight)
appState, validators, err := appExporter(ctx.Logger, db, traceWriter, height)
if err != nil {
return errors.Errorf("error exporting state: %v\n", err)
}
@ -67,6 +72,8 @@ func ExportCmd(ctx *Context, cdc *codec.Codec, appExporter AppExporter) *cobra.C
return nil
},
}
cmd.Flags().Int64(flagHeight, -1, "Export state from a particular height (-1 means latest height)")
return cmd
}
func isEmptyState(home string) (bool, error) {