Unify getbinaries method.
MODIFY
WalletWasabi.Tests/NodeBuilding/NodeBuilder.cs
WalletWasabi.Tests/NodeBuilding/NodeBuilder.cs
@@ -12,6 +12,7 @@ using System.Net.Http;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
+using WalletWasabi.Helpers;
using WalletWasabi.Logging;
using WalletWasabi.Tests.XunitConfiguration;
@@ -19,18 +20,12 @@ namespace WalletWasabi.Tests.NodeBuilding
{
public class NodeBuilder : IDisposable
{
- public static readonly AsyncLock Lock = new AsyncLock();
public static string WorkingDirectory { get; private set; }
- public static async Task<NodeBuilder> CreateAsync([CallerMemberName]string caller = null, string version = "0.18.1")
- {
- using (await Lock.LockAsync())
+ public static NodeBuilder Create([CallerMemberName]string caller = null)
{
WorkingDirectory = Path.Combine(Global.Instance.DataDir, caller);
- version ??= "0.18.1";
- var path = await EnsureDownloadedAsync(version);
- return new NodeBuilder(WorkingDirectory, path);
- }
+ return new NodeBuilder(WorkingDirectory, EnvironmentHelpers.GetBinaryPath("BitcoinCore", "bitcoind"));
}
private static async Task TryRemoveWorkingDirectoryAsync()
@@ -48,70 +43,6 @@ namespace WalletWasabi.Tests.NodeBuilding
}
}
- private static async Task<string> EnsureDownloadedAsync(string version)
- {
- //is a file
- if (version.Length >= 2 && version[1] == ':')
- {
- return version;
- }
-
- string zip;
- string bitcoind;
- string bitcoindFolderName = $"bitcoin-{version}";
-
- // Remove old bitcoind folders.
- IEnumerable<string> existingBitcoindFolderPaths = Directory.EnumerateDirectories(Global.Instance.DataDir, "bitcoin-*", SearchOption.TopDirectoryOnly);
- foreach (string dirPath in existingBitcoindFolderPaths)
- {
- string dirName = Path.GetFileName(dirPath);
- if (bitcoindFolderName != dirName)
- {
- await IoHelpers.DeleteRecursivelyWithMagicDustAsync(dirPath);
- }
- }
-
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- {
- bitcoind = Path.Combine(Global.Instance.DataDir, bitcoindFolderName, "bin", "bitcoind.exe");
- if (File.Exists(bitcoind))
- {
- return bitcoind;
- }
-
- zip = Path.Combine(Global.Instance.DataDir, $"bitcoin-{version}-win64.zip");
- string url = string.Format("https://bitcoincore.org/bin/bitcoin-core-{0}/" + Path.GetFileName(zip), version);
- using var client = new HttpClient();
- client.Timeout = TimeSpan.FromMinutes(10.0);
- var data = await client.GetByteArrayAsync(url);
- await File.WriteAllBytesAsync(zip, data);
- ZipFile.ExtractToDirectory(zip, new FileInfo(zip).Directory.FullName);
- }
- else
- {
- bitcoind = Path.Combine(Global.Instance.DataDir, bitcoindFolderName, "bin", "bitcoind");
- if (File.Exists(bitcoind))
- {
- return bitcoind;
- }
-
- zip = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
- ? Path.Combine(Global.Instance.DataDir, $"bitcoin-{version}-x86_64-linux-gnu.tar.gz")
- : Path.Combine(Global.Instance.DataDir, $"bitcoin-{version}-osx64.tar.gz");
-
- string url = string.Format("https://bitcoincore.org/bin/bitcoin-core-{0}/" + Path.GetFileName(zip), version);
- using var client = new HttpClient();
- client.Timeout = TimeSpan.FromMinutes(10.0);
- var data = await client.GetByteArrayAsync(url);
- await File.WriteAllBytesAsync(zip, data);
-
- using var process = Process.Start("tar", "-zxvf " + zip + " -C " + Global.Instance.DataDir);
- process.WaitForExit();
- }
- File.Delete(zip);
- return bitcoind;
- }
-
private int Last { get; set; }
private string Root { get; }

DELETE
WalletWasabi.Tests/UnitTests/BitcoinCore/ProcessTests.cs
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Threading.Tasks;
-using Xunit;
-
-namespace WalletWasabi.Tests.UnitTests.BitcoinD
-{
- public class ProcessTests
- {
- [Fact]
- public async Task ProcessStartsAndStopsAsync()
- {
- }
- }
-}

MODIFY
WalletWasabi.Tests/XunitConfiguration/RegTestFixture.cs
WalletWasabi.Tests/XunitConfiguration/RegTestFixture.cs
@@ -27,7 +27,7 @@ namespace WalletWasabi.Tests.XunitConfiguration
public RegTestFixture()
{
- BackendNodeBuilder = NodeBuilder.CreateAsync(EnvironmentHelpers.GetMethodName()).GetAwaiter().GetResult();
+ BackendNodeBuilder = NodeBuilder.Create(EnvironmentHelpers.GetMethodName());
BackendNodeBuilder.CreateNodeAsync().GetAwaiter().GetResult();
BackendNodeBuilder.StartAllAsync().GetAwaiter().GetResult();
BackendRegTestNode = BackendNodeBuilder.Nodes[0];

RENAME
WalletWasabi/BitcoinCore/Binaries/bitcoincore-lin64/bitcoind
WalletWasabi/BitcoinCore/Binaries/bitcoind-lin64/bitcoind
RENAME
WalletWasabi/BitcoinCore/Binaries/bitcoincore-osx64/bitcoind
WalletWasabi/BitcoinCore/Binaries/bitcoind-osx64/bitcoind
RENAME
WalletWasabi/BitcoinCore/Binaries/bitcoincore-win64/bitcoind.exe
WalletWasabi/BitcoinCore/Binaries/bitcoind-win64/bitcoind.exe
MODIFY
WalletWasabi/Helpers/EnvironmentHelpers.cs
WalletWasabi/Helpers/EnvironmentHelpers.cs
@@ -208,5 +208,34 @@ namespace WalletWasabi.Helpers
return fullBaseDirectory;
}
+
+ /// <summary>
+ /// Acessibility of binaries must follow the convention: {binariesContainingFolderRelativePath}/Binaries/{binaryNameWithoutExtension}-{os}64/binaryNameWithoutExtension(.exe)
+ /// </summary>
+ public static string GetBinaryPath(string binariesContainingFolderRelativePath, string binaryNameWithoutExtension)
+ {
+ var fullBaseDirectory = GetFullBaseDirectory();
+
+ string commonPartialPath = Path.Combine(fullBaseDirectory, binariesContainingFolderRelativePath, "Binaries");
+ string path;
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ {
+ path = Path.Combine(commonPartialPath, $"{binaryNameWithoutExtension}-win64", $"{binaryNameWithoutExtension}.exe");
+ }
+ else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+ {
+ path = Path.Combine(commonPartialPath, $"{binaryNameWithoutExtension}-lin64", binaryNameWithoutExtension);
+ }
+ else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+ {
+ path = Path.Combine(commonPartialPath, $"{binaryNameWithoutExtension}-osx64", binaryNameWithoutExtension);
+ }
+ else
+ {
+ throw new NotSupportedException("Operating system is not supported.");
+ }
+
+ return path;
+ }
}
}

MODIFY
WalletWasabi/Hwi/ProcessBridge/HwiProcessBridge.cs
WalletWasabi/Hwi/ProcessBridge/HwiProcessBridge.cs
@@ -18,7 +18,7 @@ namespace WalletWasabi.Hwi.ProcessBridge
{
string responseString;
int exitCode;
- string hwiPath = GetHwiPath();
+ string hwiPath = EnvironmentHelpers.GetBinaryPath("Hwi", "hwi");
var fileName = hwiPath;
var finalArguments = arguments;
@@ -85,31 +85,5 @@ namespace WalletWasabi.Hwi.ProcessBridge
return (responseString, exitCode);
}
-
- private string GetHwiPath()
- {
- var fullBaseDirectory = EnvironmentHelpers.GetFullBaseDirectory();
-
- string commonPartialPath = Path.Combine(fullBaseDirectory, "Hwi", "Binaries");
- string path;
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- {
- path = Path.Combine(commonPartialPath, "hwi-win64", "hwi.exe");
- }
- else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
- {
- path = Path.Combine(commonPartialPath, "hwi-lin64", "hwi");
- }
- else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
- {
- path = Path.Combine(commonPartialPath, "hwi-osx64", "hwi");
- }
- else
- {
- throw new NotSupportedException("Operating system is not supported.");
- }
-
- return path;
- }
}
}

MODIFY
WalletWasabi/WalletWasabi.csproj
WalletWasabi/WalletWasabi.csproj
</ItemGroup>
<ItemGroup>
- <None Update="BitcoinCore\Binaries\bitcoincore-lin64\bitcoind">
+ <None Update="BitcoinCore\Binaries\bitcoind-lin64\bitcoind">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
- <None Update="BitcoinCore\Binaries\bitcoincore-osx64\bitcoind">
+ <None Update="BitcoinCore\Binaries\bitcoind-osx64\bitcoind">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
- <None Update="BitcoinCore\Binaries\bitcoincore-win64\bitcoind.exe">
+ <None Update="BitcoinCore\Binaries\bitcoind-win64\bitcoind.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Hwi\Binaries\hwi-lin64\hwi">

Unify getbinaries method.