0g-chain/init/validate_genesis.go

52 lines
1.5 KiB
Go
Raw Normal View History

2019-06-20 13:37:57 +00:00
package init
import (
"fmt"
"os"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
2019-06-20 17:08:58 +00:00
"github.com/kava-labs/kava/app"
2019-06-20 13:37:57 +00:00
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/types"
)
// Validate genesis command takes
func ValidateGenesisCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "validate-genesis [file]",
Args: cobra.RangeArgs(0, 1),
Short: "validates the genesis file at the default location or at the location passed as an arg",
RunE: func(cmd *cobra.Command, args []string) (err error) {
// Load default if passed no args, otherwise load passed file
var genesis string
if len(args) == 0 {
genesis = ctx.Config.GenesisFile()
} else {
genesis = args[0]
}
//nolint
fmt.Fprintf(os.Stderr, "validating genesis file at %s\n", genesis)
var genDoc types.GenesisDoc
if genDoc, err = LoadGenesisDoc(cdc, genesis); err != nil {
return fmt.Errorf("Error loading genesis doc from %s: %s", genesis, err.Error())
}
var genstate app.GenesisState
if err = cdc.UnmarshalJSON(genDoc.AppState, &genstate); err != nil {
return fmt.Errorf("Error unmarshaling genesis doc %s: %s", genesis, err.Error())
}
2019-06-20 17:28:21 +00:00
if err = app.ValidateGenesisState(genstate); err != nil {
2019-06-20 13:37:57 +00:00
return fmt.Errorf("Error validating genesis file %s: %s", genesis, err.Error())
}
2019-06-20 17:08:58 +00:00
fmt.Printf("File at %s is a valid genesis file for kvd\n", genesis)
2019-06-20 13:37:57 +00:00
return nil
},
}
}