Add network independence
MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -101,6 +101,8 @@ namespace WalletWasabi.Gui
WalletManager.OnDequeue += WalletManager_OnDequeue;
WalletManager.WalletRelevantTransactionProcessed += WalletManager_WalletRelevantTransactionProcessed;
+
+ SingleInstanceChecker = new SingleInstanceChecker(Network);
}
}
@@ -110,7 +112,7 @@ namespace WalletWasabi.Gui
private CancellationTokenSource StoppingCts { get; }
- private SingleInstanceChecker SingleInstanceChecker { get; } = new SingleInstanceChecker();
+ private SingleInstanceChecker SingleInstanceChecker { get; }
public async Task InitializeNoWalletAsync()
{

MODIFY
WalletWasabi.Tests/UnitTests/Clients/WasabiClientTests.cs
WalletWasabi.Tests/UnitTests/Clients/WasabiClientTests.cs
@@ -117,15 +117,24 @@ namespace WalletWasabi.Tests.UnitTests.Clients
[Fact]
public async Task SingleInstanceTestsAsync()
{
- using (SingleInstanceChecker sic = new SingleInstanceChecker())
+ using (SingleInstanceChecker sic = new SingleInstanceChecker(Network.Main))
{
await sic.CheckAsync().ConfigureAwait(false);
}
- using (SingleInstanceChecker sic = new SingleInstanceChecker())
+ using (SingleInstanceChecker sic = new SingleInstanceChecker(Network.Main))
{
await sic.CheckAsync().ConfigureAwait(false);
await Assert.ThrowsAsync<InvalidOperationException>(async () => await sic.CheckAsync().ConfigureAwait(false));
+ using SingleInstanceChecker sic2 = new SingleInstanceChecker(Network.Main);
+ await Assert.ThrowsAsync<InvalidOperationException>(async () => await sic2.CheckAsync().ConfigureAwait(false));
+ }
+
+ using (SingleInstanceChecker sic = new SingleInstanceChecker(Network.Main))
+ {
+ await sic.CheckAsync().ConfigureAwait(false);
+ using SingleInstanceChecker sicTest = new SingleInstanceChecker(Network.TestNet);
+ await sicTest.CheckAsync().ConfigureAwait(false);
}
}
}

MODIFY
WalletWasabi/Services/SingleInstanceChecker.cs
WalletWasabi/Services/SingleInstanceChecker.cs
+using NBitcoin;
using Nito.AsyncEx;
using System;
using System.Collections.Generic;
@@ -13,14 +14,20 @@ namespace WalletWasabi.Services
private const string MutexString = "WalletWasabiSingleInstance";
private bool _disposedValue;
+ public SingleInstanceChecker(Network network)
+ {
+ Network = network;
+ }
+
private IDisposable SingleApplicationLockHolder { get; set; }
+ private Network Network { get; }
public async Task CheckAsync()
{
using CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.Zero);
// The disposal of this mutex handled by AsyncMutex.WaitForAllMutexToCloseAsync().
- var mutex = new AsyncMutex(MutexString);
+ var mutex = new AsyncMutex($"{MutexString}-{Network}");
try
{
SingleApplicationLockHolder = await mutex.LockAsync(cts.Token).ConfigureAwait(false);

Add network independence