2017-05-12 12:04:32 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/geth/params"
|
|
|
|
"gopkg.in/urfave/cli.v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
faucetCommand = cli.Command{
|
|
|
|
Action: faucetCommandHandler,
|
|
|
|
Name: "faucet",
|
|
|
|
Usage: "Starts faucet node (light node used by faucet service to request Ether)",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
HTTPPortFlag,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// faucetCommandHandler handles `statusd faucet` command
|
|
|
|
func faucetCommandHandler(ctx *cli.Context) error {
|
|
|
|
config, err := parseFaucetCommandConfig(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("can not parse config: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Starting Status Faucet node..")
|
2017-05-16 12:09:52 +00:00
|
|
|
if err := statusAPI.StartNode(config); err != nil {
|
2017-05-12 12:04:32 +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-12 12:04:32 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// parseFaucetCommandConfig parses incoming CLI options and returns node configuration object
|
|
|
|
func parseFaucetCommandConfig(ctx *cli.Context) (*params.NodeConfig, error) {
|
|
|
|
nodeConfig, err := makeNodeConfig(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// select sub-protocols
|
|
|
|
nodeConfig.LightEthConfig.Enabled = true
|
|
|
|
nodeConfig.WhisperConfig.Enabled = false
|
|
|
|
nodeConfig.SwarmConfig.Enabled = false
|
|
|
|
|
|
|
|
// RPC configuration
|
|
|
|
nodeConfig.APIModules = "eth"
|
|
|
|
nodeConfig.HTTPHost = "0.0.0.0" // allow to connect from anywhere
|
|
|
|
nodeConfig.HTTPPort = ctx.Int(HTTPPortFlag.Name)
|
2017-08-04 16:14:17 +00:00
|
|
|
nodeConfig.RPCEnabled = ctx.Bool(HTTPEnabledFlag.Name)
|
2017-05-12 12:04:32 +00:00
|
|
|
|
|
|
|
// extra options
|
|
|
|
nodeConfig.BootClusterConfig.Enabled = true
|
|
|
|
|
|
|
|
return nodeConfig, nil
|
|
|
|
}
|