2017-05-16 05:14:54 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/geth/params"
|
|
|
|
"gopkg.in/urfave/cli.v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
lesCommand = cli.Command{
|
|
|
|
Action: lesCommandHandler,
|
|
|
|
Name: "les",
|
|
|
|
Usage: "Starts Light Ethereum node",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
WhisperEnabledFlag,
|
|
|
|
SwarmEnabledFlag,
|
|
|
|
HTTPEnabledFlag,
|
|
|
|
HTTPPortFlag,
|
|
|
|
IPCEnabledFlag,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// lesCommandHandler handles `statusd les` command
|
|
|
|
func lesCommandHandler(ctx *cli.Context) error {
|
|
|
|
config, err := parseLESCommandConfig(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("can not parse config: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Starting Light Status node..")
|
2017-05-16 12:09:52 +00:00
|
|
|
if err := statusAPI.StartNode(config); err != nil {
|
2017-05-16 05:14:54 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// wait till node has been stopped
|
2017-05-16 12:09:52 +00:00
|
|
|
node, err := statusAPI.NodeManager().Node()
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
node.Wait()
|
2017-05-16 05:14:54 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// parseLESCommandConfig parses incoming CLI options and returns node configuration object
|
|
|
|
func parseLESCommandConfig(ctx *cli.Context) (*params.NodeConfig, error) {
|
|
|
|
nodeConfig, err := makeNodeConfig(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enabled sub-protocols
|
|
|
|
nodeConfig.LightEthConfig.Enabled = true
|
|
|
|
nodeConfig.WhisperConfig.Enabled = ctx.Bool(WhisperEnabledFlag.Name)
|
|
|
|
nodeConfig.SwarmConfig.Enabled = ctx.Bool(SwarmEnabledFlag.Name)
|
|
|
|
|
|
|
|
// RPC configuration
|
|
|
|
if !ctx.Bool(HTTPEnabledFlag.Name) {
|
|
|
|
nodeConfig.HTTPHost = "" // HTTP RPC is disabled
|
|
|
|
}
|
|
|
|
nodeConfig.HTTPPort = ctx.Int(HTTPPortFlag.Name)
|
|
|
|
nodeConfig.IPCEnabled = ctx.Bool(IPCEnabledFlag.Name)
|
|
|
|
|
|
|
|
return nodeConfig, nil
|
|
|
|
}
|