diff options
author | Martin Holst Swende <martin@swende.se> | 2018-11-25 06:22:25 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-12-03 18:34:41 +0800 |
commit | 8698fbabf6c7811e8eec6e84512510e9c9a4eb45 (patch) | |
tree | bfd4570f18e332e2d51a140aa331ab9507bd2983 /cmd/puppeth/puppeth.go | |
parent | a3fd415c0f983cae35c329d97e0b6707561daef6 (diff) | |
download | dexon-8698fbabf6c7811e8eec6e84512510e9c9a4eb45.tar dexon-8698fbabf6c7811e8eec6e84512510e9c9a4eb45.tar.gz dexon-8698fbabf6c7811e8eec6e84512510e9c9a4eb45.tar.bz2 dexon-8698fbabf6c7811e8eec6e84512510e9c9a4eb45.tar.lz dexon-8698fbabf6c7811e8eec6e84512510e9c9a4eb45.tar.xz dexon-8698fbabf6c7811e8eec6e84512510e9c9a4eb45.tar.zst dexon-8698fbabf6c7811e8eec6e84512510e9c9a4eb45.zip |
cmd/puppeth: implement chainspec converters
Diffstat (limited to 'cmd/puppeth/puppeth.go')
-rw-r--r-- | cmd/puppeth/puppeth.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/cmd/puppeth/puppeth.go b/cmd/puppeth/puppeth.go index df3fff51b..3af1751ea 100644 --- a/cmd/puppeth/puppeth.go +++ b/cmd/puppeth/puppeth.go @@ -18,11 +18,15 @@ package main import ( + "encoding/json" + "io/ioutil" "math/rand" "os" "strings" "time" + "github.com/ethereum/go-ethereum/cmd/utils" + "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/log" "gopkg.in/urfave/cli.v1" ) @@ -43,6 +47,14 @@ func main() { Usage: "log level to emit to the screen", }, } + app.Commands = []cli.Command{ + cli.Command{ + Action: utils.MigrateFlags(convert), + Name: "convert", + Usage: "Convert from geth genesis into chainspecs for other nodes.", + ArgsUsage: "<geth-genesis.json>", + }, + } app.Action = func(c *cli.Context) error { // Set up the logger to print everything and the random generator log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(c.Int("loglevel")), log.StreamHandler(os.Stdout, log.TerminalFormat(true)))) @@ -58,3 +70,23 @@ func main() { } app.Run(os.Args) } + +func convert(ctx *cli.Context) error { + // Ensure we have a source genesis + log.Root().SetHandler(log.LvlFilterHandler(log.LvlInfo, log.StreamHandler(os.Stdout, log.TerminalFormat(true)))) + if len(ctx.Args()) != 1 { + utils.Fatalf("No geth genesis provided") + } + blob, err := ioutil.ReadFile(ctx.Args().First()) + if err != nil { + utils.Fatalf("Could not read file: %v", err) + } + + var genesis core.Genesis + if err := json.Unmarshal(blob, &genesis); err != nil { + utils.Fatalf("Failed parsing genesis: %v", err) + } + basename := strings.TrimRight(ctx.Args().First(), ".json") + convertGenesis(&genesis, basename, basename, []string{}) + return nil +} |