Skip to content

Commit

Permalink
make suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jwasinger committed Jul 11, 2022
1 parent cd34a0f commit 5705985
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
15 changes: 7 additions & 8 deletions cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,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: importChain,
Expand Down Expand Up @@ -203,7 +205,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 @@ -231,13 +233,10 @@ func dumpGenesis(ctx *cli.Context) error {
}
return nil
}
if ctx.GlobalIsSet(utils.DataDirFlag.Name) {
if ctx.IsSet(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
7 changes: 5 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2134,12 +2134,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()) {
if ctx.Bool(flag.String()) {
return true
}
}
if ctx.Bool(MainnetFlag.Name) {
return true
}
return false
}

Expand Down

0 comments on commit 5705985

Please sign in to comment.