From 8efa0c0a29c2a16edccb0ec9dee4dcf483ac4bb2 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Wed, 12 Mar 2025 23:22:35 +0800 Subject: [PATCH] cmd/XDC: improve init genesis --- cmd/XDC/chaincmd.go | 54 +++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/cmd/XDC/chaincmd.go b/cmd/XDC/chaincmd.go index e43319bdcc..e936d460d2 100644 --- a/cmd/XDC/chaincmd.go +++ b/cmd/XDC/chaincmd.go @@ -155,48 +155,30 @@ Use "ethereum dump 0" to dump the genesis block.`, // initGenesis will initialise the given JSON format genesis file and writes it as // the zero'd block (i.e. genesis) or will fail hard if it can't succeed. func initGenesis(ctx *cli.Context) error { - utils.CheckExclusive(ctx, utils.MainnetFlag, utils.TestnetFlag, utils.DevnetFlag) + if ctx.Args().Len() != 1 { + utils.Fatalf("need the genesis.json file or the network name [ mainnet | testnet | devnet ] as the only argument") + } var err error genesis := new(core.Genesis) - if ctx.Bool(utils.MainnetFlag.Name) { - if ctx.Args().Len() > 0 { - utils.Fatalf("The mainnet flag and genesis file can't be used at the same time") - } - err = json.Unmarshal(xdc_genesis.TestnetGenesis, &genesis) - } else if ctx.Bool(utils.TestnetFlag.Name) { - if ctx.Args().Len() > 0 { - utils.Fatalf("The testnet flag and genesis file can't be used at the same time") - } - err = json.Unmarshal(xdc_genesis.TestnetGenesis, &genesis) - } else if ctx.Bool(utils.DevnetFlag.Name) { - if ctx.Args().Len() > 0 { - utils.Fatalf("The devnet flag and genesis file can't be used at the same time") - } - err = json.Unmarshal(xdc_genesis.TestnetGenesis, &genesis) + genesisPath := ctx.Args().First() + if genesisPath == "mainnet" || genesisPath == "xinfin" { + err = json.Unmarshal(xdc_genesis.MainnetGenesis, genesis) + } else if genesisPath == "testnet" || genesisPath == "apothem" { + err = json.Unmarshal(xdc_genesis.TestnetGenesis, genesis) + } else if genesisPath == "devnet" { + err = json.Unmarshal(xdc_genesis.DevnetGenesis, genesis) } else { - if ctx.Args().Len() != 1 { - utils.Fatalf("need the genesis.json file or the network name [ mainnet | testnet | devnet ] as the only argument") + if len(genesisPath) == 0 { + utils.Fatalf("invalid path to genesis file") } - genesisPath := ctx.Args().First() - if genesisPath == "mainnet" || genesisPath == "xinfin" { - err = json.Unmarshal(xdc_genesis.MainnetGenesis, &genesis) - } else if genesisPath == "testnet" || genesisPath == "apothem" { - err = json.Unmarshal(xdc_genesis.TestnetGenesis, &genesis) - } else if genesisPath == "devnet" { - err = json.Unmarshal(xdc_genesis.DevnetGenesis, &genesis) - } else { - if len(genesisPath) == 0 { - utils.Fatalf("invalid path to genesis file") - } - var file *os.File - file, err = os.Open(genesisPath) - if err != nil { - utils.Fatalf("Failed to read genesis file: %v", err) - } - defer file.Close() - err = json.NewDecoder(file).Decode(genesis) + var file *os.File + file, err = os.Open(genesisPath) + if err != nil { + utils.Fatalf("Failed to read genesis file: %v", err) } + defer file.Close() + err = json.NewDecoder(file).Decode(genesis) } if err != nil { utils.Fatalf("invalid genesis json: %v", err)