Ejemplo n.º 1
0
        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");
        }