aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/geth/chaincmd.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-11-30 19:34:24 +0800
committerGitHub <noreply@github.com>2016-11-30 19:34:24 +0800
commit86f9e836bea8161d9f6c1dacaa0b208e86b42e83 (patch)
treed096463c6fc28092902a8ada42788d9e5d653453 /cmd/geth/chaincmd.go
parenta90a170361f278d1ea4799a4c270f17f9c574779 (diff)
downloadgo-tangerine-86f9e836bea8161d9f6c1dacaa0b208e86b42e83.tar
go-tangerine-86f9e836bea8161d9f6c1dacaa0b208e86b42e83.tar.gz
go-tangerine-86f9e836bea8161d9f6c1dacaa0b208e86b42e83.tar.bz2
go-tangerine-86f9e836bea8161d9f6c1dacaa0b208e86b42e83.tar.lz
go-tangerine-86f9e836bea8161d9f6c1dacaa0b208e86b42e83.tar.xz
go-tangerine-86f9e836bea8161d9f6c1dacaa0b208e86b42e83.tar.zst
go-tangerine-86f9e836bea8161d9f6c1dacaa0b208e86b42e83.zip
cmd/geth: tidied up the source (#3385)
cmd/geth: tidied up the source
Diffstat (limited to 'cmd/geth/chaincmd.go')
-rw-r--r--cmd/geth/chaincmd.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go
index 1a7a9eb18..c77bd554c 100644
--- a/cmd/geth/chaincmd.go
+++ b/cmd/geth/chaincmd.go
@@ -32,6 +32,7 @@ import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
+ "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/trie"
"github.com/syndtr/goleveldb/leveldb/util"
@@ -39,6 +40,18 @@ import (
)
var (
+ initCommand = cli.Command{
+ Action: initGenesis,
+ Name: "init",
+ Usage: "Bootstrap and initialize a new genesis block",
+ ArgsUsage: "<genesisPath>",
+ Category: "BLOCKCHAIN COMMANDS",
+ Description: `
+The init command initializes a new genesis block and definition for the network.
+This is a destructive action and changes the network in which you will be
+participating.
+`,
+ }
importCommand = cli.Command{
Action: importChain,
Name: "import",
@@ -95,6 +108,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 {
+ genesisPath := ctx.Args().First()
+ if len(genesisPath) == 0 {
+ utils.Fatalf("must supply path to genesis JSON file")
+ }
+
+ stack := makeFullNode(ctx)
+ chaindb := utils.MakeChainDatabase(ctx, stack)
+
+ genesisFile, err := os.Open(genesisPath)
+ if err != nil {
+ utils.Fatalf("failed to read genesis file: %v", err)
+ }
+
+ block, err := core.WriteGenesisBlock(chaindb, genesisFile)
+ if err != nil {
+ utils.Fatalf("failed to write genesis block: %v", err)
+ }
+ glog.V(logger.Info).Infof("successfully wrote genesis block and/or chain rule set: %x", block.Hash())
+ return nil
+}
+
func importChain(ctx *cli.Context) error {
if len(ctx.Args()) != 1 {
utils.Fatalf("This command requires an argument.")