From 711ed74e091f2ada6e2aa84e5e62b9696b589d8a Mon Sep 17 00:00:00 2001 From: meowsbits <45600330+meowsbits@users.noreply.github.com> Date: Tue, 4 Feb 2020 04:49:13 -0600 Subject: [PATCH] cmd/geth: add 'dumpgenesis' command (#20191) Adds the 'geth dumpgenesis' command, which writes the configured genesis in JSON format to stdout. This provides a way to generate the data (structure and content) that can then be used with the 'geth init' command. --- cmd/geth/chaincmd.go | 23 +++++++++++++++++++++++ cmd/geth/main.go | 1 + 2 files changed, 24 insertions(+) diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 49e6a0594..5b176b6da 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -56,6 +56,18 @@ 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.`, } importCommand = cli.Command{ Action: utils.MigrateFlags(importChain), @@ -227,6 +239,17 @@ func initGenesis(ctx *cli.Context) error { return nil } +func dumpGenesis(ctx *cli.Context) error { + genesis := utils.MakeGenesis(ctx) + if genesis == nil { + genesis = core.DefaultGenesisBlock() + } + if err := json.NewEncoder(os.Stdout).Encode(genesis); err != nil { + utils.Fatalf("could not encode genesis") + } + return nil +} + func importChain(ctx *cli.Context) error { if len(ctx.Args()) < 1 { utils.Fatalf("This command requires an argument.") diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 8db19077a..0369e527b 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -205,6 +205,7 @@ func init() { copydbCommand, removedbCommand, dumpCommand, + dumpGenesisCommand, inspectCommand, // See accountcmd.go: accountCommand,