cmd/istanbul: add save flag
This commit is contained in:
parent
199d08e998
commit
ce4d048e2b
|
@ -30,3 +30,6 @@ build/_vendor/pkg
|
||||||
# travis
|
# travis
|
||||||
profile.tmp
|
profile.tmp
|
||||||
profile.cov
|
profile.cov
|
||||||
|
|
||||||
|
# vscode
|
||||||
|
.vscode/
|
|
@ -97,9 +97,9 @@ seal: 0x000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
### `setup` subcommand
|
### `setup` subcommand
|
||||||
|
|
||||||
<details>
|
<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.
|
**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)
|
--num value Number of validators (default: 0)
|
||||||
--nodes Print static nodes template
|
--nodes Print static nodes template
|
||||||
--verbose Print validator details
|
--verbose Print validator details
|
||||||
|
--save Save to files
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
|
@ -19,8 +19,12 @@ package setup
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"math/big"
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||||
|
@ -53,6 +57,7 @@ var (
|
||||||
numOfValidatorsFlag,
|
numOfValidatorsFlag,
|
||||||
staticNodesFlag,
|
staticNodesFlag,
|
||||||
verboseFlag,
|
verboseFlag,
|
||||||
|
saveFlag,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -83,6 +88,12 @@ func gen(ctx *cli.Context) error {
|
||||||
if ctx.Bool(verboseFlag.Name) {
|
if ctx.Bool(verboseFlag.Name) {
|
||||||
str, _ := json.MarshalIndent(v, "", "\t")
|
str, _ := json.MarshalIndent(v, "", "\t")
|
||||||
fmt.Println(string(str))
|
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")
|
fmt.Print("\n\n\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
staticNodes, _ := json.MarshalIndent(nodes, "", "\t")
|
||||||
if ctx.Bool(staticNodesFlag.Name) {
|
if ctx.Bool(staticNodesFlag.Name) {
|
||||||
staticNodes, _ := json.MarshalIndent(nodes, "", "\t")
|
name := "static-nodes.json"
|
||||||
fmt.Println("static-nodes.json")
|
fmt.Println(name)
|
||||||
fmt.Println(string(staticNodes))
|
fmt.Println(string(staticNodes))
|
||||||
fmt.Print("\n\n\n")
|
fmt.Print("\n\n\n")
|
||||||
|
|
||||||
|
if ctx.Bool(saveFlag.Name) {
|
||||||
|
ioutil.WriteFile(name, staticNodes, os.ModePerm)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
genesis := genesis.New(
|
genesis := genesis.New(
|
||||||
|
@ -106,5 +122,9 @@ func gen(ctx *cli.Context) error {
|
||||||
fmt.Println("genesis.json")
|
fmt.Println("genesis.json")
|
||||||
fmt.Println(string(jsonBytes))
|
fmt.Println(string(jsonBytes))
|
||||||
|
|
||||||
|
if ctx.Bool(saveFlag.Name) {
|
||||||
|
ioutil.WriteFile("genesis.json", jsonBytes, os.ModePerm)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,4 +33,9 @@ var (
|
||||||
Name: "nodes",
|
Name: "nodes",
|
||||||
Usage: "Print static nodes template",
|
Usage: "Print static nodes template",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
saveFlag = cli.BoolFlag{
|
||||||
|
Name: "save",
|
||||||
|
Usage: "Save to files",
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue