Skip to content

Commit 711ed74

Browse files
authored
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.
1 parent 058a4ac commit 711ed74

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

cmd/geth/chaincmd.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ This is a destructive action and changes the network in which you will be
5656
participating.
5757
5858
It expects the genesis file as argument.`,
59+
}
60+
dumpGenesisCommand = cli.Command{
61+
Action: utils.MigrateFlags(dumpGenesis),
62+
Name: "dumpgenesis",
63+
Usage: "Dumps genesis block JSON configuration to stdout",
64+
ArgsUsage: "",
65+
Flags: []cli.Flag{
66+
utils.DataDirFlag,
67+
},
68+
Category: "BLOCKCHAIN COMMANDS",
69+
Description: `
70+
The dumpgenesis command dumps the genesis block configuration in JSON format to stdout.`,
5971
}
6072
importCommand = cli.Command{
6173
Action: utils.MigrateFlags(importChain),
@@ -227,6 +239,17 @@ func initGenesis(ctx *cli.Context) error {
227239
return nil
228240
}
229241

242+
func dumpGenesis(ctx *cli.Context) error {
243+
genesis := utils.MakeGenesis(ctx)
244+
if genesis == nil {
245+
genesis = core.DefaultGenesisBlock()
246+
}
247+
if err := json.NewEncoder(os.Stdout).Encode(genesis); err != nil {
248+
utils.Fatalf("could not encode genesis")
249+
}
250+
return nil
251+
}
252+
230253
func importChain(ctx *cli.Context) error {
231254
if len(ctx.Args()) < 1 {
232255
utils.Fatalf("This command requires an argument.")

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ func init() {
205205
copydbCommand,
206206
removedbCommand,
207207
dumpCommand,
208+
dumpGenesisCommand,
208209
inspectCommand,
209210
// See accountcmd.go:
210211
accountCommand,

0 commit comments

Comments
 (0)