2017-03-28 09:04:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
|
|
|
|
2017-05-16 12:09:52 +00:00
|
|
|
"github.com/status-im/status-go/geth/api"
|
2017-03-28 09:04:52 +00:00
|
|
|
"github.com/status-im/status-go/geth/params"
|
|
|
|
"gopkg.in/urfave/cli.v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
gitCommit = "rely on linker: -ldflags -X main.GitCommit"
|
|
|
|
buildStamp = "rely on linker: -ldflags -X main.buildStamp"
|
|
|
|
app = makeApp(gitCommit)
|
2017-05-16 12:09:52 +00:00
|
|
|
statusAPI = api.NewStatusAPI()
|
2017-03-28 09:04:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2017-05-16 03:24:56 +00:00
|
|
|
// ProdModeFlag is whether we need dev or production settings
|
|
|
|
ProdModeFlag = cli.BoolFlag{
|
|
|
|
Name: "production",
|
|
|
|
Usage: "Whether production settings should be loaded",
|
|
|
|
}
|
|
|
|
|
2017-05-03 14:24:48 +00:00
|
|
|
// NodeKeyFileFlag is a node key file to be used as node's private key
|
2017-04-09 22:16:05 +00:00
|
|
|
NodeKeyFileFlag = cli.StringFlag{
|
|
|
|
Name: "nodekey",
|
|
|
|
Usage: "P2P node key file (private key)",
|
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
|
|
|
|
// DataDirFlag defines data directory for the node
|
2017-03-28 09:04:52 +00:00
|
|
|
DataDirFlag = cli.StringFlag{
|
|
|
|
Name: "datadir",
|
|
|
|
Usage: "Data directory for the databases and keystore",
|
2017-04-09 22:16:05 +00:00
|
|
|
Value: params.DataDir,
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
|
|
|
|
// NetworkIDFlag defines network ID
|
|
|
|
NetworkIDFlag = cli.IntFlag{
|
2017-03-28 09:04:52 +00:00
|
|
|
Name: "networkid",
|
2017-05-12 12:04:32 +00:00
|
|
|
Usage: "Network identifier (integer, 1=Homestead, 3=Ropsten, 4=Rinkeby)",
|
2017-05-16 03:24:56 +00:00
|
|
|
Value: params.RopstenNetworkID,
|
|
|
|
}
|
|
|
|
|
|
|
|
// LightEthEnabledFlag flags whether LES is enabled or not
|
|
|
|
LightEthEnabledFlag = cli.BoolFlag{
|
|
|
|
Name: "les",
|
|
|
|
Usage: "LES protocol enabled",
|
|
|
|
}
|
|
|
|
|
|
|
|
// WhisperEnabledFlag flags whether Whisper is enabled or not
|
|
|
|
WhisperEnabledFlag = cli.BoolFlag{
|
|
|
|
Name: "shh",
|
|
|
|
Usage: "SHH protocol enabled",
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
|
2017-05-16 03:24:56 +00:00
|
|
|
// SwarmEnabledFlag flags whether Swarm is enabled or not
|
|
|
|
SwarmEnabledFlag = cli.BoolFlag{
|
|
|
|
Name: "swarm",
|
|
|
|
Usage: "Swarm protocol enabled",
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
|
|
|
|
// HTTPEnabledFlag defines whether HTTP RPC endpoint should be opened or not
|
2017-03-28 09:04:52 +00:00
|
|
|
HTTPEnabledFlag = cli.BoolFlag{
|
|
|
|
Name: "http",
|
2017-08-04 16:14:17 +00:00
|
|
|
Usage: "HTTP RPC enpoint enabled (default: false)",
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
|
|
|
|
// HTTPPortFlag defines HTTP RPC port to use (if HTTP RPC is enabled)
|
2017-03-28 09:04:52 +00:00
|
|
|
HTTPPortFlag = cli.IntFlag{
|
|
|
|
Name: "httpport",
|
|
|
|
Usage: "HTTP RPC server's listening port",
|
2017-04-09 22:16:05 +00:00
|
|
|
Value: params.HTTPPort,
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
|
|
|
|
// IPCEnabledFlag flags whether IPC is enabled or not
|
2017-03-28 09:04:52 +00:00
|
|
|
IPCEnabledFlag = cli.BoolFlag{
|
|
|
|
Name: "ipc",
|
|
|
|
Usage: "IPC RPC enpoint enabled",
|
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
|
|
|
|
// LogLevelFlag defines a log reporting level
|
2017-03-28 09:04:52 +00:00
|
|
|
LogLevelFlag = cli.StringFlag{
|
|
|
|
Name: "log",
|
2017-08-24 08:50:16 +00:00
|
|
|
Usage: `Log level, one of: "ERROR", "WARN", "INFO", "DEBUG", and "TRACE"`,
|
2017-09-01 18:44:50 +00:00
|
|
|
Value: "",
|
|
|
|
}
|
|
|
|
|
|
|
|
// LogFileFlag defines a log filename
|
|
|
|
LogFileFlag = cli.StringFlag{
|
|
|
|
Name: "logfile",
|
|
|
|
Usage: `Path to the log file`,
|
|
|
|
Value: "",
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
// setup the app
|
2017-05-12 12:04:32 +00:00
|
|
|
app.Action = cli.ShowAppHelp
|
2017-03-28 09:04:52 +00:00
|
|
|
app.HideVersion = true // separate command prints version
|
|
|
|
app.Commands = []cli.Command{
|
2017-04-09 22:16:05 +00:00
|
|
|
versionCommand,
|
2017-05-12 12:04:32 +00:00
|
|
|
faucetCommand,
|
2017-05-16 03:24:56 +00:00
|
|
|
lesCommand,
|
2017-04-09 22:16:05 +00:00
|
|
|
wnodeCommand,
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
|
|
|
app.Flags = []cli.Flag{
|
2017-05-16 03:24:56 +00:00
|
|
|
ProdModeFlag,
|
2017-04-09 22:16:05 +00:00
|
|
|
NodeKeyFileFlag,
|
2017-03-28 09:04:52 +00:00
|
|
|
DataDirFlag,
|
2017-05-03 14:24:48 +00:00
|
|
|
NetworkIDFlag,
|
2017-03-28 09:04:52 +00:00
|
|
|
LogLevelFlag,
|
2017-09-01 18:44:50 +00:00
|
|
|
LogFileFlag,
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
|
|
|
app.Before = func(ctx *cli.Context) error {
|
|
|
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
app.After = func(ctx *cli.Context) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:04:32 +00:00
|
|
|
// makeApp creates an app with sane defaults.
|
|
|
|
func makeApp(gitCommit string) *cli.App {
|
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = filepath.Base(os.Args[0])
|
|
|
|
app.Author = ""
|
|
|
|
//app.Authors = nil
|
|
|
|
app.Email = ""
|
|
|
|
app.Version = params.Version
|
|
|
|
if gitCommit != "" {
|
|
|
|
app.Version += "-" + gitCommit[:8]
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
2017-05-12 12:04:32 +00:00
|
|
|
app.Usage = "CLI for Status nodes management"
|
|
|
|
return app
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// makeNodeConfig parses incoming CLI options and returns node configuration object
|
|
|
|
func makeNodeConfig(ctx *cli.Context) (*params.NodeConfig, error) {
|
2017-05-16 03:24:56 +00:00
|
|
|
nodeConfig, err := params.NewNodeConfig(
|
|
|
|
ctx.GlobalString(DataDirFlag.Name),
|
|
|
|
ctx.GlobalUint64(NetworkIDFlag.Name),
|
|
|
|
!ctx.GlobalBool(ProdModeFlag.Name))
|
2017-03-28 09:04:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-04-09 22:16:05 +00:00
|
|
|
nodeConfig.NodeKeyFile = ctx.GlobalString(NodeKeyFileFlag.Name)
|
2017-03-28 09:04:52 +00:00
|
|
|
|
2017-09-01 18:44:50 +00:00
|
|
|
if logLevel := ctx.GlobalString(LogLevelFlag.Name); logLevel != "" {
|
2017-03-28 09:04:52 +00:00
|
|
|
nodeConfig.LogLevel = logLevel
|
2017-09-01 18:44:50 +00:00
|
|
|
}
|
|
|
|
if logFile := ctx.GlobalString(LogFileFlag.Name); logFile != "" {
|
|
|
|
nodeConfig.LogFile = logFile
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nodeConfig, nil
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:04:32 +00:00
|
|
|
// printNodeConfig prints node config
|
|
|
|
func printNodeConfig(ctx *cli.Context) {
|
|
|
|
nodeConfig, err := makeNodeConfig(ctx)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Loaded Config: failed (err: %v)", err)
|
|
|
|
return
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
2017-05-12 12:04:32 +00:00
|
|
|
nodeConfig.LightEthConfig.Genesis = "SKIP"
|
|
|
|
fmt.Println("Loaded Config: ", nodeConfig)
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|