Start implementing starting services
MODIFY
WalletWasabi.Gui/Config.cs
WalletWasabi.Gui/Config.cs
@@ -28,7 +28,7 @@ namespace WalletWasabi.Gui
[JsonProperty(PropertyName = "MainNetBackendUri")]
public string MainNetBackendUri { get; private set; }
- public Uri GetCurrentUri() => Network == Network.Main ? new Uri(MainNetBackendUri) : new Uri(TestNetBackendUri);
+ public Uri GetCurrentBackendUri() => Network == Network.Main ? new Uri(MainNetBackendUri) : new Uri(TestNetBackendUri);
public Config()
{

MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
using NBitcoin;
using NBitcoin.Protocol;
using NBitcoin.Protocol.Behaviors;
+using Org.BouncyCastle.Math;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
+using WalletWasabi.Crypto;
using WalletWasabi.Helpers;
+using WalletWasabi.KeyManagement;
using WalletWasabi.Logging;
using WalletWasabi.Services;
@@ -30,12 +33,17 @@ namespace WalletWasabi.Gui
}
public static string WalletsDir => Path.Combine(DataDir, "Wallets");
+ public static string BlocksDir => Path.Combine(DataDir, "Blocks", Config.Network.ToString());
+ public static Network Network => Config.Network;
+
+ public static BlindingRsaPubKey BlindingPubKey { get; private set; }
public static string AddressManagerFilePath { get; private set; }
public static AddressManager AddressManager { get; private set; }
public static MemPoolService MemPoolService { get; private set; }
public static NodesGroup Nodes { get; private set; }
public static IndexDownloader IndexDownloader { get; private set; }
+ public static CcjClient ChaumianClient { get; private set; }
public static WalletService WalletService { get; private set; }
public static Config Config { get; private set; }
@@ -43,13 +51,34 @@ namespace WalletWasabi.Gui
public static void Initialize(Config config)
{
WalletService = null;
+ ChaumianClient = null;
Config = Guard.NotNull(nameof(config), config);
- Network network = Config.Network;
+
+ string blindingPubKeyFile = Path.Combine(DataDir, $"BlindingPubKey{Network}.json");
+ if (File.Exists(blindingPubKeyFile))
+ {
+ string blindingPubKeyJson = "";
+ blindingPubKeyJson = File.ReadAllText(blindingPubKeyFile);
+ BlindingPubKey = BlindingRsaPubKey.CreateFromJson(blindingPubKeyJson);
+ }
+ else
+ {
+ if (Network == Network.Main)
+ {
+ BlindingPubKey = new BlindingRsaPubKey(new BigInteger("16421152619146079007287475569112871971988560541093277613438316709041030720662622782033859387192362542996510605015506477964793447620206674394713753349543444988246276357919473682408472170521463339860947351211455351029147665615454176157348164935212551240942809518428851690991984017733153078846480521091423447691527000770982623947706172997649440619968085147635776736938871139581019988225202983052255684151711253254086264386774936200194229277914886876824852466823571396538091430866082004097086602287294474304344865162932126041736158327600847754258634325228417149098062181558798532036659383679712667027126535424484318399849"), new BigInteger("65537"));
+ }
+ else
+ {
+ BlindingPubKey = new BlindingRsaPubKey(new BigInteger("1947359444838071727420232507652169869937347616735925361477589434039008038907229064999576278651443575362470457496666718250346530518268694562965606704838796709743032825816642704620776596590683042135764246115456630753521"), new BigInteger("65537"));
+ }
+ Directory.CreateDirectory(DataDir);
+ File.WriteAllText(blindingPubKeyFile, BlindingPubKey.ToJson());
+ }
var addressManagerFolderPath = Path.Combine(DataDir, "AddressManager");
- AddressManagerFilePath = Path.Combine(addressManagerFolderPath, $"AddressManager{network}.dat");
- var blocksFolderPath = Path.Combine(DataDir, $"Blocks{network}");
+ AddressManagerFilePath = Path.Combine(addressManagerFolderPath, $"AddressManager{Network}.dat");
+ var blocksFolderPath = Path.Combine(DataDir, $"Blocks{Network}");
var connectionParameters = new NodeConnectionParameters();
AddressManager = null;
try
@@ -74,15 +103,15 @@ namespace WalletWasabi.Gui
MemPoolService = new MemPoolService();
connectionParameters.TemplateBehaviors.Add(new MemPoolBehavior(MemPoolService));
- Nodes = new NodesGroup(network, connectionParameters,
+ Nodes = new NodesGroup(Network, connectionParameters,
new NodeRequirement
{
RequiredServices = NodeServices.Network,
MinVersion = Constants.ProtocolVersion_WITNESS_VERSION
});
- var indexFilePath = Path.Combine(DataDir, $"Index{network}.dat");
- IndexDownloader = new IndexDownloader(network, indexFilePath, Config.GetCurrentUri());
+ var indexFilePath = Path.Combine(DataDir, $"Index{Network}.dat");
+ IndexDownloader = new IndexDownloader(Network, indexFilePath, Config.GetCurrentBackendUri());
Nodes.Connect();
Logger.LogInfo("Start connecting to nodes...");
@@ -91,17 +120,38 @@ namespace WalletWasabi.Gui
Logger.LogInfo("Start synchronizing filters...");
}
- public static void Dispose()
+ public static void InitializeWalletService(KeyManager keyManager)
{
- // Dispose index downloader service.
+ ChaumianClient = new CcjClient(Network, BlindingPubKey, keyManager, Config.GetCurrentBackendUri());
+ WalletService = new WalletService(keyManager, IndexDownloader, ChaumianClient, MemPoolService, Nodes, BlocksDir);
+
+ ChaumianClient.Start();
+ Logger.LogInfo("Start Chaumian CoinJoin service...");
+
+ //WalletService.InitializeAsync()
+ Logger.LogInfo("Start WalletService...");
+ }
+
+ public static async Task DisposeAsync()
+ {
+ WalletService?.Dispose();
+ Logger.LogInfo($"{nameof(WalletService)} is stopped.", nameof(Global));
+
IndexDownloader?.Dispose();
Logger.LogInfo($"{nameof(IndexDownloader)} is stopped.", nameof(Global));
Directory.CreateDirectory(Path.GetDirectoryName(AddressManagerFilePath));
AddressManager?.SavePeerFile(AddressManagerFilePath, Config.Network);
Logger.LogInfo($"{nameof(AddressManager)} is saved to `{AddressManagerFilePath}`.", nameof(Global));
+
Nodes?.Dispose();
Logger.LogInfo($"{nameof(Nodes)} are disposed.", nameof(Global));
+
+ if (ChaumianClient != null)
+ {
+ ChaumianClient.StopAsync().GetAwaiter().GetResult();
+ }
+ Logger.LogInfo($"{nameof(ChaumianClient)} is stopped.", nameof(Global));
}
}
}

MODIFY
WalletWasabi.Gui/Program.cs
WalletWasabi.Gui/Program.cs
@@ -46,7 +46,7 @@ namespace WalletWasabi.Gui
finally
{
statusBar?.Dispose();
- Global.Dispose();
+ await Global.DisposeAsync();
}
}

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/LoadWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/LoadWalletViewModel.cs
@@ -73,7 +73,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
var keyManager = KeyManager.FromFile(walletFullPath);
- //Global.WalletService = new WalletService(keyManager)
+ Global.InitializeWalletService(keyManager);
}
}
}

MODIFY
WalletWasabi/Services/CcjClient.cs
WalletWasabi/Services/CcjClient.cs
@@ -651,7 +651,7 @@ namespace WalletWasabi.Services
Cancel?.Cancel();
while (IsStopping)
{
- await Task.Delay(50);
+ Task.Delay(50).GetAwaiter().GetResult(); // DO NOT MAKE IT ASYNC (.NET Core threading brainfart)
}
Cancel?.Dispose();

Start implementing starting services