Beispiel #1
0
 public static void SyncBlockChain()
 {
     Task.Run(() =>
     {
         const string acc_path     = "chain.acc";
         const string acc_zip_path = acc_path + ".zip";
         if (File.Exists(acc_path))
         {
             using (FileStream fs = new FileStream(acc_path, FileMode.Open, FileAccess.Read, FileShare.None))
             {
                 ImportBlocks(fs);
             }
             File.Delete(acc_path);
         }
         else if (File.Exists(acc_zip_path))
         {
             using (FileStream fs = new FileStream(acc_zip_path, FileMode.Open, FileAccess.Read, FileShare.None))
                 using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Read))
                     using (Stream zs = zip.GetEntry(acc_path).Open())
                     {
                         ImportBlocks(zs);
                     }
             File.Delete(acc_zip_path);
         }
         Blockchain.PersistCompleted += Blockchain_PersistCompleted;
         LocalNode.Start(Properties.Settings.Default.P2P.Port, Properties.Settings.Default.P2P.WsPort);
     });
 }
Beispiel #2
0
        protected internal override void OnStart(string[] args)
        {
            Blockchain.RegisterBlockchain(new LevelDBBlockchain(Settings.Default.DataDirectoryPath));
            if (File.Exists(PeerStatePath))
            {
                using (FileStream fs = new FileStream(PeerStatePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    LocalNode.LoadState(fs);
                }
            }
            LocalNode = new LocalNode();
            Task.Run(() =>
            {
                const string acc_path     = "chain.acc";
                const string acc_zip_path = acc_path + ".zip";
                if (File.Exists(acc_path))
                {
                    using (FileStream fs = new FileStream(acc_path, FileMode.Open, FileAccess.Read, FileShare.None))
                    {
                        ImportBlocks(fs);
                    }
                    File.Delete(acc_path);
                }
                else if (File.Exists(acc_zip_path))
                {
                    using (FileStream fs = new FileStream(acc_zip_path, FileMode.Open, FileAccess.Read, FileShare.None))
                        using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Read))
                            using (Stream zs = zip.GetEntry(acc_path).Open())
                            {
                                ImportBlocks(zs);
                            }
                    File.Delete(acc_zip_path);
                }
                LocalNode.Start(Settings.Default.NodePort, Settings.Default.WsPort);
                bool recordNotifications = false;
                for (int i = 0; i < args.Length; i++)
                {
                    switch (args[i])
                    {
                    case "/rpc":
                    case "--rpc":
                    case "-r":
                        if (rpc == null)
                        {
                            rpc = new RpcServerWithWallet(LocalNode);
                            rpc.Start(Settings.Default.UriPrefix.OfType <string>().ToArray(), Settings.Default.SslCert, Settings.Default.SslCertPassword);
                        }
                        break;

                    case "--record-notifications":
                        recordNotifications = true;
                        break;
                    }
                }
                if (recordNotifications)
                {
                    Blockchain.Notify += Blockchain_Notify;
                }
            });
        }
        public void StartBlockchain()
        {
            BlockChain = Neo.Core.Blockchain.RegisterBlockchain(new LevelDBBlockchain(NeoSettings.Default.DataDirectoryPath));

            localNode = new LocalNode();
            Task.Run(() =>
            {
                const string acc_path     = "chain.acc";
                const string acc_zip_path = acc_path + ".zip";
                if (File.Exists(acc_path))
                {
                    using (FileStream fs = new FileStream(acc_path, FileMode.Open, FileAccess.Read, FileShare.None))
                    {
                        ImportBlocks(fs);
                    }
                    File.Delete(acc_path);
                }
                else if (File.Exists(acc_zip_path))
                {
                    using (FileStream fs = new FileStream(acc_zip_path, FileMode.Open, FileAccess.Read, FileShare.None))
                        using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Read))
                            using (Stream zs = zip.GetEntry(acc_path).Open())
                            {
                                ImportBlocks(zs);
                            }
                    File.Delete(acc_zip_path);
                }

                localNode.Start(NeoSettings.Default.NodePort, NeoSettings.Default.WsPort);
            });
        }
 protected internal override void OnStart(string[] args)
 {
     Blockchain.RegisterBlockchain(new LevelDBBlockchain(Settings.Default.DataDirectoryPath));
     LocalNode = new LocalNode();
     Task.Run(() =>
     {
         const string acc_path     = "chain.acc";
         const string acc_zip_path = acc_path + ".zip";
         if (File.Exists(acc_path))
         {
             using (FileStream fs = new FileStream(acc_path, FileMode.Open, FileAccess.Read, FileShare.None))
             {
                 ImportBlocks(fs);
             }
             File.Delete(acc_path);
         }
         else if (File.Exists(acc_zip_path))
         {
             using (FileStream fs = new FileStream(acc_zip_path, FileMode.Open, FileAccess.Read, FileShare.None))
                 using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Read))
                     using (Stream zs = zip.GetEntry(acc_path).Open())
                     {
                         ImportBlocks(zs);
                     }
             File.Delete(acc_zip_path);
         }
         LocalNode.Start(Settings.Default.NodePort, Settings.Default.WsPort);
         if (args.Length >= 1 && args[0] == "/rpc")
         {
             rpc = new RpcServerWithWallet(LocalNode);
             rpc.Start(Settings.Default.UriPrefix.OfType <string>().ToArray(), Settings.Default.SslCert, Settings.Default.SslCertPassword);
         }
     });
 }
Beispiel #5
0
 protected internal override void OnStart()
 {
     Blockchain.RegisterBlockchain(new LevelDBBlockchain(Settings.Default.DataDirectoryPath));
     localnode = new LocalNode();
     localnode.Start();
     StartMine(source.Token);
 }
Beispiel #6
0
        static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            WindowsFormsSynchronizationContext.AutoInstall = false;
            MainForm = new MainForm();
            const string path = "nodes.dat";

            if (File.Exists(path))
            {
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    LocalNode.LoadState(fs);
                }
            }
            using (LevelDBBlockchain blockchain = new LevelDBBlockchain(Settings.Default.ChainPath))
                using (LocalNode = new LocalNode())
                {
                    Blockchain.RegisterBlockchain(blockchain);
                    LocalNode.Start();
                    Application.Run(MainForm);
                }
            using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write))
            {
                LocalNode.SaveState(fs);
            }
        }
Beispiel #7
0
 protected internal override void OnStart()
 {
     Blockchain.RegisterBlockchain(new LevelDBBlockchain(Settings.Default.DataDirectoryPath));
     Blockchain.Default.PersistCompleted += Blockchain_PersistCompleted;
     LocalNode.NewInventory += LocalNode_NewInventory;
     localnode = new LocalNode();
     localnode.Start();
 }
Beispiel #8
0
 protected internal override void OnStart(string[] args)
 {
     Blockchain.RegisterBlockchain(new LevelDBBlockchain(Settings.Default.DataDirectoryPath));
     LocalNode = new LocalNode();
     LocalNode.Start(Settings.Default.NodePort);
     if (args.Length >= 1 && args[0] == "/rpc")
     {
         rpc = new RpcServer(LocalNode);
         rpc.Start();
     }
 }
Beispiel #9
0
        /// <summary>
        ///     Starts a node and connects to the network. Once connected, starts synchornizing the blocks
        /// </summary>
        public void Start()
        {
            _configuration.CreateJsonFiles();

            _logger.LogMessage("Chain location: " + _configuration.ChainPath);
            //TODO: take in the folder, take in the ports as parameters
            var levelDbBlockchain = new LevelDBBlockchain(_configuration.ChainPath);

            _blockchain = Blockchain.RegisterBlockchain(levelDbBlockchain);
            LocalNode   = new LocalNode {
                UpnpEnabled = true
            };
            _logger.LogMessage("Starting Node");

            //start a node in the background;
            Task.Run(() => { LocalNode.Start(_configuration.NodePort, _configuration.WsPort); });

            var stopWatch = new Stopwatch();

            stopWatch.Start();
            var nodeCount = 0;

            while (LocalNode.RemoteNodeCount <= 1)
            {
                if (stopWatch.Elapsed.TotalSeconds > 30)
                {
                    throw new ApplicationException("could not connect to any peers within 30 seconds. Check network and settings and try again.");
                }
                _logger.LogMessage("Looking for peers");
                Thread.Sleep(1000); //wait to connect to peers.
            }

            _logger.LogMessage("connected to peers");
            //sync the chain. If headerHeight == 0 then we have not received any data about the height yet
            var count = 0;

            while (Blockchain.Default.HeaderHeight == 0 || Blockchain.Default.Height < Blockchain.Default.HeaderHeight)
            {
                if (count % 10 == 0) //don't spam out too many messages
                {
                    _logger.LogMessage($"Synchronizing blockchain. Processed {Blockchain.Default.Height.ToString("N0", CultureInfo.InvariantCulture)} of {Blockchain.Default.HeaderHeight.ToString("N0", CultureInfo.InvariantCulture)} blocks");
                }
                Thread.Sleep(1000);
                count++;
            }

            _logger.LogMessage("Blockchain Synchronized");
        }
Beispiel #10
0
        private void runBlockChain()
        {
            Task.Run(() =>
            {
                const string path_acc = "chain.acc";
                if (File.Exists(path_acc))
                {
                    using (FileStream fs = new FileStream(path_acc, FileMode.Open, FileAccess.Read, FileShare.None))
                    {
                        ImportBlocks(fs);
                    }
                }

                var paths = Directory.EnumerateFiles(".", "chain.*.acc", SearchOption.TopDirectoryOnly).Concat(Directory.EnumerateFiles(".", "chain.*.acc.zip", SearchOption.TopDirectoryOnly)).Select(p => new
                {
                    FileName     = Path.GetFileName(p),
                    Start        = uint.Parse(Regex.Match(p, @"\d+").Value),
                    IsCompressed = p.EndsWith(".zip")
                }).OrderBy(p => p.Start);

                foreach (var path in paths)
                {
                    if (path.Start > Blockchain.Default.Height + 1)
                    {
                        break;
                    }
                    if (path.IsCompressed)
                    {
                        using (FileStream fs = new FileStream(path.FileName, FileMode.Open, FileAccess.Read, FileShare.None))
                            using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Read))
                                using (Stream zs = zip.GetEntry(Path.GetFileNameWithoutExtension(path.FileName)).Open())
                                {
                                    ImportBlocks(zs, true);
                                }
                    }
                    else
                    {
                        using (FileStream fs = new FileStream(path.FileName, FileMode.Open, FileAccess.Read, FileShare.None))
                        {
                            ImportBlocks(fs, true);
                        }
                    }
                }
                Blockchain.PersistCompleted += Blockchain_PersistCompleted;
                LocalNode.Start(Properties.Settings.Default.P2P.Port, Properties.Settings.Default.P2P.WsPort);
            });
        }
Beispiel #11
0
 private void MainWindow_Loaded(object sender, RoutedEventArgs e)
 {
     LocalNode.UpnpEnabled = true;
     LocalNode.Start(Settings.Default.NodePort);
     listView.ItemsSource = RecordInfoList;
 }
Beispiel #12
0
        protected internal override void OnStart(string[] args)
        {
            bool useRPC = false, nopeers = false, useLog = false;

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "/rpc":
                case "--rpc":
                case "-r":
                    useRPC = true;
                    break;

                case "--nopeers":
                    nopeers = true;
                    break;

                case "-l":
                case "--log":
                    useLog = true;
                    break;
                }
            }
            Blockchain.RegisterBlockchain(new LevelDBBlockchain(Path.GetFullPath(Settings.Default.Paths.Chain)));
            if (!nopeers && File.Exists(PeerStatePath))
            {
                using (FileStream fs = new FileStream(PeerStatePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    LocalNode.LoadState(fs);
                }
            }
            LocalNode = new LocalNode();
            if (useLog)
            {
                LevelDBBlockchain.ApplicationExecuted += LevelDBBlockchain_ApplicationExecuted;
            }
            Task.Run(() =>
            {
                const string acc_path     = "chain.acc";
                const string acc_zip_path = acc_path + ".zip";
                if (File.Exists(acc_path))
                {
                    using (FileStream fs = new FileStream(acc_path, FileMode.Open, FileAccess.Read, FileShare.None))
                    {
                        ImportBlocks(fs);
                    }
                    File.Delete(acc_path);
                }
                else if (File.Exists(acc_zip_path))
                {
                    using (FileStream fs = new FileStream(acc_zip_path, FileMode.Open, FileAccess.Read, FileShare.None))
                        using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Read))
                            using (Stream zs = zip.GetEntry(acc_path).Open())
                            {
                                ImportBlocks(zs);
                            }
                    File.Delete(acc_zip_path);
                }
                LocalNode.Start(Settings.Default.P2P.Port, Settings.Default.P2P.WsPort);
                if (useRPC)
                {
                    rpc = new RpcServerWithWallet(LocalNode);
                    rpc.Start(Settings.Default.RPC.Port, Settings.Default.RPC.SslCert, Settings.Default.RPC.SslCertPassword);
                }
            });
        }
Beispiel #13
0
        protected internal override void OnStart(string[] args)
        {
            bool useRPC = false, nopeers = false, useLog = false;

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "/rpc":
                case "--rpc":
                case "-r":
                    useRPC = true;
                    break;

                case "--nopeers":
                    nopeers = true;
                    break;

                case "-l":
                case "--log":
                    useLog = true;
                    break;
                }
            }
            Blockchain.RegisterBlockchain(new LevelDBBlockchain(
                                              Path.GetFullPath(Settings.Default.Paths.Chain),
                                              Path.GetFullPath(Settings.Default.Paths.Fulllogs),
                                              Settings.Default.Paths.FullLogOnlyLocal,
                                              Settings.Default.Paths.fulllog_splitcount,
                                              Settings.Default.Paths.fulllog_splitindex
                                              ));
            if (!nopeers && File.Exists(PeerStatePath))
            {
                using (FileStream fs = new FileStream(PeerStatePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    LocalNode.LoadState(fs);
                }
            }
            LocalNode = new LocalNode();
            //if (useLog)
            LevelDBBlockchain.ApplicationExecuted += LevelDBBlockchain_ApplicationExecuted;
            Task.Run(() =>
            {
                const string path_acc = "chain.acc";
                if (File.Exists(path_acc))
                {
                    using (FileStream fs = new FileStream(path_acc, FileMode.Open, FileAccess.Read, FileShare.None))
                    {
                        ImportBlocks(fs);
                    }
                }
                const string path_acc_zip = path_acc + ".zip";
                if (File.Exists(path_acc_zip))
                {
                    using (FileStream fs = new FileStream(path_acc_zip, FileMode.Open, FileAccess.Read, FileShare.None))
                        using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Read))
                            using (Stream zs = zip.GetEntry(path_acc).Open())
                            {
                                ImportBlocks(zs);
                            }
                }
                var paths = Directory.EnumerateFiles(".", "chain.*.acc", SearchOption.TopDirectoryOnly).Concat(Directory.EnumerateFiles(".", "chain.*.acc.zip", SearchOption.TopDirectoryOnly)).Select(p => new
                {
                    FileName     = Path.GetFileName(p),
                    Start        = uint.Parse(Regex.Match(p, @"\d+").Value),
                    IsCompressed = p.EndsWith(".zip")
                }).OrderBy(p => p.Start);
                foreach (var path in paths)
                {
                    if (path.Start > Blockchain.Default.Height + 1)
                    {
                        break;
                    }
                    if (path.IsCompressed)
                    {
                        using (FileStream fs = new FileStream(path.FileName, FileMode.Open, FileAccess.Read, FileShare.None))
                            using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Read))
                                using (Stream zs = zip.GetEntry(Path.GetFileNameWithoutExtension(path.FileName)).Open())
                                {
                                    ImportBlocks(zs, true);
                                }
                    }
                    else
                    {
                        using (FileStream fs = new FileStream(path.FileName, FileMode.Open, FileAccess.Read, FileShare.None))
                        {
                            ImportBlocks(fs, true);
                        }
                    }
                }
                LocalNode.Start(Settings.Default.P2P.Port, Settings.Default.P2P.WsPort);
                if (Settings.Default.UnlockWallet.IsActive)
                {
                    try
                    {
                        Program.Wallet = OpenWallet(Settings.Default.UnlockWallet.Path, Settings.Default.UnlockWallet.Password);
                    }
                    catch (CryptographicException)
                    {
                        Console.WriteLine($"failed to open file \"{Settings.Default.UnlockWallet.Path}\"");
                    }
                    if (Settings.Default.UnlockWallet.StartConsensus && Program.Wallet != null)
                    {
                        OnStartConsensusCommand(null);
                    }
                }
                //if (useRPC)
                {
                    rpc = new RpcServerWithWallet(LocalNode);
                    rpc.Start(Settings.Default.RPC.Port, Settings.Default.RPC.SslCert, Settings.Default.RPC.SslCertPassword,
                              Settings.Default.Paths.ApplicationLogs,
                              Settings.Default.Paths.Fulllogs
                              );
                }
            });
        }
Beispiel #14
0
        public void Init()
        {
            Blockchain.RegisterBlockchain(new LevelDBBlockchain(NeoSettings.Default.DataDirectoryPath));

            Task.Run(() => localNode.Start(NeoSettings.Default.NodePort, NeoSettings.Default.WsPort));
        }
Beispiel #15
0
 protected void OnStart(bool useRPC = false, bool nopeers = false, bool useLog = false)
 {
     Blockchain.RegisterBlockchain(new LevelDBBlockchain(Path.GetFullPath(Settings.Default.Paths.Chain)));
     if (!nopeers && File.Exists(PeerStatePath))
     {
         using (FileStream fs = new FileStream(PeerStatePath, FileMode.Open, FileAccess.Read, FileShare.Read))
         {
             LocalNode.LoadState(fs);
         }
     }
     LocalNode = new LocalNode();
     if (useLog)
     {
         LevelDBBlockchain.ApplicationExecuted += LevelDBBlockchain_ApplicationExecuted;
     }
     Task.Run(() =>
     {
         const string path_acc = "chain.acc";
         if (File.Exists(path_acc))
         {
             using (FileStream fs = new FileStream(path_acc, FileMode.Open, FileAccess.Read, FileShare.None))
             {
                 ImportBlocks(fs);
             }
         }
         const string path_acc_zip = path_acc + ".zip";
         if (File.Exists(path_acc_zip))
         {
             using (FileStream fs = new FileStream(path_acc_zip, FileMode.Open, FileAccess.Read, FileShare.None))
                 using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Read))
                     using (Stream zs = zip.GetEntry(path_acc).Open())
                     {
                         ImportBlocks(zs);
                     }
         }
         var paths = Directory.EnumerateFiles(".", "chain.*.acc", SearchOption.TopDirectoryOnly).Concat(Directory.EnumerateFiles(".", "chain.*.acc.zip", SearchOption.TopDirectoryOnly)).Select(p => new
         {
             FileName     = Path.GetFileName(p),
             Start        = uint.Parse(Regex.Match(p, @"\d+").Value),
             IsCompressed = p.EndsWith(".zip")
         }).OrderBy(p => p.Start);
         foreach (var path in paths)
         {
             if (path.Start > Blockchain.Default.Height + 1)
             {
                 break;
             }
             if (path.IsCompressed)
             {
                 using (FileStream fs = new FileStream(path.FileName, FileMode.Open, FileAccess.Read, FileShare.None))
                     using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Read))
                         using (Stream zs = zip.GetEntry(Path.GetFileNameWithoutExtension(path.FileName)).Open())
                         {
                             ImportBlocks(zs, true);
                         }
             }
             else
             {
                 using (FileStream fs = new FileStream(path.FileName, FileMode.Open, FileAccess.Read, FileShare.None))
                 {
                     ImportBlocks(fs, true);
                 }
             }
         }
         LocalNode.Start(Settings.Default.P2P.Port, Settings.Default.P2P.WsPort);
         if (useRPC)
         {
             rpc = new RpcServerWithWallet(LocalNode);
             rpc.Start(Settings.Default.RPC.Port, Settings.Default.RPC.SslCert, Settings.Default.RPC.SslCertPassword);
         }
     });
 }
Beispiel #16
0
        protected internal override void OnStart(string[] args)
        {
            Blockchain.RegisterBlockchain(new LevelDBBlockchain(Settings.Default.Paths.Chain,
                                                                Settings.Default.Paths.Fulllogs,
                                                                Settings.Default.Paths.fulllog_splitcount,
                                                                Settings.Default.Paths.fulllog_splitindex));
            if (!args.Contains("--nopeers") && File.Exists(PeerStatePath))
            {
                using (FileStream fs = new FileStream(PeerStatePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    LocalNode.LoadState(fs);
                }
            }
            LocalNode = new LocalNode();
            Task.Run(() =>
            {
                const string acc_path     = "chain.acc";
                const string acc_zip_path = acc_path + ".zip";
                if (File.Exists(acc_path))
                {
                    using (FileStream fs = new FileStream(acc_path, FileMode.Open, FileAccess.Read, FileShare.None))
                    {
                        ImportBlocks(fs);
                    }
                    File.Delete(acc_path);
                }
                else if (File.Exists(acc_zip_path))
                {
                    using (FileStream fs = new FileStream(acc_zip_path, FileMode.Open, FileAccess.Read, FileShare.None))
                        using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Read))
                            using (Stream zs = zip.GetEntry(acc_path).Open())
                            {
                                ImportBlocks(zs);
                            }
                    File.Delete(acc_zip_path);
                }
                LocalNode.Start(Settings.Default.P2P.Port, Settings.Default.P2P.WsPort);

                //open rpc & notifications for default

                //bool recordNotifications = false;
                //for (int i = 0; i < args.Length; i++)
                //{
                //    switch (args[i])
                //    {
                //        case "/rpc":
                //        case "--rpc":
                //        case "-r":
                //if (rpc == null)
                //{
                rpc = new RpcServerWithWallet(LocalNode);
                rpc.Start(Settings.Default.RPC.Port, Settings.Default.RPC.SslCert, Settings.Default.RPC.SslCertPassword,
                          Settings.Default.Paths.ApplicationLogs,
                          Settings.Default.Paths.Fulllogs
                          );
                //}
                //            break;
                //        case "--record-notifications":
                //            recordNotifications = true;
                //            break;
                //    }
                //}
                //if (recordNotifications)
                LevelDBBlockchain.ApplicationExecuted += LevelDBBlockchain_ApplicationExecuted;
            });
        }