Implement stuff
MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -92,7 +92,7 @@ namespace WalletWasabi.Gui
Config.LoadOrCreateDefaultFile();
HostedServices = new HostedServices();
- WalletManager = new WalletManager(new WalletDirectories(DataDir));
+ WalletManager = new WalletManager(Network, new WalletDirectories(DataDir));
LegalDocuments = LegalDocuments.TryLoadAgreed(DataDir);
@@ -329,7 +329,7 @@ namespace WalletWasabi.Gui
#endregion JsonRpcServerInitialization
- WalletManager.RegisterServices(BitcoinStore, Synchronizer, Nodes, DataDir, Config.ServiceConfiguration, FeeProviders, BitcoinCoreNode);
+ WalletManager.RegisterServices(BitcoinStore, Synchronizer, Nodes, Config.ServiceConfiguration, FeeProviders, BitcoinCoreNode);
}
catch (Exception ex)
{
@@ -477,7 +477,7 @@ namespace WalletWasabi.Gui
{
// In lurking wife mode no notification is raised.
// If there are no news, then don't bother too.
- if (UiConfig.LurkingWifeMode is true || !e.IsNews)
+ if (UiConfig.LurkingWifeMode is true || !e.IsNews || (sender as Wallet).State != WalletState.Started)
{
return;
}

MODIFY
WalletWasabi.Tests/IntegrationTests/P2pTests.cs
WalletWasabi.Tests/IntegrationTests/P2pTests.cs
@@ -95,6 +95,7 @@ namespace WalletWasabi.Tests.IntegrationTests
KeyManager keyManager = KeyManager.CreateNew(out _, "password");
WasabiSynchronizer syncer = new WasabiSynchronizer(network, bitcoinStore, new Uri("http://localhost:12345"), Global.Instance.TorSocks5Endpoint);
using Wallet wallet = new Wallet(
+ network,
bitcoinStore,
keyManager,
syncer,

MODIFY
WalletWasabi.Tests/RegressionTests/BuildTests.cs
WalletWasabi.Tests/RegressionTests/BuildTests.cs
@@ -59,7 +59,7 @@ namespace WalletWasabi.Tests.RegressionTests
// 5. Create wallet service.
var workDir = Common.GetWorkDir();
- using var wallet = new Wallet(bitcoinStore, keyManager, synchronizer, nodes, workDir, serviceConfiguration, synchronizer);
+ using var wallet = new Wallet(network, bitcoinStore, keyManager, synchronizer, nodes, workDir, serviceConfiguration, synchronizer);
wallet.NewFilterProcessed += Common.Wallet_NewFilterProcessed;
var scp = new Key().ScriptPubKey;
@@ -218,8 +218,8 @@ namespace WalletWasabi.Tests.RegressionTests
// 5. Create wallet service.
var workDir = Common.GetWorkDir();
- var walletManager = new WalletManager(null);
- walletManager.RegisterServices(bitcoinStore, synchronizer, nodes, workDir, serviceConfiguration, synchronizer, null);
+ var walletManager = new WalletManager(network, new WalletDirectories(workDir));
+ walletManager.RegisterServices(bitcoinStore, synchronizer, nodes, serviceConfiguration, synchronizer, null);
var baseTip = await rpc.GetBestBlockHashAsync();

MODIFY
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
@@ -1312,11 +1312,11 @@ namespace WalletWasabi.Tests.RegressionTests
// 5. Create wallet service.
var workDir = Common.GetWorkDir();
- using var wallet = new Wallet(bitcoinStore, keyManager, synchronizer, nodes, workDir, serviceConfiguration, synchronizer);
+ using var wallet = new Wallet(network, bitcoinStore, keyManager, synchronizer, nodes, workDir, serviceConfiguration, synchronizer);
wallet.NewFilterProcessed += Common.Wallet_NewFilterProcessed;
var workDir2 = Path.Combine(Common.GetWorkDir(), "2");
- using var wallet2 = new Wallet(bitcoinStore, keyManager2, synchronizer2, nodes2, workDir2, serviceConfiguration, synchronizer2);
+ using var wallet2 = new Wallet(network, bitcoinStore, keyManager2, synchronizer2, nodes2, workDir2, serviceConfiguration, synchronizer2);
// Get some money, make it confirm.
var key = keyManager.GetNextReceiveKey("fundZeroLink", out _);

MODIFY
WalletWasabi.Tests/RegressionTests/SendTests.cs
WalletWasabi.Tests/RegressionTests/SendTests.cs
@@ -57,8 +57,8 @@ namespace WalletWasabi.Tests.RegressionTests
// 5. Create wallet service.
var workDir = Common.GetWorkDir();
- var walletManager = new WalletManager(null);
- walletManager.RegisterServices(bitcoinStore, synchronizer, nodes, workDir, serviceConfiguration, synchronizer, null);
+ var walletManager = new WalletManager(network, new WalletDirectories(workDir));
+ walletManager.RegisterServices(bitcoinStore, synchronizer, nodes, serviceConfiguration, synchronizer, null);
// Get some money, make it confirm.
var key = keyManager.GetNextReceiveKey("foo label", out _);
@@ -531,8 +531,8 @@ namespace WalletWasabi.Tests.RegressionTests
// 5. Create wallet service.
var workDir = Common.GetWorkDir();
- var walletManager = new WalletManager(null);
- walletManager.RegisterServices(bitcoinStore, synchronizer, nodes, workDir, serviceConfiguration, synchronizer, null);
+ var walletManager = new WalletManager(network, new WalletDirectories(workDir));
+ walletManager.RegisterServices(bitcoinStore, synchronizer, nodes, serviceConfiguration, synchronizer, null);
// Get some money, make it confirm.
var key = keyManager.GetNextReceiveKey("foo label", out _);
@@ -699,7 +699,7 @@ namespace WalletWasabi.Tests.RegressionTests
// 5. Create wallet service.
var workDir = Common.GetWorkDir();
- using var wallet = new Wallet(bitcoinStore, keyManager, synchronizer, nodes, workDir, serviceConfiguration, synchronizer);
+ using var wallet = new Wallet(network, bitcoinStore, keyManager, synchronizer, nodes, workDir, serviceConfiguration, synchronizer);
wallet.NewFilterProcessed += Common.Wallet_NewFilterProcessed;
Assert.Empty(wallet.Coins);

MODIFY
WalletWasabi.Tests/RegressionTests/WalletTests.cs
WalletWasabi.Tests/RegressionTests/WalletTests.cs
@@ -296,7 +296,7 @@ namespace WalletWasabi.Tests.RegressionTests
// 4. Create wallet service.
var workDir = Common.GetWorkDir();
- using var wallet = new Wallet(bitcoinStore, keyManager, synchronizer, nodes, workDir, serviceConfiguration, synchronizer);
+ using var wallet = new Wallet(network, bitcoinStore, keyManager, synchronizer, nodes, workDir, serviceConfiguration, synchronizer);
wallet.NewFilterProcessed += Common.Wallet_NewFilterProcessed;
// Get some money, make it confirm.

MODIFY
WalletWasabi/Wallets/Wallet.cs
WalletWasabi/Wallets/Wallet.cs
@@ -40,6 +40,7 @@ namespace WalletWasabi.Wallets
private Node _localBitcoinCoreNode = null;
public Wallet(
+ Network network,
BitcoinStore bitcoinStore,
KeyManager keyManager,
WasabiSynchronizer syncer,
@@ -49,6 +50,7 @@ namespace WalletWasabi.Wallets
IFeeProvider feeProvider,
CoreNode coreNode = null)
{
+ Network = Guard.NotNull(nameof(network), network);
BitcoinStore = Guard.NotNull(nameof(bitcoinStore), bitcoinStore);
KeyManager = Guard.NotNull(nameof(keyManager), keyManager);
Nodes = Guard.NotNull(nameof(nodes), nodes);
@@ -76,7 +78,7 @@ namespace WalletWasabi.Wallets
if (Directory.Exists(BlocksFolderPath))
{
- if (Synchronizer.Network == Network.RegTest)
+ if (Network == Network.RegTest)
{
Directory.Delete(BlocksFolderPath, true);
Directory.CreateDirectory(BlocksFolderPath);
@@ -121,7 +123,7 @@ namespace WalletWasabi.Wallets
/// </summary>
public ICoinsView Coins { get; }
- public Network Network => Synchronizer.Network;
+ public Network Network { get; }
public TransactionProcessor TransactionProcessor { get; }
public Node LocalBitcoinCoreNode
@@ -315,13 +317,13 @@ namespace WalletWasabi.Wallets
BitcoinStore.MempoolService.TransactionReceived -= Mempool_TransactionReceived;
TransactionProcessor.WalletRelevantTransactionProcessed -= TransactionProcessor_WalletRelevantTransactionProcessedAsync;
ChaumianClient.OnDequeue -= ChaumianClient_OnDequeue;
- }
-
- DisconnectDisposeNullLocalBitcoinCoreNode();
await ChaumianClient.StopAsync(cancel).ConfigureAwait(false);
Logger.LogInfo($"{nameof(ChaumianClient)} is stopped.");
}
+
+ DisconnectDisposeNullLocalBitcoinCoreNode();
+ }
finally
{
State = WalletState.Stopped;
@@ -395,7 +397,7 @@ namespace WalletWasabi.Wallets
}
}
- WalletRelevantTransactionProcessed?.Invoke(sender, e);
+ WalletRelevantTransactionProcessed?.Invoke(this, e);
}
catch (Exception ex)
{
@@ -405,7 +407,7 @@ namespace WalletWasabi.Wallets
private void ChaumianClient_OnDequeue(object sender, DequeueResult e)
{
- OnDequeue?.Invoke(sender, e);
+ OnDequeue?.Invoke(this, e);
}
private void Mempool_TransactionReceived(object sender, SmartTransaction tx)
@@ -578,7 +580,7 @@ namespace WalletWasabi.Wallets
try
{
var blockBytes = await File.ReadAllBytesAsync(filePath, cancel);
- block = Block.Load(blockBytes, Synchronizer.Network);
+ block = Block.Load(blockBytes, Network);
}
catch
{
@@ -623,7 +625,7 @@ namespace WalletWasabi.Wallets
// Select a random node we are connected to.
Node node = Nodes.ConnectedNodes.RandomElement();
- if (node == default(Node) && !node.IsConnected && Synchronizer.Network == Network.RegTest)
+ if (node == default(Node) && !node.IsConnected && Network == Network.RegTest)
{
await Task.Delay(100);
continue;

MODIFY
WalletWasabi/Wallets/WalletManager.cs
WalletWasabi/Wallets/WalletManager.cs
@@ -25,13 +25,17 @@ namespace WalletWasabi.Wallets
{
public class WalletManager
{
- public WalletManager(WalletDirectories walletDirectories)
+ public WalletManager(Network network, WalletDirectories walletDirectories)
{
+ using (BenchmarkLogger.Measure())
+ {
+ Network = Guard.NotNull(nameof(network), network);
+ WalletDirectories = Guard.NotNull(nameof(walletDirectories), walletDirectories);
Wallets = new Dictionary<Wallet, HashSet<uint256>>();
Lock = new object();
AddRemoveLock = new AsyncLock();
CancelAllInitialization = new CancellationTokenSource();
- WalletDirectories = walletDirectories;
+ }
}
private CancellationTokenSource CancelAllInitialization { get; }
@@ -47,14 +51,13 @@ namespace WalletWasabi.Wallets
private BitcoinStore BitcoinStore { get; set; }
private WasabiSynchronizer Synchronizer { get; set; }
private NodesGroup Nodes { get; set; }
- private string DataDir { get; set; }
private ServiceConfiguration ServiceConfiguration { get; set; }
public void SignalQuitPending(bool isQuitPending)
{
lock (Lock)
{
- foreach (var client in Wallets.Keys.Select(x => x.ChaumianClient))
+ foreach (var client in Wallets.Keys.Where(x => x.ChaumianClient is { }).Select(x => x.ChaumianClient))
{
client.IsQuitPending = isQuitPending;
}
@@ -63,13 +66,14 @@ namespace WalletWasabi.Wallets
private IFeeProvider FeeProvider { get; set; }
private CoreNode BitcoinCoreNode { get; set; }
+ public Network Network { get; }
public WalletDirectories WalletDirectories { get; }
public Wallet GetFirstOrDefaultWallet()
{
lock (Lock)
{
- return Wallets.Keys.FirstOrDefault();
+ return Wallets.Keys.FirstOrDefault(x => x.State == WalletState.Started);
}
}
@@ -77,7 +81,7 @@ namespace WalletWasabi.Wallets
{
lock (Lock)
{
- return Wallets.Keys.Any();
+ return Wallets.Keys.Any(x => x.State >= WalletState.Starting);
}
}
@@ -88,7 +92,7 @@ namespace WalletWasabi.Wallets
Wallet wallet = null;
try
{
- wallet = new Wallet(BitcoinStore, keyManager, Synchronizer, Nodes, DataDir, ServiceConfiguration, FeeProvider, BitcoinCoreNode);
+ wallet = new Wallet(Network, BitcoinStore, keyManager, Synchronizer, Nodes, WalletDirectories.WorkDir, ServiceConfiguration, FeeProvider, BitcoinCoreNode);
var cancel = CancelAllInitialization.Token;
lock (Lock)
@@ -129,7 +133,7 @@ namespace WalletWasabi.Wallets
IEnumerable<Task> tasks = null;
lock (Lock)
{
- tasks = Wallets.Keys.Select(x => x.ChaumianClient.DequeueAllCoinsFromMixGracefullyAsync(reason, token)).ToArray();
+ tasks = Wallets.Keys.Where(x => x.ChaumianClient is { }).Select(x => x.ChaumianClient.DequeueAllCoinsFromMixGracefullyAsync(reason, token)).ToArray();
}
await Task.WhenAll(tasks).ConfigureAwait(false);
}
@@ -258,12 +262,11 @@ namespace WalletWasabi.Wallets
}
}
- public void RegisterServices(BitcoinStore bitcoinStore, WasabiSynchronizer synchronizer, NodesGroup nodes, string dataDir, ServiceConfiguration serviceConfiguration, IFeeProvider feeProvider, CoreNode bitcoinCoreNode)
+ public void RegisterServices(BitcoinStore bitcoinStore, WasabiSynchronizer synchronizer, NodesGroup nodes, ServiceConfiguration serviceConfiguration, IFeeProvider feeProvider, CoreNode bitcoinCoreNode)
{
BitcoinStore = bitcoinStore;
Synchronizer = synchronizer;
Nodes = nodes;
- DataDir = dataDir;
ServiceConfiguration = serviceConfiguration;
FeeProvider = feeProvider;
BitcoinCoreNode = bitcoinCoreNode;

Implement stuff