statusd: les sub-command implemented, closes #159

This commit is contained in:
Victor Farazdagi 2017-05-16 08:14:54 +03:00
parent 4f27a79d83
commit 4d1d5c7912
1 changed files with 64 additions and 0 deletions

64
cmd/statusd/lescmd.go Normal file
View File

@ -0,0 +1,64 @@
package main
import (
"fmt"
"github.com/status-im/status-go/geth"
"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..")
if err = geth.CreateAndRunNode(config); err != nil {
return err
}
// wait till node has been stopped
geth.NodeManagerInstance().Node().GethStack().Wait()
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
}