forked from TrueCloudLab/neoneo-go
Persistance (#53)
* added publish TX for backwards compat. * lowered the prototick for faster block syncing * print useragent on startup * added createMultiRedeemScript for genesis block generation. * building genesis block from scratch. * implemented merkle tree. * starting blockhain with generated genesis hash * Fixed bug in unspent coin state. * fixed broken tests after genesis block. * removed log line. * bumped version -> 0.34.0
This commit is contained in:
parent
ad9333c74c
commit
94672cb9cc
35 changed files with 955 additions and 187 deletions
|
@ -5,11 +5,11 @@ import (
|
|||
"os"
|
||||
"os/signal"
|
||||
|
||||
"github.com/CityOfZion/neo-go/config"
|
||||
"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/rpc"
|
||||
"github.com/CityOfZion/neo-go/pkg/util"
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
|
@ -32,17 +32,17 @@ func NewCommand() cli.Command {
|
|||
}
|
||||
|
||||
func startServer(ctx *cli.Context) error {
|
||||
net := network.ModePrivNet
|
||||
net := config.ModePrivNet
|
||||
if ctx.Bool("testnet") {
|
||||
net = network.ModeTestNet
|
||||
net = config.ModeTestNet
|
||||
}
|
||||
if ctx.Bool("mainnet") {
|
||||
net = network.ModeMainNet
|
||||
net = config.ModeMainNet
|
||||
}
|
||||
|
||||
configPath := "./config"
|
||||
configPath = ctx.String("config-path")
|
||||
config, err := network.LoadConfig(configPath, net)
|
||||
cfg, err := config.Load(configPath, net)
|
||||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
|
@ -50,10 +50,10 @@ func startServer(ctx *cli.Context) error {
|
|||
interruptChan := make(chan os.Signal, 1)
|
||||
signal.Notify(interruptChan, os.Interrupt)
|
||||
|
||||
serverConfig := network.NewServerConfig(config)
|
||||
chain, err := newBlockchain(net, config.ApplicationConfiguration.DataDirectoryPath)
|
||||
serverConfig := network.NewServerConfig(cfg)
|
||||
chain, err := newBlockchain(cfg)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("could not initialize blockhain: %s", err)
|
||||
err = fmt.Errorf("could not initialize blockchain: %s", err)
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
|
||||
|
@ -61,15 +61,18 @@ func startServer(ctx *cli.Context) error {
|
|||
log.SetLevel(log.DebugLevel)
|
||||
}
|
||||
|
||||
fmt.Println(logo())
|
||||
server := network.NewServer(serverConfig, chain)
|
||||
rpcServer := rpc.NewServer(chain, config.ApplicationConfiguration.RPCPort, server)
|
||||
rpcServer := rpc.NewServer(chain, cfg.ApplicationConfiguration.RPCPort, server)
|
||||
errChan := make(chan error)
|
||||
|
||||
go server.Start(errChan)
|
||||
go rpcServer.Start(errChan)
|
||||
var shutdownErr error
|
||||
|
||||
fmt.Println(logo())
|
||||
fmt.Println(server.UserAgent)
|
||||
fmt.Println()
|
||||
|
||||
var shutdownErr error
|
||||
Main:
|
||||
for {
|
||||
select {
|
||||
|
@ -93,25 +96,17 @@ Main:
|
|||
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()
|
||||
}
|
||||
|
||||
func newBlockchain(cfg config.Config) (*core.Blockchain, error) {
|
||||
// Hardcoded for now.
|
||||
store, err := storage.NewLevelDBStore(path, nil)
|
||||
store, err := storage.NewLevelDBStore(
|
||||
cfg.ApplicationConfiguration.DataDirectoryPath,
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return core.NewBlockchain(store, startHash)
|
||||
return core.NewBlockchain(store, cfg.ProtocolConfiguration)
|
||||
}
|
||||
|
||||
func logo() string {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue