Networkify wallets
MODIFY
WalletWasabi.Fluent.Desktop/Program.cs
WalletWasabi.Fluent.Desktop/Program.cs
@@ -133,7 +133,8 @@ namespace WalletWasabi.Fluent.Desktop
private static Global CreateGlobal(string dataDir, UiConfig uiConfig, Config config)
{
string torLogsFile = Path.Combine(dataDir, "TorLogs.txt");
- var walletManager = new WalletManager(config.Network, new WalletDirectories(dataDir));
+ RuntimeParams.SetDataDir(dataDir);
+ var walletManager = new WalletManager(config.Network, new WalletDirectories(config.Network, dataDir));
return new Global(dataDir, torLogsFile, config, uiConfig, walletManager);
}

MODIFY
WalletWasabi.Gui/Program.cs
WalletWasabi.Gui/Program.cs
@@ -73,7 +73,8 @@ namespace WalletWasabi.Gui
var config = new Config(Path.Combine(dataDir, "Config.json"));
config.LoadOrCreateDefaultFile();
config.CorrectMixUntilAnonymitySet();
- var walletManager = new WalletManager(config.Network, new WalletDirectories(dataDir));
+ RuntimeParams.SetDataDir(dataDir);
+ var walletManager = new WalletManager(config.Network, new WalletDirectories(config.Network, dataDir));
return new Global(dataDir, torLogsFile, config, uiConfig, walletManager);
}

MODIFY
WalletWasabi.Tests/IntegrationTests/P2pTests.cs
WalletWasabi.Tests/IntegrationTests/P2pTests.cs
@@ -107,7 +107,6 @@ namespace WalletWasabi.Tests.IntegrationTests
keyManager,
syncer,
nodes,
- dataDir,
new ServiceConfiguration(MixUntilAnonymitySet.PrivacyLevelStrong.ToString(), 2, 21, 50, new IPEndPoint(IPAddress.Loopback, network.DefaultPort), Money.Coins(Constants.DefaultDustThreshold)),
syncer,
blockProvider);

MODIFY
WalletWasabi.Tests/RegressionTests/BuildTests.cs
WalletWasabi.Tests/RegressionTests/BuildTests.cs
@@ -58,13 +58,11 @@ namespace WalletWasabi.Tests.RegressionTests
// 4. Create key manager service.
var keyManager = KeyManager.CreateNew(out _, password);
- // 5. Create wallet service.
- var workDir = Helpers.Common.GetWorkDir();
CachedBlockProvider blockProvider = new CachedBlockProvider(
new P2pBlockProvider(nodes, null, synchronizer, serviceConfiguration, network),
bitcoinStore.BlockRepository);
- using var wallet = Wallet.CreateAndRegisterServices(network, bitcoinStore, keyManager, synchronizer, nodes, workDir, serviceConfiguration, synchronizer, blockProvider);
+ using var wallet = Wallet.CreateAndRegisterServices(network, bitcoinStore, keyManager, synchronizer, nodes, serviceConfiguration, synchronizer, blockProvider);
wallet.NewFilterProcessed += Common.Wallet_NewFilterProcessed;
var scp = new Key().ScriptPubKey;
@@ -227,7 +225,7 @@ namespace WalletWasabi.Tests.RegressionTests
CachedBlockProvider blockProvider = new CachedBlockProvider(
new P2pBlockProvider(nodes, null, synchronizer, serviceConfiguration, network),
bitcoinStore.BlockRepository);
- var walletManager = new WalletManager(network, new WalletDirectories(workDir));
+ var walletManager = new WalletManager(network, new WalletDirectories(network, workDir));
walletManager.RegisterServices(bitcoinStore, synchronizer, nodes, serviceConfiguration, synchronizer, blockProvider);
var baseTip = await rpc.GetBestBlockHashAsync();

MODIFY
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
@@ -1388,9 +1388,6 @@ namespace WalletWasabi.Tests.RegressionTests
var keyManager2 = KeyManager.CreateNew(out _, password);
- // 5. Create wallet service.
- var workDir = Helpers.Common.GetWorkDir();
-
CachedBlockProvider blockProvider = new CachedBlockProvider(
new P2pBlockProvider(nodes, null, synchronizer, serviceConfiguration, network),
bitcoinStore.BlockRepository);
@@ -1399,11 +1396,10 @@ namespace WalletWasabi.Tests.RegressionTests
new P2pBlockProvider(nodes2, null, synchronizer, serviceConfiguration, network),
bitcoinStore.BlockRepository);
- using var wallet = Wallet.CreateAndRegisterServices(network, bitcoinStore, keyManager, synchronizer, nodes, workDir, serviceConfiguration, synchronizer, blockProvider);
+ using var wallet = Wallet.CreateAndRegisterServices(network, bitcoinStore, keyManager, synchronizer, nodes, serviceConfiguration, synchronizer, blockProvider);
wallet.NewFilterProcessed += Common.Wallet_NewFilterProcessed;
- var workDir2 = Path.Combine(Helpers.Common.GetWorkDir(), "2");
- using var wallet2 = Wallet.CreateAndRegisterServices(network, bitcoinStore, keyManager2, synchronizer2, nodes2, workDir2, serviceConfiguration, synchronizer2, blockProvider2);
+ using var wallet2 = Wallet.CreateAndRegisterServices(network, bitcoinStore, keyManager2, synchronizer2, nodes2, serviceConfiguration, synchronizer2, blockProvider2);
// Get some money, make it confirm.
var key = keyManager.GetNextReceiveKey("fundZeroLink", out _);

MODIFY
WalletWasabi.Tests/RegressionTests/SendTests.cs
WalletWasabi.Tests/RegressionTests/SendTests.cs
@@ -62,7 +62,7 @@ namespace WalletWasabi.Tests.RegressionTests
new P2pBlockProvider(nodes, null, synchronizer, serviceConfiguration, network),
bitcoinStore.BlockRepository);
- var walletManager = new WalletManager(network, new WalletDirectories(workDir));
+ var walletManager = new WalletManager(network, new WalletDirectories(network, workDir));
walletManager.RegisterServices(bitcoinStore, synchronizer, nodes, serviceConfiguration, synchronizer, blockProvider);
// Get some money, make it confirm.
@@ -542,7 +542,7 @@ namespace WalletWasabi.Tests.RegressionTests
new P2pBlockProvider(nodes, null, synchronizer, serviceConfiguration, network),
bitcoinStore.BlockRepository);
- var walletManager = new WalletManager(network, new WalletDirectories(workDir));
+ var walletManager = new WalletManager(network, new WalletDirectories(network, workDir));
walletManager.RegisterServices(bitcoinStore, synchronizer, nodes, serviceConfiguration, synchronizer, blockProvider);
// Get some money, make it confirm.
@@ -709,14 +709,11 @@ namespace WalletWasabi.Tests.RegressionTests
// 4. Create key manager service.
var keyManager = KeyManager.CreateNew(out _, password);
- // 5. Create wallet service.
- var workDir = Helpers.Common.GetWorkDir();
-
CachedBlockProvider blockProvider = new CachedBlockProvider(
new P2pBlockProvider(nodes, null, synchronizer, serviceConfiguration, network),
bitcoinStore.BlockRepository);
- using var wallet = Wallet.CreateAndRegisterServices(network, bitcoinStore, keyManager, synchronizer, nodes, workDir, serviceConfiguration, synchronizer, blockProvider);
+ using var wallet = Wallet.CreateAndRegisterServices(network, bitcoinStore, keyManager, synchronizer, nodes, serviceConfiguration, synchronizer, blockProvider);
wallet.NewFilterProcessed += Common.Wallet_NewFilterProcessed;
Assert.Empty(wallet.Coins);

MODIFY
WalletWasabi.Tests/RegressionTests/WalletTests.cs
WalletWasabi.Tests/RegressionTests/WalletTests.cs
@@ -249,14 +249,11 @@ namespace WalletWasabi.Tests.RegressionTests
// 3. Create key manager service.
var keyManager = KeyManager.CreateNew(out _, password);
- // 4. Create wallet service.
- var workDir = Helpers.Common.GetWorkDir();
-
CachedBlockProvider blockProvider = new CachedBlockProvider(
new P2pBlockProvider(nodes, null, synchronizer, serviceConfiguration, network),
bitcoinStore.BlockRepository);
- using var wallet = Wallet.CreateAndRegisterServices(network, bitcoinStore, keyManager, synchronizer, nodes, workDir, serviceConfiguration, synchronizer, blockProvider);
+ using var wallet = Wallet.CreateAndRegisterServices(network, bitcoinStore, keyManager, synchronizer, nodes, serviceConfiguration, synchronizer, blockProvider);
wallet.NewFilterProcessed += Common.Wallet_NewFilterProcessed;
// Get some money, make it confirm.

MODIFY
WalletWasabi.Tests/UnitTests/WalletDirTests.cs
WalletWasabi.Tests/UnitTests/WalletDirTests.cs
+using NBitcoin;
using System;
using System.Collections.Generic;
using System.IO;
@@ -29,24 +30,45 @@ namespace WalletWasabi.Tests.UnitTests
var baseDir = Common.GetWorkDir();
(string walletsPath, string walletsBackupPath) = await CleanupWalletDirectoriesAsync(baseDir);
- new WalletDirectories(baseDir);
+ _ = new WalletDirectories(Network.Main, baseDir);
Assert.True(Directory.Exists(walletsPath));
Assert.True(Directory.Exists(walletsBackupPath));
// Testing what happens if the directories are already exist.
- new WalletDirectories(baseDir);
+ _ = new WalletDirectories(Network.Main, baseDir);
Assert.True(Directory.Exists(walletsPath));
Assert.True(Directory.Exists(walletsBackupPath));
}
+ [Fact]
+ public async Task TestPathsAsync()
+ {
+ var baseDir = Common.GetWorkDir();
+ _ = await CleanupWalletDirectoriesAsync(baseDir);
+
+ var mainWd = new WalletDirectories(Network.Main, baseDir);
+ Assert.Equal(Network.Main, mainWd.Network);
+ Assert.Equal(Path.Combine(baseDir, "Wallets"), mainWd.WalletsDir);
+ Assert.Equal(Path.Combine(baseDir, "WalletBackups"), mainWd.WalletsBackupDir);
+
+ var testWd = new WalletDirectories(Network.TestNet, baseDir);
+ Assert.Equal(Network.TestNet, testWd.Network);
+ Assert.Equal(Path.Combine(baseDir, "Wallets", "TestNet"), testWd.WalletsDir);
+ Assert.Equal(Path.Combine(baseDir, "WalletBackups", "TestNet"), testWd.WalletsBackupDir);
+
+ var regWd = new WalletDirectories(Network.RegTest, baseDir);
+ Assert.Equal(Network.RegTest, regWd.Network);
+ Assert.Equal(Path.Combine(baseDir, "Wallets", "RegTest"), regWd.WalletsDir);
+ Assert.Equal(Path.Combine(baseDir, "WalletBackups", "RegTest"), regWd.WalletsBackupDir);
+ }
+
[Fact]
public async Task CorrectWalletDirectoryNameAsync()
{
var baseDir = Common.GetWorkDir();
(string walletsPath, string walletsBackupPath) = await CleanupWalletDirectoriesAsync(baseDir);
- var walletDirectories = new WalletDirectories($" {baseDir} ");
- Assert.Equal(baseDir, walletDirectories.WorkDir);
+ var walletDirectories = new WalletDirectories(Network.Main, $" {baseDir} ");
Assert.Equal(walletsPath, walletDirectories.WalletsDir);
Assert.Equal(walletsBackupPath, walletDirectories.WalletsBackupDir);
}
@@ -57,7 +79,7 @@ namespace WalletWasabi.Tests.UnitTests
var baseDir = Common.GetWorkDir();
await CleanupWalletDirectoriesAsync(baseDir);
- var walletDirectories = new WalletDirectories(baseDir);
+ var walletDirectories = new WalletDirectories(Network.Main, baseDir);
string walletName = "FooWallet.json";
(string walletPath, string walletBackupPath) = walletDirectories.GetWalletFilePaths(walletName);
@@ -72,7 +94,7 @@ namespace WalletWasabi.Tests.UnitTests
var baseDir = Common.GetWorkDir();
await CleanupWalletDirectoriesAsync(baseDir);
- var walletDirectories = new WalletDirectories(baseDir);
+ var walletDirectories = new WalletDirectories(Network.Main, baseDir);
string walletName = "FooWallet";
string walletFileName = $"{walletName}.json";
@@ -88,7 +110,7 @@ namespace WalletWasabi.Tests.UnitTests
var baseDir = Common.GetWorkDir();
await CleanupWalletDirectoriesAsync(baseDir);
- var walletDirectories = new WalletDirectories(baseDir);
+ var walletDirectories = new WalletDirectories(Network.Main, baseDir);
var wallets = new List<string>();
var walletBackups = new List<string>();
@@ -117,7 +139,7 @@ namespace WalletWasabi.Tests.UnitTests
var baseDir = Common.GetWorkDir();
await CleanupWalletDirectoriesAsync(baseDir);
- var walletDirectories = new WalletDirectories(baseDir);
+ var walletDirectories = new WalletDirectories(Network.Main, baseDir);
var walletFile1 = Path.Combine(walletDirectories.WalletsDir, $"FooWallet1.json");
await File.Create(walletFile1).DisposeAsync();
@@ -142,7 +164,7 @@ namespace WalletWasabi.Tests.UnitTests
var baseDir = Common.GetWorkDir();
(string walletsPath, string walletsBackupPath) = await CleanupWalletDirectoriesAsync(baseDir);
- var walletDirectories = new WalletDirectories(baseDir);
+ var walletDirectories = new WalletDirectories(Network.Main, baseDir);
Assert.Empty(walletDirectories.EnumerateWalletFiles());
Directory.Delete(walletsBackupPath);
@@ -158,7 +180,7 @@ namespace WalletWasabi.Tests.UnitTests
{
var baseDir = Common.GetWorkDir();
await CleanupWalletDirectoriesAsync(baseDir);
- var walletDirectories = new WalletDirectories(baseDir);
+ var walletDirectories = new WalletDirectories(Network.Main, baseDir);
IoHelpers.CreateOrOverwriteFile(Path.Combine(walletDirectories.WalletsDir, "Random Wallet 3.json"));
Assert.Equal("Random Wallet", walletDirectories.GetNextWalletName());
@@ -186,7 +208,7 @@ namespace WalletWasabi.Tests.UnitTests
}
[Fact]
- public async Task GetFriendlyNameTestAsync()
+ public void GetFriendlyNameTest()
{
Assert.Equal("Hardware Wallet", HardwareWalletModels.Unknown.FriendlyName());
Assert.Equal("Coldcard", HardwareWalletModels.Coldcard.FriendlyName());

MODIFY
WalletWasabi/Wallets/Wallet.cs
WalletWasabi/Wallets/Wallet.cs
@@ -29,17 +29,15 @@ namespace WalletWasabi.Wallets
{
private WalletState _state;
- public Wallet(string dataDir, Network network, string filePath) : this(dataDir, network, KeyManager.FromFile(filePath))
+ public Wallet(Network network, string filePath) : this(network, KeyManager.FromFile(filePath))
{
}
- public Wallet(string dataDir, Network network, KeyManager keyManager)
+ public Wallet(Network network, KeyManager keyManager)
{
- Guard.NotNullOrEmptyOrWhitespace(nameof(dataDir), dataDir);
Network = Guard.NotNull(nameof(network), network);
KeyManager = Guard.NotNull(nameof(keyManager), keyManager);
- RuntimeParams.SetDataDir(dataDir);
HandleFiltersLock = new AsyncLock();
KeyManager.AssertCleanKeysIndexed();
@@ -488,9 +486,9 @@ namespace WalletWasabi.Wallets
State = WalletState.WaitingForInit;
}
- public static Wallet CreateAndRegisterServices(Network network, BitcoinStore bitcoinStore, KeyManager keyManager, WasabiSynchronizer synchronizer, NodesGroup nodes, string dataDir, ServiceConfiguration serviceConfiguration, IFeeProvider feeProvider, IBlockProvider blockProvider)
+ public static Wallet CreateAndRegisterServices(Network network, BitcoinStore bitcoinStore, KeyManager keyManager, WasabiSynchronizer synchronizer, NodesGroup nodes, ServiceConfiguration serviceConfiguration, IFeeProvider feeProvider, IBlockProvider blockProvider)
{
- var wallet = new Wallet(dataDir, network, keyManager);
+ var wallet = new Wallet(network, keyManager);
wallet.RegisterServices(bitcoinStore, synchronizer, nodes, serviceConfiguration, feeProvider, blockProvider);
return wallet;
}

MODIFY
WalletWasabi/Wallets/WalletDirectories.cs
WalletWasabi/Wallets/WalletDirectories.cs
+using NBitcoin;
using System;
using System.Collections.Generic;
using System.IO;
@@ -12,17 +13,29 @@ namespace WalletWasabi.Wallets
public const string WalletsBackupDirName = "WalletBackups";
private const string WalletFileExtension = "json";
- public WalletDirectories(string workDir)
+ public WalletDirectories(Network network, string workDir)
{
- WorkDir = Guard.NotNullOrEmptyOrWhitespace(nameof(workDir), workDir, true);
+ Network = network;
+ var correctedWorkDir = Guard.NotNullOrEmptyOrWhitespace(nameof(workDir), workDir, true);
+ if (network.NetworkType == NetworkType.Mainnet)
+ {
+ WalletsDir = Path.Combine(correctedWorkDir, WalletsDirName);
+ WalletsBackupDir = Path.Combine(correctedWorkDir, WalletsBackupDirName);
+ }
+ else
+ {
+ WalletsDir = Path.Combine(correctedWorkDir, WalletsDirName, network.ToString());
+ WalletsBackupDir = Path.Combine(correctedWorkDir, WalletsBackupDirName, network.ToString());
+ }
Directory.CreateDirectory(WalletsDir);
Directory.CreateDirectory(WalletsBackupDir);
}
- public string WorkDir { get; }
- public string WalletsDir => Path.Combine(WorkDir, WalletsDirName);
- public string WalletsBackupDir => Path.Combine(WorkDir, WalletsBackupDirName);
+ public string WalletsDir { get; }
+ public string WalletsBackupDir { get; }
+
+ public Network Network { get; }
public (string walletFilePath, string walletBackupFilePath) GetWalletFilePaths(string walletName)
{
@@ -39,7 +52,7 @@ namespace WalletWasabi.Wallets
var walletsDirExists = walletsDirInfo.Exists;
var searchPattern = $"*.{WalletFileExtension}";
var searchOption = SearchOption.TopDirectoryOnly;
- IEnumerable<FileInfo> result = null;
+ IEnumerable<FileInfo> result;
if (includeBackupDir)
{

MODIFY
WalletWasabi/Wallets/WalletManager.cs
WalletWasabi/Wallets/WalletManager.cs
@@ -198,7 +198,7 @@ namespace WalletWasabi.Wallets
public Wallet AddWallet(KeyManager keyManager)
{
- Wallet wallet = new Wallet(WalletDirectories.WorkDir, Network, keyManager);
+ Wallet wallet = new Wallet(Network, keyManager);
AddWallet(wallet);
return wallet;
}
@@ -209,7 +209,7 @@ namespace WalletWasabi.Wallets
Wallet wallet;
try
{
- wallet = new Wallet(WalletDirectories.WorkDir, Network, walletFullPath);
+ wallet = new Wallet(Network, walletFullPath);
}
catch (Exception ex)
{
@@ -236,7 +236,7 @@ namespace WalletWasabi.Wallets
}
File.Copy(walletBackupFullPath, walletFullPath);
- wallet = new Wallet(WalletDirectories.WorkDir, Network, walletFullPath);
+ wallet = new Wallet(Network, walletFullPath);
}
AddWallet(wallet);

Networkify wallets