public static void Main(string[] args) { Console.WriteLine("Starting up NxtTipbot"); var configSettings = ReadConfig(); var logLevel = GetLogLevel(configSettings); var apiToken = configSettings.Single(c => c.Key == "apitoken").Value; var walletFile = configSettings.Single(c => c.Key == "walletFile").Value; var nxtServerAddress = configSettings.Single(c => c.Key == "nxtServerAddress").Value; var masterKey = configSettings.Single(c => c.Key == "masterKey").Value; var currencyConfigs = GetTransferableConfiguration(configSettings, "currencies"); var assetConfigs = GetTransferableConfiguration(configSettings, "assets"); var blockchainBackup = bool.Parse(configSettings.Single(c => c.Key == "blockchainBackup").Value); var logger = SetupLogging(logLevel); logger.LogInformation($"logLevel: {logLevel}"); logger.LogInformation($"nxtServerAddress: {nxtServerAddress}"); logger.LogInformation($"walletFile: {walletFile}"); logger.LogInformation($"blockchainBackup: {blockchainBackup}"); currencyConfigs.ToList().ForEach(c => logger.LogInformation($"currency id: {c.Id} ({c.Name})")); assetConfigs.ToList().ForEach(a => logger.LogInformation($"asset id: {a.Id} ({a.Name})")); InitDatabase(walletFile); var transferables = new Transferables(); var nxtConnector = new NxtConnector(new ServiceFactory(nxtServerAddress)); var blockchainStore = blockchainBackup ? new BlockchainStore(masterKey, nxtConnector) : null; var walletRepository = new WalletRepository(blockchainStore); var slackHandler = new SlackHandler(nxtConnector, walletRepository, transferables, logger); var slackConnector = new SlackConnector(apiToken, logger, slackHandler); CheckMasterKey(logger, masterKey, nxtConnector); nxtConnector.MasterKey = masterKey; VerifyBlockchainBackup(blockchainBackup, logger, nxtConnector, blockchainStore, walletRepository); slackHandler.SlackConnector = slackConnector; var transferableList = GetTransferables(currencyConfigs, assetConfigs, nxtConnector); CheckReactionIds(transferableList); transferableList.ForEach(t => transferables.AddTransferable(t)); var slackTask = Task.Run(() => slackConnector.Run()); Task.WaitAll(slackTask); logger.LogInformation("Exiting NxtTipbot"); }
private static void VerifyBlockchainBackup(bool blockchainBackup, ILogger logger, NxtConnector nxtConnector, BlockchainStore blockchainStore, WalletRepository walletRepository) { if (blockchainBackup) { logger.LogInformation("Verifying blockchain backup status..."); var backupCount = 0; var accountCount = 0; Task.Run(async() => { var balance = await nxtConnector.GetBalance(Nxt.Singleton, blockchainStore.MainAccount.AccountRs); if (balance < 10) { logger.LogWarning($"Make sure your main account ({blockchainStore.MainAccount.AccountRs}) is properly funded!"); } var accounts = await walletRepository.GetAllAccounts(); accountCount = accounts.Count; await blockchainStore.VerifyBackupStatus(accounts); }).Wait(); logger.LogInformation($"Done, {backupCount} new accounts were backed up ({accountCount} total)."); } }