Exemplo n.º 1
0
        private async Task CleanupAsync(Global global)
        {
            var coordinator = global.Coordinator;

            if (coordinator is { })
Exemplo n.º 2
0
 public InitConfigStartupTask(Global global, IHostingEnvironment hostingEnvironment)
 {
     Global          = global;
     WebsiteTorifier = new WebsiteTorifier(((HostingEnvironment)hostingEnvironment).WebRootPath);
 }
Exemplo n.º 3
0
 private void OnShutdown(Global global)
 {
     CleanupAsync(global).GetAwaiter().GetResult();             // This is needed, if async function is registered then it won't wait until it finishes
 }
Exemplo n.º 4
0
#pragma warning disable IDE1006 // Naming Styles

        public static async Task Main(string[] args)
#pragma warning restore IDE1006 // Naming Styles
        {
            try
            {
                Logger.InitializeDefaults(Path.Combine(Global.DataDir, "Logs.txt"));
                Logger.LogStarting("Wasabi Backend");

                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                TaskScheduler.UnobservedTaskException      += TaskScheduler_UnobservedTaskException;
                var configFilePath = Path.Combine(Global.DataDir, "Config.json");
                var config         = new Config(configFilePath);
                await config.LoadOrCreateDefaultFileAsync();

                Logger.LogInfo <Config>("Config is successfully initialized.");

                var roundConfigFilePath = Path.Combine(Global.DataDir, "CcjRoundConfig.json");
                var roundConfig         = new CcjRoundConfig(roundConfigFilePath);
                await roundConfig.LoadOrCreateDefaultFileAsync();

                Logger.LogInfo <CcjRoundConfig>("RoundConfig is successfully initialized.");

                var rpc = new RPCClient(
                    credentials: RPCCredentialString.Parse(config.BitcoinRpcConnectionString),
                    network: config.Network);

                await Global.InitializeAsync(config, roundConfig, rpc);

                try
                {
                    Directory.CreateDirectory(UnversionedWebBuilder.UnversionedFolder);
                    UnversionedWebBuilder.CreateDownloadTextWithVersionHtml();
                    UnversionedWebBuilder.CloneAndUpdateOnionIndexHtml();

                    if (File.Exists(Global.Coordinator.CoinJoinsFilePath))
                    {
                        string[] allLines = File.ReadAllLines(Global.Coordinator.CoinJoinsFilePath);
                        Last5CoinJoins = allLines.TakeLast(5).Reverse().ToList();
                        UnversionedWebBuilder.UpdateCoinJoinsHtml(Last5CoinJoins);
                    }

                    Global.Coordinator.CoinJoinBroadcasted += Coordinator_CoinJoinBroadcasted;
                }
                catch (Exception ex)
                {
                    Logger.LogWarning(ex, nameof(Program));
                }

                var endPoint = "http://localhost:37127/";

                using (var host = WebHost.CreateDefaultBuilder(args)
                                  .UseStartup <Startup>()
                                  .UseUrls(endPoint)
                                  .Build())
                {
                    await host.RunAsync();
                }
            }
            catch (Exception ex)
            {
                Logger.LogCritical <Program>(ex);
            }
            // Note: Don't do finally here. Dispose in Startup.cs.
        }