public static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += delegate(object sender, UnhandledExceptionEventArgs args2) { var filePath = ClassUtilsNode.ConvertPath(AppDomain.CurrentDomain.BaseDirectory + "\\error_remotenode.txt"); var exception = (Exception)args2.ExceptionObject; using (var writer = new StreamWriter(filePath, true)) { writer.WriteLine("Message :" + exception.Message + "<br/>" + Environment.NewLine + "StackTrace :" + exception.StackTrace + "" + Environment.NewLine + "Date :" + DateTime.Now); writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine); } Trace.TraceError(exception.StackTrace); Environment.Exit(1); }; Thread.CurrentThread.Name = Path.GetFileName(Environment.GetCommandLineArgs()[0]); ClassRemoteNodeSave.InitializePath(); if (ClassRemoteNodeSave.LoadBlockchainTransaction()) { ClassRemoteNodeSave.LoadBlockchainBlock(); } else { Console.WriteLine("Blockchain database corrupted, clean up.."); ClassRemoteNodeSync.ListOfTransaction.Clear(); ClassRemoteNodeSync.ListOfBlock.Clear(); ClassRemoteNodeSync.ListTransactionPerWallet.Clear(); Thread.Sleep(2000); } Console.WriteLine("Remote node Xiropht - " + Assembly.GetExecutingAssembly().GetName().Version + "R"); if (File.Exists(ClassUtilsNode.ConvertPath(AppDomain.CurrentDomain.BaseDirectory + ConfigFilePath))) { ReadConfigFile(); if (EnableWriteLog) { ClassLog.EnableWriteLog(); } if (EnableFilteringSystem) { ClassApiBan.FilterAutoCheckObject(); } } else { Console.WriteLine( "Welcome, please write your wallet address, in a near future public remote nodes will get reward: "); RemoteNodeWalletAddress = Console.ReadLine(); Console.WriteLine("Do you want load your node as a Public Remote Node? [Y/N]"); var answer = Console.ReadLine(); if (answer == "Y" || answer == "y") { Console.WriteLine("Be carefull, you need to open the default port " + ClassConnectorSetting.RemoteNodePort + " of your remote node in your router."); Console.WriteLine( "Your port need to be opened for everyone and not only for Seed Nodes, for proceed test of your sync."); Console.WriteLine("If everything is alright, your remote node will be listed in the public list."); Console.WriteLine( "If informations of your sync are not right, your remote node will be not listed."); Console.WriteLine( "Checking by Seed Nodes of your Remote Node work everytime for be sure your node is legit and can be rewarded."); Console.WriteLine(""); Console.WriteLine("Are you sure to enable this mode? [Y/N]"); answer = Console.ReadLine(); if (answer == "Y" || answer == "y") { Console.WriteLine("Enabling public remote node system.."); ClassRemoteNodeSync.WantToBePublicNode = true; } } Console.WriteLine("Do you to enable the HTTP API ? [Y/N]"); answer = Console.ReadLine(); if (answer == "Y" || answer == "y") { EnableApiHttp = true; Console.WriteLine("Do you want to select another port for your HTTP API? [Y/N]"); answer = Console.ReadLine(); if (answer == "Y" || answer == "y") { Console.WriteLine("Enter your port selected for your HTTP API: (By default: " + ClassConnectorSetting.RemoteNodeHttpPort + ")"); string portChoosed = Console.ReadLine(); while (!int.TryParse(portChoosed, out ClassApiHttp.PersonalRemoteNodeHttpPort)) { Console.WriteLine("Invalid port, please try another one:"); portChoosed = Console.ReadLine(); } } } SaveConfigFile(); } Certificate = ClassUtils.GenerateCertificate(); Console.WriteLine("Initialize Remote Node Sync Objects.."); RemoteNodeObjectToBePublic = new ClassRemoteNodeObject(SyncEnumerationObject.ObjectToBePublic); RemoteNodeObjectCoinMaxSupply = new ClassRemoteNodeObject(SyncEnumerationObject.ObjectCoinSupply); RemoteNodeObjectTransaction = new ClassRemoteNodeObject(SyncEnumerationObject.ObjectTransaction); RemoteNodeObjectCoinMaxSupply = new ClassRemoteNodeObject(SyncEnumerationObject.ObjectCoinSupply); RemoteNodeObjectCoinCirculating = new ClassRemoteNodeObject(SyncEnumerationObject.ObjectCoinCirculating); RemoteNodeObjectTotalBlockMined = new ClassRemoteNodeObject(SyncEnumerationObject.ObjectBlockMined); RemoteNodeObjectTotalPendingTransaction = new ClassRemoteNodeObject(SyncEnumerationObject.ObjectPendingTransaction); RemoteNodeObjectCurrentDifficulty = new ClassRemoteNodeObject(SyncEnumerationObject.ObjectCurrentDifficulty); RemoteNodeObjectCurrentRate = new ClassRemoteNodeObject(SyncEnumerationObject.ObjectCurrentRate); RemoteNodeObjectTotalFee = new ClassRemoteNodeObject(SyncEnumerationObject.ObjectTotalFee); RemoteNodeObjectTotalTransaction = new ClassRemoteNodeObject(SyncEnumerationObject.ObjectTotalTransaction); RemoteNodeObjectBlock = new ClassRemoteNodeObject(SyncEnumerationObject.ObjectBlock); Task.Factory.StartNew(async delegate() { ClassCheckRemoteNodeSync.AutoCheckBlockchainNetwork(); if (!ClassCheckRemoteNodeSync.BlockchainNetworkStatus) { while (!ClassCheckRemoteNodeSync.BlockchainNetworkStatus) { Console.WriteLine("Blockchain network is not available. Check again after 1 seconds."); await Task.Delay(1000); } } var initializeConnection = false; while (!initializeConnection) { Console.WriteLine("Start Remote Node Sync Objects Connection.."); await Task.Factory.StartNew(() => RemoteNodeObjectCoinMaxSupply.StartConnectionAsync(), CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); await Task.Factory.StartNew(() => RemoteNodeObjectCoinCirculating.StartConnectionAsync(), CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); await Task.Factory.StartNew(() => RemoteNodeObjectTotalPendingTransaction.StartConnectionAsync(), CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); await Task.Factory.StartNew(() => RemoteNodeObjectTotalBlockMined.StartConnectionAsync(), CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); await Task.Factory.StartNew(() => RemoteNodeObjectCurrentDifficulty.StartConnectionAsync(), CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); await Task.Factory.StartNew(() => RemoteNodeObjectCurrentRate.StartConnectionAsync(), CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); await Task.Factory.StartNew(() => RemoteNodeObjectTotalFee.StartConnectionAsync(), CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); await Task.Factory.StartNew(() => RemoteNodeObjectTotalTransaction.StartConnectionAsync(), CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); await Task.Factory.StartNew(() => RemoteNodeObjectTransaction.StartConnectionAsync(), CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); await Task.Factory.StartNew(() => RemoteNodeObjectBlock.StartConnectionAsync(), CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); if (ClassRemoteNodeSync.WantToBePublicNode) { await Task.Factory.StartNew(() => RemoteNodeObjectToBePublic.StartConnectionAsync(), CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); } initializeConnection = true; } if (initializeConnection) { Console.WriteLine("Remote node objects successfully connected."); } else { Console.WriteLine("Remote node objects can't connect to the network, retry in 10 seconds.."); ClassCheckRemoteNodeSync.DisableCheckRemoteNodeSync(); RemoteNodeObjectBlock.StopConnection(); RemoteNodeObjectToBePublic.StopConnection(); RemoteNodeObjectTransaction.StopConnection(); RemoteNodeObjectCoinCirculating.StopConnection(); RemoteNodeObjectCoinMaxSupply.StopConnection(); RemoteNodeObjectCurrentDifficulty.StopConnection(); RemoteNodeObjectCurrentRate.StopConnection(); RemoteNodeObjectTotalBlockMined.StopConnection(); RemoteNodeObjectTotalFee.StopConnection(); RemoteNodeObjectTotalPendingTransaction.StopConnection(); RemoteNodeObjectTotalTransaction.StopConnection(); await Task.Delay(10000); } Console.WriteLine("Enable Check Remote Node Objects connection.."); ClassCheckRemoteNodeSync.EnableCheckRemoteNodeSync(); Console.WriteLine("Enable System of Generating Trusted Key's of Remote Node.."); ClassRemoteNodeKey.StartUpdateTrustedKey(); Console.WriteLine("Enable Auto save system.."); ClassRemoteNodeSave.SaveTransaction(); ClassRemoteNodeSave.SaveBlock(); Console.WriteLine("Enable API.."); ClassApi.StartApiRemoteNode(); if (EnableApiHttp) { Console.WriteLine("Enable API HTTP.."); ClassApiHttp.StartApiHttpServer(); } }, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Current).ConfigureAwait(true); _threadCommandLine = new Thread(delegate() { while (!ClassApi.ApiReceiveConnectionStatus) { Thread.Sleep(100); } Console.WriteLine( "Remote node successfully started, you can run command: help for get the list of commands."); while (!Closed) { try { if (!ClassCommandLine.CommandLine(Console.ReadLine())) { break; } } catch { } } }); _threadCommandLine.Start(); }