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(); }
public static bool CommandLine(string command) { var splitCommand = command.Split(new char[0], StringSplitOptions.None); try { switch (splitCommand[0]) { case ClassCommandLineEnumeration.CommandLineHelp: Console.WriteLine("Command list: "); Console.WriteLine(ClassCommandLineEnumeration.CommandLineStatus + " -> Get Network status of your node"); Console.WriteLine(ClassCommandLineEnumeration.CommandLineTransaction + " -> Get the number of transaction(s) sync."); Console.WriteLine(ClassCommandLineEnumeration.CommandLineBlock + " -> Get the number of block(s) sync."); Console.WriteLine(ClassCommandLineEnumeration.CommandLineLog + " -> Can set level of log to show: (default) log 0 max level 4"); Console.WriteLine(ClassCommandLineEnumeration.CommandLineClearSync + " -> Clear the sync of the remote node."); Console.WriteLine(ClassCommandLineEnumeration.CommandLineFilterList + " -> show every incoming connections ip's and their status."); Console.WriteLine(ClassCommandLineEnumeration.CommandLineBanList + " -> show every incoming connections ip's banned."); Console.WriteLine(ClassCommandLineEnumeration.CommandLineSave + " -> Save sync."); Console.WriteLine(ClassCommandLineEnumeration.CommandLineExit + " -> Save sync and Exit the node."); break; case ClassCommandLineEnumeration.CommandLineStatus: Console.WriteLine("Total Transaction Sync: " + (ClassRemoteNodeSync.ListOfTransaction.Count)); Console.WriteLine("Total Transaction in the Blockchain: " + ClassRemoteNodeSync.TotalTransaction); long totalTransactionSortedPerWallet = ClassRemoteNodeSync.ListTransactionPerWallet.Count; Console.WriteLine("Total Transaction Sorted for Wallet(s): " + totalTransactionSortedPerWallet); Console.WriteLine("Total Block(s) Sync: " + (ClassRemoteNodeSync.ListOfBlock.Count)); Console.WriteLine("Total Block(s) mined in the Blockchain: " + ClassRemoteNodeSync.TotalBlockMined); Console.WriteLine("Total Block(s) left to mining: " + ClassRemoteNodeSync.CurrentBlockLeft); Console.WriteLine("Total pending transaction in the network: " + ClassRemoteNodeSync.TotalPendingTransaction); Console.WriteLine("Total Fee in the network: " + ClassRemoteNodeSync.CurrentTotalFee, Program.GlobalCultureInfo); Console.WriteLine("Current Mining Difficulty: " + ClassRemoteNodeSync.CurrentDifficulty); if (ClassRemoteNodeSync.CurrentHashrate != null) { Console.WriteLine("Current Mining Hashrate: " + ClassUtils.GetTranslateHashrate(ClassRemoteNodeSync.CurrentHashrate.Replace(".", ","), 2).Replace(",", "."), Program.GlobalCultureInfo); } Console.WriteLine("Total Coin Max Supply: " + ClassRemoteNodeSync.CoinMaxSupply, Program.GlobalCultureInfo); Console.WriteLine("Total Coin Circulating: " + ClassRemoteNodeSync.CoinCirculating, Program.GlobalCultureInfo); if (ClassRemoteNodeSync.WantToBePublicNode) { string publicNodes = string.Empty; for (int i = 0; i < ClassRemoteNodeSync.ListOfPublicNodes.Count; i++) { if (i < ClassRemoteNodeSync.ListOfPublicNodes.Count) { publicNodes += ClassRemoteNodeSync.ListOfPublicNodes[i] + " "; } } Console.WriteLine("List of Public Remote Node: " + publicNodes); string status = "NOT LISTED"; if (ClassRemoteNodeSync.ImPublicNode) { status = "LISTED"; } Console.WriteLine("Public Status of the Remote Node: " + status); } Console.WriteLine("Trusted Key: " + ClassRemoteNodeSync.TrustedKey); Console.WriteLine("Hash Transaction Key: " + ClassRemoteNodeSync.HashTransactionList); Console.WriteLine("Hash Block Key: " + ClassRemoteNodeSync.HashBlockList); break; case ClassCommandLineEnumeration.CommandLineTransaction: Console.WriteLine("Total Transaction Sync: " + (ClassRemoteNodeSync.ListOfTransaction.Count)); Console.WriteLine("Total Transaction in the Blockchain: " + ClassRemoteNodeSync.TotalTransaction); break; case ClassCommandLineEnumeration.CommandLineBlock: Console.WriteLine("Total Block(s) Sync: " + (ClassRemoteNodeSync.ListOfBlock.Count)); Console.WriteLine("Total Block(s) mined in the Blockchain: " + ClassRemoteNodeSync.TotalBlockMined); Console.WriteLine("Total Block(s) left to mining: " + ClassRemoteNodeSync.CurrentBlockLeft); break; case ClassCommandLineEnumeration.CommandLineLog: if (!string.IsNullOrEmpty(splitCommand[1])) { if (int.TryParse(splitCommand[1], out var logLevel)) { if (logLevel < 0) { logLevel = 0; } if (logLevel > 7) { logLevel = 7; } Console.WriteLine("Log Level " + Program.LogLevel + " -> " + logLevel); Program.LogLevel = logLevel; } else { Console.WriteLine("Wrong argument: " + splitCommand[1] + " should be a number."); } } else { Console.WriteLine("Empty/Missing argument."); } break; case ClassCommandLineEnumeration.CommandLineClearSync: if (Program.RemoteNodeObjectTransaction.RemoteNodeObjectInSyncTransaction || Program.RemoteNodeObjectBlock.RemoteNodeObjectInSyncBlock) { Console.WriteLine("Cannot clean remote node sync, your remote node is currently on sync."); Console.WriteLine("If you absolutly want to clear your sync, close the remote node, remove the Blockchain folder and restart."); } else { ClassRemoteNodeSync.ListOfTransaction.Clear(); ClassRemoteNodeSync.ListOfTransactionHash.Clear(); ClassRemoteNodeSync.ListTransactionPerWallet.Clear(); ClassRemoteNodeSync.ListOfBlock.Clear(); ClassRemoteNodeSync.ListOfBlockHash.Clear(); ClassRemoteNodeSave.ClearBlockSyncSave(); ClassRemoteNodeSave.ClearTransactionSyncSave(); ClassRemoteNodeKey.DataBlockRead = string.Empty; ClassRemoteNodeKey.DataTransactionRead = string.Empty; ClassRemoteNodeSave.TotalBlockSaved = 0; ClassRemoteNodeSave.TotalTransactionSaved = 0; ClassRemoteNodeSave.DataTransactionSaved = string.Empty; ClassRemoteNodeSave.DataBlockSaved = string.Empty; Console.WriteLine("Clear finish, restart sync.."); ClassRemoteNodeKey.StartUpdateHashTransactionList(); ClassRemoteNodeKey.StartUpdateHashBlockList(); ClassRemoteNodeKey.StartUpdateTrustedKey(); } break; case ClassCommandLineEnumeration.CommandLineFilterList: if (ClassApiBan.ListFilterObjects.Count > 0) { foreach (var objectBan in ClassApiBan.ListFilterObjects) { if (objectBan.Value.Banned) { long banDelay = objectBan.Value.LastBanDate - DateTimeOffset.Now.ToUnixTimeSeconds(); Console.WriteLine("IP: " + objectBan.Value.Ip + " Total Invalid Packet:" + objectBan.Value.TotalInvalidPacket + " banned pending: " + banDelay + " second(s)."); } else { Console.WriteLine("IP: " + objectBan.Value.Ip + " Total Invalid Packet:" + objectBan.Value.TotalInvalidPacket + " not banned."); } } } else { Console.WriteLine("Their is any incoming ip on the list."); } break; case ClassCommandLineEnumeration.CommandLineBanList: if (ClassApiBan.ListFilterObjects.Count > 0) { foreach (var objectBan in ClassApiBan.ListFilterObjects) { if (objectBan.Value.Banned) { long banDelay = objectBan.Value.LastBanDate - DateTimeOffset.Now.ToUnixTimeSeconds(); Console.WriteLine("IP: " + objectBan.Value.Ip + " Total Invalid Packet:" + objectBan.Value.TotalInvalidPacket + " banned pending: " + banDelay + " second(s)."); } } } else { Console.WriteLine("Their is any incoming ip on the list."); } break; case ClassCommandLineEnumeration.CommandLineSave: Console.WriteLine("Stop auto save system. Start manual save sync.."); while (ClassRemoteNodeSave.InSaveTransactionDatabase) { Thread.Sleep(1000); } ClassRemoteNodeSave.TotalTransactionSaved = 0; ClassRemoteNodeSave.DataTransactionSaved = string.Empty; ClassRemoteNodeSave.SaveTransaction(false); while (ClassRemoteNodeSave.InSaveBlockDatabase) { Thread.Sleep(1000); } ClassRemoteNodeSave.TotalBlockSaved = 0; ClassRemoteNodeSave.DataBlockSaved = string.Empty; ClassRemoteNodeSave.SaveBlock(false); Console.WriteLine("Sync saved."); Console.WriteLine("Restart auto save system."); ClassRemoteNodeSave.SaveTransaction(); ClassRemoteNodeSave.SaveBlock(); break; case ClassCommandLineEnumeration.CommandLineExit: Program.Closed = true; Console.WriteLine("Disable auto reconnect remote node.."); ClassCheckRemoteNodeSync.DisableCheckRemoteNodeSync(); Thread.Sleep(1000); Console.WriteLine("Stop each connection of the remote node."); Program.RemoteNodeObjectBlock.StopConnection(); Program.RemoteNodeObjectTransaction.StopConnection(); Program.RemoteNodeObjectTotalTransaction.StopConnection(); Program.RemoteNodeObjectCoinCirculating.StopConnection(); Program.RemoteNodeObjectCoinMaxSupply.StopConnection(); Program.RemoteNodeObjectCurrentDifficulty.StopConnection(); Program.RemoteNodeObjectCurrentRate.StopConnection(); Program.RemoteNodeObjectTotalBlockMined.StopConnection(); Program.RemoteNodeObjectTotalFee.StopConnection(); Program.RemoteNodeObjectTotalPendingTransaction.StopConnection(); ClassLog.StopWriteLog(); Thread.Sleep(1000); Console.WriteLine("Stop api.."); ClassApi.StopApi(); Console.WriteLine("Starting save sync.."); while (ClassRemoteNodeSave.InSaveTransactionDatabase) { Thread.Sleep(1000); } ClassRemoteNodeSave.TotalTransactionSaved = 0; ClassRemoteNodeSave.DataTransactionSaved = string.Empty; ClassRemoteNodeSave.SaveTransaction(false); while (ClassRemoteNodeSave.InSaveBlockDatabase) { Thread.Sleep(1000); } ClassRemoteNodeSave.TotalBlockSaved = 0; ClassRemoteNodeSave.DataBlockSaved = string.Empty; ClassRemoteNodeSave.SaveBlock(false); Console.WriteLine("Sync saved."); Process.GetCurrentProcess().Kill(); return(false); } } catch (Exception error) { Console.WriteLine("Command line error: " + error.Message); } return(true); }