Apply Global.Instance pattern to Backend
MODIFY
.gitignore
.gitignore
@@ -272,3 +272,4 @@ lcov.info
\.DS_Store
*.DS_Store
/WalletWasabi.Backend/wwwroot/onion-index.html
+/NuGet.Config

MODIFY
WalletWasabi.Backend/Controllers/BatchController.cs
WalletWasabi.Backend/Controllers/BatchController.cs
@@ -52,7 +52,7 @@ namespace WalletWasabi.Backend.Controllers
var knownHash = new uint256(bestKnownBlockHash);
- (Height bestHeight, IEnumerable<FilterModel> filters) = Global.IndexBuilderService.GetFilterLinesExcluding(knownHash, maxNumberOfFilters, out bool found);
+ (Height bestHeight, IEnumerable<FilterModel> filters) = Global.Instance.IndexBuilderService.GetFilterLinesExcluding(knownHash, maxNumberOfFilters, out bool found);
var response = new SynchronizeResponse();
response.Filters = Enumerable.Empty<FilterModel>();

MODIFY
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
@@ -34,11 +34,11 @@ namespace WalletWasabi.Backend.Controllers
[Route("api/v" + Constants.BackendMajorVersion + "/btc/[controller]")]
public class ChaumianCoinJoinController : Controller
{
- private static RPCClient RpcClient => Global.RpcClient;
+ private static RPCClient RpcClient => Global.Instance.RpcClient;
- private static Network Network => Global.Config.Network;
+ private static Network Network => Global.Instance.Config.Network;
- private static CcjCoordinator Coordinator => Global.Coordinator;
+ private static CcjCoordinator Coordinator => Global.Instance.Coordinator;
/// <summary>
/// Satoshi gets various status information.

MODIFY
WalletWasabi.Backend/Program.cs
WalletWasabi.Backend/Program.cs
@@ -25,17 +25,17 @@ namespace WalletWasabi.Backend
{
try
{
- Logger.InitializeDefaults(Path.Combine(Global.DataDir, "Logs.txt"));
+ Logger.InitializeDefaults(Path.Combine(Global.Instance.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.Instance.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.Instance.DataDir, "CcjRoundConfig.json");
var roundConfig = new CcjRoundConfig(roundConfigFilePath);
await roundConfig.LoadOrCreateDefaultFileAsync();
Logger.LogInfo<CcjRoundConfig>("RoundConfig is successfully initialized.");
@@ -44,7 +44,7 @@ namespace WalletWasabi.Backend
credentials: RPCCredentialString.Parse(config.BitcoinRpcConnectionString),
network: config.Network);
- await Global.InitializeAsync(config, roundConfig, rpc);
+ await Global.Instance.InitializeAsync(config, roundConfig, rpc);
try
{
@@ -52,14 +52,14 @@ namespace WalletWasabi.Backend
UnversionedWebBuilder.CreateDownloadTextWithVersionHtml();
UnversionedWebBuilder.CloneAndUpdateOnionIndexHtml();
- if (File.Exists(Global.Coordinator.CoinJoinsFilePath))
+ if (File.Exists(Global.Instance.Coordinator.CoinJoinsFilePath))
{
- string[] allLines = File.ReadAllLines(Global.Coordinator.CoinJoinsFilePath);
+ string[] allLines = File.ReadAllLines(Global.Instance.Coordinator.CoinJoinsFilePath);
Last5CoinJoins = allLines.TakeLast(5).Reverse().ToList();
UnversionedWebBuilder.UpdateCoinJoinsHtml(Last5CoinJoins);
}
- Global.Coordinator.CoinJoinBroadcasted += Coordinator_CoinJoinBroadcasted;
+ Global.Instance.Coordinator.CoinJoinBroadcasted += Coordinator_CoinJoinBroadcasted;
}
catch (Exception ex)
{

MODIFY
WalletWasabi.Backend/UnversionedWebBuilder.cs
WalletWasabi.Backend/UnversionedWebBuilder.cs
@@ -51,7 +51,7 @@ namespace WalletWasabi.Backend
var endContent = "</ul>";
string blockstreamPath;
string onionBlockstreamPath;
- if (Global.Config.Network == Network.TestNet)
+ if (Global.Instance.Config.Network == Network.TestNet)
{
blockstreamPath = "https://blockstream.info/testnet/tx/";
onionBlockstreamPath = "http://explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion/testnet/tx/";

MODIFY
WalletWasabi.Tests/RegTests.cs
WalletWasabi.Tests/RegTests.cs
@@ -51,7 +51,7 @@ namespace WalletWasabi.Tests
private async Task AssertFiltersInitializedAsync()
{
- var firstHash = await Backend.Global.RpcClient.GetBlockHashAsync(0);
+ var firstHash = await Backend.Global.Instance.RpcClient.GetBlockHashAsync(0);
while (true)
{
using (var client = new WasabiClient(new Uri(RegTestFixture.BackendEndPoint), null))
@@ -77,16 +77,16 @@ namespace WalletWasabi.Tests
await AssertFiltersInitializedAsync(); // Make sure fitlers are created on the server side.
if (numberOfBlocksToGenerate != 0)
{
- await Backend.Global.RpcClient.GenerateAsync(numberOfBlocksToGenerate); // Make sure everything is confirmed.
+ await Backend.Global.Instance.RpcClient.GenerateAsync(numberOfBlocksToGenerate); // Make sure everything is confirmed.
}
- Backend.Global.Coordinator.UtxoReferee.Clear();
+ Backend.Global.Instance.Coordinator.UtxoReferee.Clear();
- var network = Backend.Global.RpcClient.Network;
+ var network = Backend.Global.Instance.RpcClient.Network;
var serviceConfiguration = new ServiceConfiguration(2, 2, 21, 50, RegTestFixture.BackendRegTestNode.Endpoint, Money.Coins(0.0001m));
var bitcoinStore = new BitcoinStore();
var dir = Path.Combine(Global.Instance.DataDir, caller);
await bitcoinStore.InitializeAsync(dir, network);
- return ("password", Backend.Global.RpcClient, network, Backend.Global.Coordinator, serviceConfiguration, bitcoinStore);
+ return ("password", Backend.Global.Instance.RpcClient, network, Backend.Global.Instance.Coordinator, serviceConfiguration, bitcoinStore);
}
#region BackendTests
@@ -166,7 +166,7 @@ namespace WalletWasabi.Tests
var indexFilePath = Path.Combine(indexBuilderServiceDir, $"Index{rpc.Network}.dat");
var utxoSetFilePath = Path.Combine(indexBuilderServiceDir, $"UtxoSet{rpc.Network}.dat");
- var indexBuilderService = new IndexBuilderService(rpc, Backend.Global.TrustedNodeNotifyingBehavior, indexFilePath, utxoSetFilePath);
+ var indexBuilderService = new IndexBuilderService(rpc, Backend.Global.Instance.TrustedNodeNotifyingBehavior, indexFilePath, utxoSetFilePath);
try
{
indexBuilderService.Synchronize();
@@ -404,7 +404,7 @@ namespace WalletWasabi.Tests
var tipBlock = await rpc.GetBlockHeaderAsync(tip);
Assert.Equal(tipBlock.HashPrevBlock, bitcoinStore.HashChain.GetChain().Select(x => x.hash).ToArray()[bitcoinStore.HashChain.HashCount - 2]);
- var utxoPath = Backend.Global.IndexBuilderService.Bech32UtxoSetFilePath;
+ var utxoPath = Backend.Global.Instance.IndexBuilderService.Bech32UtxoSetFilePath;
var utxoLines = await File.ReadAllTextAsync(utxoPath);
Assert.Contains(tx1.ToString(), utxoLines);
Assert.Contains(tx2.ToString(), utxoLines);
@@ -489,7 +489,7 @@ namespace WalletWasabi.Tests
private async Task WaitForIndexesToSyncAsync(TimeSpan timeout, BitcoinStore bitcoinStore)
{
- var bestHash = await Backend.Global.RpcClient.GetBestBlockHashAsync();
+ var bestHash = await Backend.Global.Instance.RpcClient.GetBestBlockHashAsync();
var times = 0;
while (bitcoinStore.HashChain.TipHash != bestHash)
@@ -522,7 +522,7 @@ namespace WalletWasabi.Tests
// Create the services.
// 1. Create connection service.
- var nodes = new NodesGroup(Backend.Global.Config.Network, requirements: Constants.NodeRequirements);
+ var nodes = new NodesGroup(Backend.Global.Instance.Config.Network, requirements: Constants.NodeRequirements);
nodes.ConnectedNodes.Add(await RegTestFixture.BackendRegTestNode.CreateNodeClientAsync());
// 2. Create mempool service.
@@ -751,7 +751,7 @@ namespace WalletWasabi.Tests
// Create the services.
// 1. Create connection service.
- var nodes = new NodesGroup(Backend.Global.Config.Network, requirements: Constants.NodeRequirements);
+ var nodes = new NodesGroup(Backend.Global.Instance.Config.Network, requirements: Constants.NodeRequirements);
nodes.ConnectedNodes.Add(await RegTestFixture.BackendRegTestNode.CreateNodeClientAsync());
// 2. Create mempool service.
@@ -1194,7 +1194,7 @@ namespace WalletWasabi.Tests
// Create the services.
// 1. Create connection service.
- var nodes = new NodesGroup(Backend.Global.Config.Network, requirements: Constants.NodeRequirements);
+ var nodes = new NodesGroup(Backend.Global.Instance.Config.Network, requirements: Constants.NodeRequirements);
nodes.ConnectedNodes.Add(await RegTestFixture.BackendRegTestNode.CreateNodeClientAsync());
// 2. Create mempool service.
@@ -1357,7 +1357,7 @@ namespace WalletWasabi.Tests
// Create the services.
// 1. Create connection service.
- var nodes = new NodesGroup(Backend.Global.Config.Network, requirements: Constants.NodeRequirements);
+ var nodes = new NodesGroup(Backend.Global.Instance.Config.Network, requirements: Constants.NodeRequirements);
nodes.ConnectedNodes.Add(await RegTestFixture.BackendRegTestNode.CreateNodeClientAsync());
// 2. Create mempool service.
@@ -1521,7 +1521,7 @@ namespace WalletWasabi.Tests
// Create the services.
// 1. Create connection service.
- var nodes = new NodesGroup(Backend.Global.Config.Network, requirements: Constants.NodeRequirements);
+ var nodes = new NodesGroup(Backend.Global.Instance.Config.Network, requirements: Constants.NodeRequirements);
nodes.ConnectedNodes.Add(await RegTestFixture.BackendRegTestNode.CreateNodeClientAsync());
// 2. Create mempool service.
@@ -1687,7 +1687,7 @@ namespace WalletWasabi.Tests
// Create the services.
// 1. Create connection service.
- var nodes = new NodesGroup(Backend.Global.Config.Network, requirements: Constants.NodeRequirements);
+ var nodes = new NodesGroup(Backend.Global.Instance.Config.Network, requirements: Constants.NodeRequirements);
nodes.ConnectedNodes.Add(await RegTestFixture.BackendRegTestNode.CreateNodeClientAsync());
// 2. Create mempool service.
@@ -1809,7 +1809,7 @@ namespace WalletWasabi.Tests
mempoolTxId.ToString()
});
- using (var coordinatorToTest = new CcjCoordinator(network, Backend.Global.TrustedNodeNotifyingBehavior, folder, rpc, coordinator.RoundConfig))
+ using (var coordinatorToTest = new CcjCoordinator(network, Backend.Global.Instance.TrustedNodeNotifyingBehavior, folder, rpc, coordinator.RoundConfig))
{
var txIds = await File.ReadAllLinesAsync(cjfile);
@@ -1824,7 +1824,7 @@ namespace WalletWasabi.Tests
"This line is invalid (the file is corrupted)",
offchainTxId.ToString(),
});
- var coordinatorToTest2 = new CcjCoordinator(network, Backend.Global.TrustedNodeNotifyingBehavior, folder, rpc, coordinatorToTest.RoundConfig);
+ var coordinatorToTest2 = new CcjCoordinator(network, Backend.Global.Instance.TrustedNodeNotifyingBehavior, folder, rpc, coordinatorToTest.RoundConfig);
coordinatorToTest2?.Dispose();
txIds = await File.ReadAllLinesAsync(cjfile);
Assert.Single(txIds);
@@ -3298,10 +3298,10 @@ namespace WalletWasabi.Tests
// Create the services.
// 1. Create connection service.
- var nodes = new NodesGroup(Backend.Global.Config.Network, requirements: Constants.NodeRequirements);
+ var nodes = new NodesGroup(Backend.Global.Instance.Config.Network, requirements: Constants.NodeRequirements);
nodes.ConnectedNodes.Add(await RegTestFixture.BackendRegTestNode.CreateNodeClientAsync());
- var nodes2 = new NodesGroup(Backend.Global.Config.Network, requirements: Constants.NodeRequirements);
+ var nodes2 = new NodesGroup(Backend.Global.Instance.Config.Network, requirements: Constants.NodeRequirements);
nodes2.ConnectedNodes.Add(await RegTestFixture.BackendRegTestNode.CreateNodeClientAsync());
// 2. Create mempool service.

MODIFY
WalletWasabi.Tests/XunitConfiguration/RegTestFixture.cs
WalletWasabi.Tests/XunitConfiguration/RegTestFixture.cs
@@ -35,7 +35,7 @@ namespace WalletWasabi.Tests.XunitConfiguration
var roundConfig = new CcjRoundConfig(Money.Coins(0.1m), 144, 0.7, 0.1m, 100, 120, 60, 60, 60, 1, 24, true, 11);
- Backend.Global.InitializeAsync(config, roundConfig, rpc).GetAwaiter().GetResult();
+ Backend.Global.Instance.InitializeAsync(config, roundConfig, rpc).GetAwaiter().GetResult();
BackendEndPoint = $"http://localhost:{new Random().Next(37130, 38000)}/";
BackendHost = WebHost.CreateDefaultBuilder()

Apply Global.Instance pattern to Backend