neo-go/cli/server/server.go
Anthony De Meulemeester f7d57e4e49
VM draft + cli setup (#20)
* updated readme

* added basic cmd.

* added seperate folders for cmd packages.

* Fix netmodes in test + reverse bigint bytes

* glide get deps
2018-02-09 17:08:50 +01:00

56 lines
1 KiB
Go

package server
import (
"strings"
"github.com/CityOfZion/neo-go/pkg/network"
"github.com/urfave/cli"
)
// NewCommand creates a new Node command
func NewCommand() cli.Command {
return cli.Command{
Name: "node",
Usage: "start a NEO node",
Action: startServer,
Flags: []cli.Flag{
cli.IntFlag{Name: "tcp"},
cli.IntFlag{Name: "rpc"},
cli.StringFlag{Name: "seed"},
cli.BoolFlag{Name: "privnet, p"},
cli.BoolFlag{Name: "mainnet, m"},
cli.BoolFlag{Name: "testnet, t"},
},
}
}
func startServer(ctx *cli.Context) error {
opts := network.StartOpts{
Seeds: parseSeeds(ctx.String("seed")),
TCP: ctx.Int("tcp"),
RPC: ctx.Int("rpc"),
}
net := network.ModePrivNet
if ctx.Bool("testnet") {
net = network.ModeTestNet
}
if ctx.Bool("mainnet") {
net = network.ModeMainNet
}
s := network.NewServer(net)
s.Start(opts)
return nil
}
func parseSeeds(s string) []string {
if len(s) == 0 {
return nil
}
seeds := strings.Split(s, ",")
if len(seeds) == 0 {
return nil
}
return seeds
}