Merge pull request #92 from getamis/feature/genesis-save
cmd/istanbul: add save flag
This commit is contained in:
commit
a72a4b5633
|
@ -30,3 +30,6 @@ build/_vendor/pkg
|
|||
# travis
|
||||
profile.tmp
|
||||
profile.cov
|
||||
|
||||
# vscode
|
||||
.vscode/
|
|
@ -97,9 +97,9 @@ seal: 0x000000000000000000000000000000000000000000000000000000000000000000000000
|
|||
### `setup` subcommand
|
||||
|
||||
<details>
|
||||
<summary>Click here to exapand</summary>
|
||||
<summary>Click here to expand</summary>
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
</details>
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -33,4 +33,9 @@ var (
|
|||
Name: "nodes",
|
||||
Usage: "Print static nodes template",
|
||||
}
|
||||
|
||||
saveFlag = cli.BoolFlag{
|
||||
Name: "save",
|
||||
Usage: "Save to files",
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue