Skip to content
Permalink
Browse files

A bunch of stylistic changes

  • Loading branch information...
NicolasDorier committed Jul 8, 2019
1 parent a482b54 commit 75ff55d77eb10ea5d3dfc3453089f73a72866b46
@@ -34,17 +34,16 @@ namespace WalletWasabi.Backend.Controllers
[Route("api/v" + Constants.BackendMajorVersion + "/btc/[controller]")]
public class ChaumianCoinJoinController : Controller
{
public ChaumianCoinJoinController(Global global)
{
Global = global;
}
public Global Global { get; }
private RPCClient RpcClient => Global.RpcClient;

private Network Network => Global.Config.Network;

private CcjCoordinator Coordinator => Global.Coordinator;

public ChaumianCoinJoinController(Global global)
{
Global = global;
}

/// <summary>
/// Satoshi gets various status information.
/// </summary>
@@ -15,32 +15,30 @@ namespace WalletWasabi.Backend
{
public class InitConfigStartupTask : IStartupTask
{
private readonly Global _global;
private readonly HostingEnvironment _hostingEnvironment;
private UnversionedWebBuilder _unversionedWebBuilder;

private static List<string> Last5CoinJoins { get; set; } = new List<string>();
private static object UpdateUnversionedLock { get; } = new object();
public UnversionedWebBuilder UnversionedWebBuilder { get; }
public Global Global { get; }

public InitConfigStartupTask(Global global, IHostingEnvironment hostingEnvironment)
{
_global = global;
_hostingEnvironment = (HostingEnvironment)hostingEnvironment;
Global = global;
UnversionedWebBuilder = new UnversionedWebBuilder(global, ((HostingEnvironment)hostingEnvironment).WebRootPath);
}

public async Task ExecuteAsync(CancellationToken cancellationToken)
{
Logger.InitializeDefaults(Path.Combine(_global.DataDir, "Logs.txt"));
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 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 roundConfigFilePath = Path.Combine(Global.DataDir, "CcjRoundConfig.json");
var roundConfig = new CcjRoundConfig(roundConfigFilePath);
await roundConfig.LoadOrCreateDefaultFileAsync();
Logger.LogInfo<CcjRoundConfig>("RoundConfig is successfully initialized.");
@@ -49,23 +47,22 @@ public async Task ExecuteAsync(CancellationToken cancellationToken)
credentials: RPCCredentialString.Parse(config.BitcoinRpcConnectionString),
network: config.Network);

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

try
{
_unversionedWebBuilder = new UnversionedWebBuilder(_hostingEnvironment.WebRootPath);
Directory.CreateDirectory(_unversionedWebBuilder.UnversionedFolder);
_unversionedWebBuilder.CreateDownloadTextWithVersionHtml();
_unversionedWebBuilder.CloneAndUpdateOnionIndexHtml();
Directory.CreateDirectory(UnversionedWebBuilder.UnversionedFolder);
UnversionedWebBuilder.CreateDownloadTextWithVersionHtml();
UnversionedWebBuilder.CloneAndUpdateOnionIndexHtml();

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

_global.Coordinator.CoinJoinBroadcasted += Coordinator_CoinJoinBroadcasted;
Global.Coordinator.CoinJoinBroadcasted += Coordinator_CoinJoinBroadcasted;
}
catch (Exception ex)
{
@@ -94,7 +91,7 @@ private void Coordinator_CoinJoinBroadcasted(object sender, Transaction tx)
Last5CoinJoins.RemoveLast();
}
Last5CoinJoins.Insert(0, tx.GetHash().ToString());
_unversionedWebBuilder.UpdateCoinJoinsHtml(_global, Last5CoinJoins);
UnversionedWebBuilder.UpdateCoinJoinsHtml(Last5CoinJoins);
}
}
catch (Exception ex)
@@ -57,7 +57,7 @@ public void ConfigureServices(IServiceCollection services)
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
#pragma warning disable IDE0060 // Remove unused parameter

public void Configure(IApplicationBuilder app, IHostingEnvironment env, Global backendGlobal)
public void Configure(IApplicationBuilder app, IHostingEnvironment env, Global global)
#pragma warning restore IDE0060 // Remove unused parameter
{
app.UseStaticFiles();
@@ -81,34 +81,34 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, Global b
app.UseMvc();

var applicationLifetime = app.ApplicationServices.GetRequiredService<IApplicationLifetime>();
applicationLifetime.ApplicationStopping.Register(() => OnShutdown(backendGlobal)); // Don't register async, that won't hold up the shutdown
applicationLifetime.ApplicationStopping.Register(() => OnShutdown(global)); // Don't register async, that won't hold up the shutdown
}

private void OnShutdown(Global backendGlobal)
private void OnShutdown(Global global)
{
CleanupAsync(backendGlobal).GetAwaiter().GetResult(); // This is needed, if async function is regisered then it won't wait until it finishes
CleanupAsync(global).GetAwaiter().GetResult(); // This is needed, if async function is regisered then it won't wait until it finishes
}

private async Task CleanupAsync(Global backendGlobal)
private async Task CleanupAsync(Global global)
{
backendGlobal.Coordinator?.Dispose();
global.Coordinator?.Dispose();
Logger.LogInfo<Startup>("Coordinator is disposed.");

if (backendGlobal.IndexBuilderService != null)
if (global.IndexBuilderService != null)
{
await backendGlobal.IndexBuilderService.StopAsync();
await global.IndexBuilderService.StopAsync();
Logger.LogInfo<Startup>("IndexBuilderService is disposed.");
}

if (backendGlobal.RoundConfigWatcher != null)
if (global.RoundConfigWatcher != null)
{
await backendGlobal.RoundConfigWatcher.StopAsync();
await global.RoundConfigWatcher.StopAsync();
Logger.LogInfo<Startup>("RoundConfigWatcher is disposed.");
}

if (backendGlobal.LocalNode != null)
if (global.LocalNode != null)
{
backendGlobal.DisconnectDisposeNullLocalNode();
global.DisconnectDisposeNullLocalNode();
Logger.LogInfo<Startup>("LocalNode is disposed.");
}

@@ -8,16 +8,17 @@ namespace WalletWasabi.Backend
{
public class UnversionedWebBuilder
{
public UnversionedWebBuilder(string rootFolder)
public Global Global { get; }
public string RootFolder { get; }
public string UnversionedFolder { get; }

public UnversionedWebBuilder(Global global, string rootFolder)
{
Global = global;
RootFolder = rootFolder;
UnversionedFolder = Path.GetFullPath(Path.Combine(RootFolder, "unversioned"));
}

public string RootFolder { get; }

public string UnversionedFolder { get; }

public string CreateFilePath(string fileName) => Path.Combine(UnversionedFolder, fileName);

public static string HtmlStartLine { get; } = "<link href=\"../css/bootstrap.css\" rel=\"stylesheet\" type=\"text/css\" />\r\n<link href=\"../css/OpenSansCondensed300700.css\" rel=\"stylesheet\" type=\"text/css\" />\r\n";
@@ -44,7 +45,7 @@ public void CloneAndUpdateOnionIndexHtml()
File.WriteAllText(onionPath, content);
}

public void UpdateCoinJoinsHtml(Global backendGlobal, IEnumerable<string> coinJoins)
public void UpdateCoinJoinsHtml(IEnumerable<string> coinJoins)
{
var filePath = CreateFilePath("coinjoins-table.html");
var onionFilePath = CreateFilePath("onion-coinjoins-table.html");
@@ -54,7 +55,7 @@ public void UpdateCoinJoinsHtml(Global backendGlobal, IEnumerable<string> coinJo
var endContent = "</ul>";
string blockstreamPath;
string onionBlockstreamPath;
if (backendGlobal.Config.Network == Network.TestNet)
if (Global.Config.Network == Network.TestNet)
{
blockstreamPath = "https://blockstream.info/testnet/tx/";
onionBlockstreamPath = "http://explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion/testnet/tx/";
@@ -130,6 +130,7 @@ public NodeBuilder(string root, string bitcoindPath)
public string BitcoinD { get; }
public List<CoreNode> Nodes { get; } = new List<CoreNode>();
public NodeConfigParameters ConfigParameters { get; } = new NodeConfigParameters();
public Network Network => NBitcoin.Network.RegTest;

public async Task<CoreNode> CreateNodeAsync(bool start = false)
{
@@ -215,7 +216,6 @@ public void Dispose()
}

private List<IDisposable> Disposables { get; } = new List<IDisposable>();
public Network Network => NBitcoin.Network.RegTest;

internal void AddDisposable(IDisposable group)
{

0 comments on commit 75ff55d

Please sign in to comment.
You can’t perform that action at this time.