forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validate-genesis command (cosmos#3399)
- Loading branch information
1 parent
f494a92
commit df86585
Showing
5 changed files
with
71 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
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
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
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
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,52 @@ | ||
package init | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/cosmos/cosmos-sdk/cmd/gaia/app" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/server" | ||
"github.com/pkg/errors" | ||
"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 errors.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 errors.Errorf("Error unmarshaling genesis doc %s: %s", genesis, err.Error()) | ||
} | ||
|
||
if err = app.GaiaValidateGenesisState(genstate); err != nil { | ||
return errors.Errorf("Error validating genesis file %s: %s", genesis, err.Error()) | ||
} | ||
|
||
fmt.Printf("File at %s is a valid genesis file for gaiad\n", genesis) | ||
return nil | ||
}, | ||
} | ||
} |