/// <summary> /// Initialization of the mining pool. /// </summary> /// <returns></returns> private static bool InitializeMiningPool() { ClassLog.ConsoleWriteLog("Initialize Log system..", ClassLogEnumeration.IndexPoolGeneralLog, ClassLogConsoleEnumeration.IndexPoolConsoleYellowLog, true); if (ClassLog.LogInitialization()) { ClassLog.ConsoleWriteLog("Initialize pool settings..", ClassLogEnumeration.IndexPoolGeneralLog, ClassLogConsoleEnumeration.IndexPoolConsoleYellowLog, true); if (MiningPoolSettingInitialization.InitializationPoolSettingFile()) { ClassLog.ConsoleWriteLog("Pool settings initialized.", ClassLogEnumeration.IndexPoolGeneralLog, ClassLogConsoleEnumeration.IndexPoolConsoleGreenLog, true); ClassLog.ConsoleWriteLog("Intialize pool databases..", ClassLogEnumeration.IndexPoolGeneralLog, ClassLogConsoleEnumeration.IndexPoolConsoleYellowLog, true); if (ClassMiningPoolDatabase.InitializationMiningPoolDatabases()) { ClassMiningPoolDatabase.AutoSaveMiningPoolDatabases(); ClassLog.ConsoleWriteLog("Pool databases initialized.", ClassLogEnumeration.IndexPoolGeneralLog, ClassLogConsoleEnumeration.IndexPoolConsoleGreenLog, true); ClassLog.ConsoleWriteLog("Log System initialized.", ClassLogEnumeration.IndexPoolGeneralLog, ClassLogConsoleEnumeration.IndexPoolConsoleGreenLog, true); ThreadNetworkBlockchain = new Thread(async delegate() { ClassLog.ConsoleWriteLog("Connect Pool to the network for retrieve current blocktemplate..", ClassLogEnumeration.IndexPoolGeneralLog, ClassLogConsoleEnumeration.IndexPoolConsoleYellowLog, true); bool notConnected = true; while (notConnected) { Certificate = ClassUtils.GenerateCertificate(); while (!await ClassNetworkBlockchain.ConnectToBlockchainAsync()) { Thread.Sleep(5000); ClassLog.ConsoleWriteLog("Can't connect Pool to the network, retry in 5 seconds.. (Press CTRL+C to cancel and close the pool.)", ClassLogEnumeration.IndexPoolGeneralLog, ClassLogConsoleEnumeration.IndexPoolConsoleRedLog, true); } Certificate = ClassUtils.GenerateCertificate(); ClassLog.ConsoleWriteLog("Certificate generate, send to the network..", ClassLogEnumeration.IndexPoolGeneralLog, ClassLogConsoleEnumeration.IndexPoolConsoleYellowLog, true); if (!await ClassNetworkBlockchain.SendPacketToNetworkBlockchain(Certificate, false)) { ClassLog.ConsoleWriteLog("Can't send certificate, reconnect now..", ClassLogEnumeration.IndexPoolGeneralLog, ClassLogConsoleEnumeration.IndexPoolConsoleRedLog, true); } else { ClassLog.ConsoleWriteLog("Certificate sent, start to login..", ClassLogEnumeration.IndexPoolGeneralLog, ClassLogConsoleEnumeration.IndexPoolConsoleYellowLog, true); ClassNetworkBlockchain.ListenBlockchain(); Thread.Sleep(1000); if (!await ClassNetworkBlockchain.SendPacketToNetworkBlockchain(ClassConnectorSettingEnumeration.MinerLoginType + "|" + MiningPoolSetting.MiningPoolWalletAddress, true)) { ClassLog.ConsoleWriteLog("Can't login to the network, reconnect now.", ClassLogEnumeration.IndexPoolGeneralLog, ClassLogConsoleEnumeration.IndexPoolConsoleRedLog, true); } else { ClassLog.ConsoleWriteLog("Login successfully sent, waiting confirmation..", ClassLogEnumeration.IndexPoolGeneralLog, ClassLogConsoleEnumeration.IndexPoolConsoleYellowLog, true); notConnected = false; } } if (notConnected) { ClassLog.ConsoleWriteLog("Can't long Pool to the network, retry in 5 seconds.. (Press CTRL+C to cancel and close the pool.)", ClassLogEnumeration.IndexPoolGeneralLog, ClassLogConsoleEnumeration.IndexPoolConsoleYellowLog, true); Thread.Sleep(5000); } else { break; } } }) { IsBackground = true }; ThreadNetworkBlockchain.Start(); if (MiningPoolSetting.MiningPoolEnableFiltering) { ClassLog.ConsoleWriteLog("Enable Filtering Miner System..", ClassLogEnumeration.IndexPoolGeneralLog, ClassLogConsoleEnumeration.IndexPoolConsoleYellowLog, true); ClassFilteringMiner.EnableFilteringMiner(); } if (MiningPoolSetting.MiningPoolEnableCheckMinerStats) { ClassLog.ConsoleWriteLog("Enable Check Miner Stats System..", ClassLogEnumeration.IndexPoolGeneralLog, ClassLogConsoleEnumeration.IndexPoolConsoleYellowLog, true); ClassMinerStats.EnableCheckMinerStats(); } if (MiningPoolSetting.MiningPoolEnableTrustedShare) { ClassLog.ConsoleWriteLog("Enable Trusted Share System..", ClassLogEnumeration.IndexPoolGeneralLog, ClassLogConsoleEnumeration.IndexPoolConsoleYellowLog, true); ClassMinerStats.EnableCheckTrustedMinerStats(); } if (MiningPoolSetting.MiningPoolEnablePayment) { ClassPayment.EnableAutoPaymentSystem(); } if (MiningPoolSetting.MiningPoolMiningPort.Count > 0) { foreach (var miningPoolPort in MiningPoolSetting.MiningPoolMiningPort) { var miningPoolObject = new ClassMiningPool(miningPoolPort.Key, miningPoolPort.Value); miningPoolObject.StartMiningPool(); ListMiningPool.Add(miningPoolPort.Key, miningPoolObject); } ClassApi.StartApiHttpServer(); EnableMiningPoolCommandLine(); } else { ClassLog.ConsoleWriteLog("Cannot start mining pool, their is any ports on the setting.", ClassLogEnumeration.IndexPoolGeneralErrorLog, ClassLogConsoleEnumeration.IndexPoolConsoleRedLog, true); return(false); } } else { return(false); } } else { return(false); } } else { return(false); } return(true); }
static void Main(string[] args) { EnableCatchUnexpectedException(); Console.CancelKeyPress += Console_CancelKeyPress; Thread.CurrentThread.Name = Path.GetFileName(Environment.GetCommandLineArgs()[0]); GlobalCultureInfo = new CultureInfo("fr-FR"); ClassLog.LogInitialization(); ServicePointManager.DefaultConnectionLimit = 65535; ClassConsole.ConsoleWriteLine(ClassConnectorSetting.CoinName + " RPC Wallet - " + Assembly.GetExecutingAssembly().GetName().Version + "R", ClassConsoleColorEnumeration.IndexConsoleBlueLog, LogLevel); if (ClassRpcSetting.InitializeRpcWalletSetting()) { ClassConsole.ConsoleWriteLine("Please write your rpc wallet password for decrypt your databases of wallet (Input keys are hidden): ", ClassConsoleColorEnumeration.IndexConsoleYellowLog, LogLevel); ClassRpcDatabase.SetRpcDatabasePassword(ClassUtility.GetHiddenConsoleInput()); ClassConsole.ConsoleWriteLine("RPC Wallet Database loading..", ClassConsoleColorEnumeration.IndexConsoleYellowLog, LogLevel); if (ClassRpcDatabase.LoadRpcDatabaseFile()) { ClassConsole.ConsoleWriteLine("RPC Wallet Database successfully loaded.", ClassConsoleColorEnumeration.IndexConsoleGreenLog, LogLevel); ClassConsole.ConsoleWriteLine("RPC Sync Database loading..", ClassConsoleColorEnumeration.IndexConsoleYellowLog, LogLevel); if (ClassSyncDatabase.InitializeSyncDatabase()) { ClassConsole.ConsoleWriteLine("RPC Sync Database successfully loaded.", ClassConsoleColorEnumeration.IndexConsoleGreenLog, LogLevel); if (ClassRpcSetting.WalletEnableAutoUpdateWallet) { ClassConsole.ConsoleWriteLine("Enable Auto Update Wallet System..", ClassConsoleColorEnumeration.IndexConsoleYellowLog, LogLevel); ClassWalletUpdater.EnableAutoUpdateWallet(); ClassConsole.ConsoleWriteLine("Enable Auto Update Wallet System done.", ClassConsoleColorEnumeration.IndexConsoleGreenLog, LogLevel); } ClassConsole.ConsoleWriteLine("Start RPC Wallet API Server..", ClassConsoleColorEnumeration.IndexConsoleYellowLog, LogLevel); ClassApi.StartApiHttpServer(); ClassConsole.ConsoleWriteLine("Start RPC Wallet API Server sucessfully started.", ClassConsoleColorEnumeration.IndexConsoleGreenLog, LogLevel); if (ClassRpcSetting.RpcWalletEnableRemoteNodeSync && ClassRpcSetting.RpcWalletRemoteNodeHost != string.Empty && ClassRpcSetting.RpcWalletRemoteNodePort != 0) { ClassConsole.ConsoleWriteLine("RPC Remote Node Sync system loading..", ClassConsoleColorEnumeration.IndexConsoleYellowLog, LogLevel); ThreadRemoteNodeSync = new Thread(async() => await ClassRemoteSync.ConnectRpcWalletToRemoteNodeSyncAsync()); ThreadRemoteNodeSync.Start(); } ClassConsole.ConsoleWriteLine("Enable Command Line system.", ClassConsoleColorEnumeration.IndexConsoleGreenLog, LogLevel); ClassConsoleCommandLine.EnableConsoleCommandLine(); } else { ClassConsole.ConsoleWriteLine("Cannot read RPC Sync Database, the database is maybe corrupted.", ClassConsoleColorEnumeration.IndexConsoleRedLog, LogLevel); Console.WriteLine("Press ENTER to exit."); Console.ReadLine(); Environment.Exit(0); } } else { ClassConsole.ConsoleWriteLine("Cannot read RPC Wallet Database, the database is maybe corrupted.", ClassConsoleColorEnumeration.IndexConsoleRedLog, LogLevel); Console.WriteLine("Press ENTER to exit."); Console.ReadLine(); Environment.Exit(0); } } else { ClassConsole.ConsoleWriteLine("Cannot read RPC Wallet setting, the setting is maybe corrupted, you can delete your setting file to build another one.", ClassConsoleColorEnumeration.IndexConsoleRedLog, LogLevel); Console.WriteLine("Press ENTER to exit."); Console.ReadLine(); Environment.Exit(0); } }