cmd/geth: add dumpgenesis command

I have a hard time believing this doesn't already exist...
although I could not find it anywhere.
This commit is contained in:
meows 2019-10-15 08:01:03 -05:00 committed by ia
parent 538f763fdc
commit a2a006928e
2 changed files with 24 additions and 0 deletions

View file

@ -56,6 +56,21 @@ This is a destructive action and changes the network in which you will be
participating.
It expects the genesis file as argument.`,
}
dumpGenesisCommand = cli.Command{
Action: utils.MigrateFlags(dumpGenesis),
Name: "dumpgenesis",
Usage: "Dumps genesis block JSON configuration to stdout",
ArgsUsage: "",
Flags: []cli.Flag{
utils.DataDirFlag,
},
Category: "BLOCKCHAIN COMMANDS",
Description: `
The dumpgenesis command dumps the genesis block configuration in JSON format to stdout.
This data can be used as a template or passed to the 'init' command.
`,
}
importCommand = cli.Command{
Action: utils.MigrateFlags(importChain),
@ -227,6 +242,14 @@ func initGenesis(ctx *cli.Context) error {
return nil
}
func dumpGenesis(ctx *cli.Context) error {
genesis := utils.MakeGenesis(ctx)
if err := json.NewEncoder(os.Stdout).Encode(genesis); err != nil {
utils.Fatalf("could not encode defaulty genesis")
}
return nil
}
func importChain(ctx *cli.Context) error {
if len(ctx.Args()) < 1 {
utils.Fatalf("This command requires an argument.")

View file

@ -208,6 +208,7 @@ func init() {
copydbCommand,
removedbCommand,
dumpCommand,
dumpGenesisCommand,
inspectCommand,
// See accountcmd.go:
accountCommand,