cosmos-sdk/server/export.go

46 lines
1023 B
Go
Raw Normal View History

2018-04-26 08:53:07 -07:00
package server
import (
"fmt"
2018-04-27 17:00:33 -07:00
2018-04-26 08:53:07 -07:00
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/cosmos/cosmos-sdk/wire"
tmtypes "github.com/tendermint/tendermint/types"
2018-04-26 08:53:07 -07:00
)
// ExportCmd dumps app state to JSON.
2018-04-27 17:36:11 -07:00
func ExportCmd(ctx *Context, cdc *wire.Codec, appExporter AppExporter) *cobra.Command {
2018-04-27 17:00:33 -07:00
return &cobra.Command{
2018-04-26 08:53:07 -07:00
Use: "export",
Short: "Export state to JSON",
2018-04-27 17:00:33 -07:00
RunE: func(cmd *cobra.Command, args []string) error {
home := viper.GetString("home")
traceStore := viper.GetString(flagTraceStore)
appState, validators, err := appExporter(home, ctx.Logger, traceStore)
2018-04-27 17:00:33 -07:00
if err != nil {
return errors.Errorf("error exporting state: %v\n", err)
2018-04-27 17:00:33 -07:00
}
doc, err := tmtypes.GenesisDocFromFile(ctx.Config.GenesisFile())
if err != nil {
return err
}
doc.AppStateJSON = appState
doc.Validators = validators
encoded, err := wire.MarshalJSONIndent(cdc, doc)
if err != nil {
return err
}
fmt.Println(string(encoded))
2018-04-27 17:00:33 -07:00
return nil
},
2018-04-26 08:53:07 -07:00
}
}