Remove ProcessInvoker class and put the implementation to HwiProcessBridge which is the only place that uses the code.
MODIFY
WalletWasabi.Tests/UnitTests/Hwi/DefaultResponseTests.cs
WalletWasabi.Tests/UnitTests/Hwi/DefaultResponseTests.cs
@@ -9,7 +9,6 @@ using WalletWasabi.Hwi;
using WalletWasabi.Hwi.Models;
using WalletWasabi.Hwi.Parsers;
using WalletWasabi.Hwi.ProcessBridge;
-using WalletWasabi.Microservices;
using Xunit;
using WalletWasabi.Helpers;
@@ -123,7 +122,7 @@ namespace WalletWasabi.Tests.UnitTests.Hwi
[Fact]
public async Task OpenConsoleDoesntThrowAsync()
{
- var pb = new HwiProcessBridge(new ProcessInvoker());
+ HwiProcessBridge pb = new();
using var cts = new CancellationTokenSource(ReasonableRequestTimeout);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
@@ -209,7 +208,7 @@ namespace WalletWasabi.Tests.UnitTests.Hwi
{
using var cts = new CancellationTokenSource(ReasonableRequestTimeout);
- var pb = new HwiProcessBridge(new ProcessInvoker());
+ HwiProcessBridge pb = new();
// Start HWI with "version" argument and test that we get non-empty response.
(string response, int exitCode) result = await pb.SendCommandAsync("--version", openConsole: false, cts.Token);
@@ -228,7 +227,7 @@ namespace WalletWasabi.Tests.UnitTests.Hwi
{
using var cts = new CancellationTokenSource(ReasonableRequestTimeout);
- var processBridge = new HwiProcessBridge(new ProcessInvoker());
+ HwiProcessBridge processBridge = new();
(string response, int exitCode) result = await processBridge.SendCommandAsync("--help", openConsole: false, cts.Token);
Assert.Equal(0, result.exitCode);

MODIFY
WalletWasabi/Hwi/HwiClient.cs
WalletWasabi/Hwi/HwiClient.cs
@@ -21,7 +21,7 @@ namespace WalletWasabi.Hwi
public HwiClient(Network network, IHwiProcessInvoker? bridge = null)
{
Network = Guard.NotNull(nameof(network), network);
- Bridge = bridge ?? new HwiProcessBridge(new ProcessInvoker());
+ Bridge = bridge ?? new HwiProcessBridge();
}
#endregion ConstructorsAndInitializers

MODIFY
WalletWasabi/Hwi/ProcessBridge/HwiProcessBridge.cs
WalletWasabi/Hwi/ProcessBridge/HwiProcessBridge.cs
@@ -9,20 +9,18 @@ namespace WalletWasabi.Hwi.ProcessBridge
{
public class HwiProcessBridge : IHwiProcessInvoker
{
- public HwiProcessBridge(ProcessInvoker processInvoker)
+ public HwiProcessBridge()
{
ProcessPath = MicroserviceHelpers.GetBinaryPath("hwi");
- ProcessInvoker = processInvoker;
}
private string ProcessPath { get; }
- private ProcessInvoker ProcessInvoker { get; }
public async Task<(string response, int exitCode)> SendCommandAsync(string arguments, bool openConsole, CancellationToken cancel, Action<StreamWriter>? standardInputWriter = null)
{
ProcessStartInfo startInfo = ProcessStartInfoFactory.Make(ProcessPath, arguments, openConsole);
- (string rawResponse, int exitCode) = await ProcessInvoker.SendCommandAsync(startInfo, cancel, standardInputWriter).ConfigureAwait(false);
+ (string rawResponse, int exitCode) = await SendCommandAsync(startInfo, cancel, standardInputWriter).ConfigureAwait(false);
string response;
@@ -39,5 +37,33 @@ namespace WalletWasabi.Hwi.ProcessBridge
return (response, exitCode);
}
+
+ private async Task<(string response, int exitCode)> SendCommandAsync(ProcessStartInfo startInfo, CancellationToken token, Action<StreamWriter>? standardInputWriter = null)
+ {
+ using var processAsync = new ProcessAsync(startInfo);
+
+ if (standardInputWriter is { })
+ {
+ processAsync.StartInfo.RedirectStandardInput = true;
+ }
+
+ processAsync.Start();
+
+ if (standardInputWriter is { })
+ {
+ standardInputWriter(processAsync.StandardInput);
+ processAsync.StandardInput.Close();
+ }
+
+ Task<string> readPipeTask = processAsync.StartInfo.UseShellExecute
+ ? Task.FromResult(string.Empty)
+ : processAsync.StandardOutput.ReadToEndAsync();
+
+ await processAsync.WaitForExitAsync(token).ConfigureAwait(false);
+
+ string output = await readPipeTask.ConfigureAwait(false);
+
+ return (output, exitCode: processAsync.ExitCode);
+ }
}
}

DELETE
WalletWasabi/Microservices/ProcessInvoker.cs
-using System;
-using System.Diagnostics;
-using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace WalletWasabi.Microservices
-{
- public class ProcessInvoker
- {
- public async Task<(string response, int exitCode)> SendCommandAsync(ProcessStartInfo startInfo, CancellationToken token, Action<StreamWriter>? standardInputWriter = null)
- {
- using var processAsync = new ProcessAsync(startInfo);
-
- if (standardInputWriter is { })
- {
- processAsync.StartInfo.RedirectStandardInput = true;
- }
-
- processAsync.Start();
-
- if (standardInputWriter is { })
- {
- standardInputWriter(processAsync.StandardInput);
- processAsync.StandardInput.Close();
- }
-
- Task<string> readPipeTask = processAsync.StartInfo.UseShellExecute
- ? Task.FromResult(string.Empty)
- : processAsync.StandardOutput.ReadToEndAsync();
-
- await processAsync.WaitForExitAsync(token).ConfigureAwait(false);
-
- string output = await readPipeTask.ConfigureAwait(false);
-
- return (output, exitCode: processAsync.ExitCode);
- }
- }
-}

Remove ProcessInvoker class and put the implementation to HwiProcessBridge which is the only place that uses the code.