Skip to content

Commit

Permalink
make suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jwasinger committed Jun 28, 2022
1 parent dc4b07b commit d570187
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 5 additions & 7 deletions cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ It expects the genesis file as argument.`,
Name: "dumpgenesis",
Usage: "Dumps genesis block JSON configuration to stdout",
ArgsUsage: "",
Flags: utils.NetworkFlags,
Flags: append([]cli.Flag{utils.DataDirFlag}, utils.NetworkFlags...),
Category: "BLOCKCHAIN COMMANDS",
Description: `
The dumpgenesis command prints a genesis block as JSON. What it outputs is determined in order of preference: testnet preset if it is set, preexisting datadir, mainnet.`,
The dumpgenesis command prints the genesis configuration of the network preset
if one is set. Otherwise it prints the genesis from the datadir.`,
}
importCommand = cli.Command{
Action: utils.MigrateFlags(importChain),
Expand Down Expand Up @@ -208,7 +209,7 @@ func initGenesis(ctx *cli.Context) error {

func dumpGenesis(ctx *cli.Context) error {
// if there is a testnet preset enabled, dump that
if utils.IsTestnetPreset(ctx) {
if utils.IsNetworkPreset(ctx) {
genesis := utils.MakeGenesis(ctx)
if err := json.NewEncoder(os.Stdout).Encode(genesis); err != nil {
utils.Fatalf("could not encode genesis: %s", err)
Expand Down Expand Up @@ -239,10 +240,7 @@ func dumpGenesis(ctx *cli.Context) error {
if ctx.GlobalIsSet(utils.DataDirFlag.Name) {
utils.Fatalf("no existing datadir at %s", stack.Config().DataDir)
}
// no datadir exists or is specified, dump mainnet
if err := json.NewEncoder(os.Stdout).Encode(core.DefaultGenesisBlock()); err != nil {
utils.Fatalf("could not encode genesis: %s", err)
}
utils.Fatalf("no network preset provided. no exisiting genesis in the default datadir")
return nil
}

Expand Down
5 changes: 4 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1987,12 +1987,15 @@ func MakeChainDatabase(ctx *cli.Context, stack *node.Node, readonly bool) ethdb.
return chainDb
}

func IsTestnetPreset(ctx *cli.Context) bool {
func IsNetworkPreset(ctx *cli.Context) bool {
for _, flag := range TestnetFlags {
if ctx.GlobalBool(flag.GetName()) {
return true
}
}
if ctx.GlobalBool(MainnetFlag.Name) {
return true
}
return false
}

Expand Down

0 comments on commit d570187

Please sign in to comment.