a67728628e
* Created test_data folder with block json files for testing + create separate file for block base. * Fixed bug in WriteVarUint + Trim logic + unit tests * Refactored store and add more tests for it. * restore headerList from chain file * Fix tx decode bug + lots of housekeeping. * Implemented Node restore state from chain file. * Created standalone package for storage. Added couple more methods to Batch and Store interfaces. * Block persisting + tests * bumped version -> 0.31.0
91 lines
2.1 KiB
Go
91 lines
2.1 KiB
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/core"
|
|
"github.com/CityOfZion/neo-go/pkg/core/storage"
|
|
"github.com/CityOfZion/neo-go/pkg/network"
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
|
log "github.com/sirupsen/logrus"
|
|
"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.StringFlag{Name: "config-path"},
|
|
cli.BoolFlag{Name: "privnet, p"},
|
|
cli.BoolFlag{Name: "mainnet, m"},
|
|
cli.BoolFlag{Name: "testnet, t"},
|
|
cli.BoolFlag{Name: "debug, d"},
|
|
},
|
|
}
|
|
}
|
|
|
|
func startServer(ctx *cli.Context) error {
|
|
net := network.ModePrivNet
|
|
if ctx.Bool("testnet") {
|
|
net = network.ModeTestNet
|
|
}
|
|
if ctx.Bool("mainnet") {
|
|
net = network.ModeMainNet
|
|
}
|
|
|
|
configPath := "./config"
|
|
configPath = ctx.String("config-path")
|
|
config, err := network.LoadConfig(configPath, net)
|
|
if err != nil {
|
|
return cli.NewExitError(err, 1)
|
|
}
|
|
|
|
serverConfig := network.NewServerConfig(config)
|
|
chain, err := newBlockchain(net, config.ApplicationConfiguration.DataDirectoryPath)
|
|
if err != nil {
|
|
err = fmt.Errorf("could not initialize blockhain: %s", err)
|
|
return cli.NewExitError(err, 1)
|
|
}
|
|
|
|
if ctx.Bool("debug") {
|
|
log.SetLevel(log.DebugLevel)
|
|
}
|
|
|
|
fmt.Println(logo())
|
|
network.NewServer(serverConfig, chain).Start()
|
|
return nil
|
|
}
|
|
|
|
func newBlockchain(net network.NetMode, path string) (*core.Blockchain, error) {
|
|
var startHash util.Uint256
|
|
if net == network.ModePrivNet {
|
|
startHash = core.GenesisHashPrivNet()
|
|
}
|
|
if net == network.ModeTestNet {
|
|
startHash = core.GenesisHashTestNet()
|
|
}
|
|
if net == network.ModeMainNet {
|
|
startHash = core.GenesisHashMainNet()
|
|
}
|
|
|
|
// Hardcoded for now.
|
|
store, err := storage.NewLevelDBStore(path, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return core.NewBlockchain(store, startHash)
|
|
}
|
|
|
|
func logo() string {
|
|
return `
|
|
_ ____________ __________
|
|
/ | / / ____/ __ \ / ____/ __ \
|
|
/ |/ / __/ / / / /_____/ / __/ / / /
|
|
/ /| / /___/ /_/ /_____/ /_/ / /_/ /
|
|
/_/ |_/_____/\____/ \____/\____/
|
|
`
|
|
}
|