diff --git a/.gitignore b/.gitignore index e53e461d..fcce8d5b 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ build/_vendor/pkg # travis profile.tmp profile.cov + +# vscode +.vscode/ \ No newline at end of file diff --git a/README.md b/README.md index e7cadfb9..4e82deef 100644 --- a/README.md +++ b/README.md @@ -97,9 +97,9 @@ seal: 0x000000000000000000000000000000000000000000000000000000000000000000000000 ### `setup` subcommand
-Click here to exapand +Click here to expand -When `--nodes --verbose` flags are given, a `static-nodes.json` template as well as the validators' node keys, public keys, and addresses are generated. +When `--nodes --verbose` flags are given, a `static-nodes.json` template as well as the validators' node keys, public keys, and addresses are generated. When `--save` flag is given, the generated configs will be saved. **Note**: the generated `static-nodes.json` template are set with IP `0.0.0.0`, please make according change to match your environment. @@ -204,6 +204,7 @@ OPTIONS: --num value Number of validators (default: 0) --nodes Print static nodes template --verbose Print validator details + --save Save to files ```
diff --git a/cmd/istanbul/setup/cmd.go b/cmd/istanbul/setup/cmd.go index 21982638..1618c2ef 100644 --- a/cmd/istanbul/setup/cmd.go +++ b/cmd/istanbul/setup/cmd.go @@ -19,8 +19,12 @@ package setup import ( "encoding/json" "fmt" + "io/ioutil" "math/big" "net" + "os" + "path" + "strconv" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/p2p/discover" @@ -53,6 +57,7 @@ var ( numOfValidatorsFlag, staticNodesFlag, verboseFlag, + saveFlag, }, } ) @@ -83,6 +88,12 @@ func gen(ctx *cli.Context) error { if ctx.Bool(verboseFlag.Name) { str, _ := json.MarshalIndent(v, "", "\t") fmt.Println(string(str)) + + if ctx.Bool(saveFlag.Name) { + folderName := strconv.Itoa(i) + os.MkdirAll(folderName, os.ModePerm) + ioutil.WriteFile(path.Join(folderName, "nodekey"), []byte(nodekeys[i]), os.ModePerm) + } } } @@ -90,11 +101,16 @@ func gen(ctx *cli.Context) error { fmt.Print("\n\n\n") } + staticNodes, _ := json.MarshalIndent(nodes, "", "\t") if ctx.Bool(staticNodesFlag.Name) { - staticNodes, _ := json.MarshalIndent(nodes, "", "\t") - fmt.Println("static-nodes.json") + name := "static-nodes.json" + fmt.Println(name) fmt.Println(string(staticNodes)) fmt.Print("\n\n\n") + + if ctx.Bool(saveFlag.Name) { + ioutil.WriteFile(name, staticNodes, os.ModePerm) + } } genesis := genesis.New( @@ -106,5 +122,9 @@ func gen(ctx *cli.Context) error { fmt.Println("genesis.json") fmt.Println(string(jsonBytes)) + if ctx.Bool(saveFlag.Name) { + ioutil.WriteFile("genesis.json", jsonBytes, os.ModePerm) + } + return nil } diff --git a/cmd/istanbul/setup/flags.go b/cmd/istanbul/setup/flags.go index 225b423b..24f4cf49 100644 --- a/cmd/istanbul/setup/flags.go +++ b/cmd/istanbul/setup/flags.go @@ -33,4 +33,9 @@ var ( Name: "nodes", Usage: "Print static nodes template", } + + saveFlag = cli.BoolFlag{ + Name: "save", + Usage: "Save to files", + } )