cmd/puppeth: implement chainspec converters

This commit is contained in:
Martin Holst Swende
2018-11-24 23:22:25 +01:00
committed by Péter Szilágyi
parent a3fd415c0f
commit 8698fbabf6
9 changed files with 780 additions and 162 deletions

View File

@ -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
}