Slim down ITorHttpClient.
MODIFY
WalletWasabi.Tests/UnitTests/Transactions/PayjoinTests.cs
WalletWasabi.Tests/UnitTests/Transactions/PayjoinTests.cs
@@ -16,6 +16,7 @@ using System.Net;
using System.Text;
using WalletWasabi.Models;
using System.Collections.Specialized;
+using WalletWasabi.Tor.Http;
namespace WalletWasabi.Tests.UnitTests.Transactions
{
@@ -86,7 +87,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
{
OnSendAsync = PayjoinServerOk(psbt => psbt)
};
- var payjoinClient = new PayjoinClient(httpClient);
+ var payjoinClient = NewPayjoinClient(httpClient);
var transactionFactory = Common.CreateTransactionFactory(new[]
{
("Pablo", 0, 0.1m, confirmed: true, anonymitySet: 1)
@@ -133,7 +134,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
return newPsbt;
})
};
- var payjoinClient = new PayjoinClient(httpClient);
+ var payjoinClient = NewPayjoinClient(httpClient);
var transactionFactory = Common.CreateTransactionFactory(new[]
{
("Pablo", 0, 0.1m, confirmed: true, anonymitySet: 1)
@@ -195,7 +196,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
};
var transactionFactory = Common.CreateTransactionFactory(walletCoins);
- var tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), new PayjoinClient(httpClient));
+ var tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), NewPayjoinClient(httpClient));
Assert.Single(tx.Transaction.Transaction.Inputs);
///////
@@ -219,7 +220,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
})
};
- tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), new PayjoinClient(httpClient));
+ tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), NewPayjoinClient(httpClient));
Assert.Single(tx.Transaction.Transaction.Inputs);
}
@@ -242,7 +243,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
};
var transactionFactory = Common.CreateTransactionFactory(walletCoins);
- var tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), new PayjoinClient(httpClient));
+ var tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), NewPayjoinClient(httpClient));
Assert.Single(tx.Transaction.Transaction.Inputs);
////////
@@ -257,7 +258,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
})
};
- tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), new PayjoinClient(httpClient));
+ tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), NewPayjoinClient(httpClient));
Assert.Single(tx.Transaction.Transaction.Inputs);
////////
@@ -272,7 +273,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
})
};
- tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), new PayjoinClient(httpClient));
+ tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), NewPayjoinClient(httpClient));
Assert.Single(tx.Transaction.Transaction.Inputs);
////////
@@ -287,7 +288,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
})
};
- tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), new PayjoinClient(httpClient));
+ tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), NewPayjoinClient(httpClient));
Assert.Single(tx.Transaction.Transaction.Inputs);
////////
@@ -303,7 +304,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
})
};
- tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), new PayjoinClient(httpClient));
+ tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), NewPayjoinClient(httpClient));
Assert.Single(tx.Transaction.Transaction.Inputs);
////////
@@ -318,7 +319,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
})
};
- tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), new PayjoinClient(httpClient));
+ tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), NewPayjoinClient(httpClient));
Assert.Single(tx.Transaction.Transaction.Inputs);
////////
@@ -333,7 +334,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
})
};
- tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), new PayjoinClient(httpClient));
+ tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), NewPayjoinClient(httpClient));
Assert.Single(tx.Transaction.Transaction.Inputs);
////////
@@ -348,7 +349,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
})
};
- tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), new PayjoinClient(httpClient));
+ tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), NewPayjoinClient(httpClient));
Assert.Single(tx.Transaction.Transaction.Inputs);
////////
@@ -363,7 +364,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
})
};
- tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), new PayjoinClient(httpClient));
+ tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), NewPayjoinClient(httpClient));
Assert.Single(tx.Transaction.Transaction.Inputs);
}
@@ -389,7 +390,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
};
var transactionFactory = Common.CreateTransactionFactory(walletCoins);
- var tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), new PayjoinClient(httpClient));
+ var tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), NewPayjoinClient(httpClient));
Assert.Single(tx.Transaction.Transaction.Inputs);
}
@@ -409,8 +410,13 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
};
var transactionFactory = Common.CreateTransactionFactory(walletCoins);
- var tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), new PayjoinClient(httpClient));
+ var tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), transactionFactory.Coins.Select(x => x.OutPoint), NewPayjoinClient(httpClient));
Assert.Single(tx.Transaction.Transaction.Inputs);
}
+
+ private static PayjoinClient NewPayjoinClient(MockTorHttpClient client)
+ {
+ return new PayjoinClient(client.DestinationUri, client);
+ }
}
}

MODIFY
WalletWasabi/Tor/Http/Interfaces/ITorHttpClient.cs
WalletWasabi/Tor/Http/Interfaces/ITorHttpClient.cs
using System;
-using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
@@ -8,10 +7,6 @@ namespace WalletWasabi.Tor.Http.Interfaces
{
public interface ITorHttpClient : IHttpClient
{
- Uri DestinationUri { get; }
- Func<Uri> DestinationUriAction { get; }
- EndPoint TorSocks5EndPoint { get; }
-
bool IsTorUsed { get; }
Task<HttpResponseMessage> SendAsync(HttpMethod method, string relativeUri, HttpContent? content = null, CancellationToken cancel = default);

MODIFY
WalletWasabi/Tor/Http/TorHttpClient.cs
WalletWasabi/Tor/Http/TorHttpClient.cs
@@ -35,7 +35,7 @@ namespace WalletWasabi.Tor.Http
DestinationUriAction = Guard.NotNull(nameof(baseUriAction), baseUriAction);
// Connecting to loopback's URIs cannot be done via Tor.
- TorSocks5EndPoint = DestinationUri.IsLoopback ? null : torSocks5EndPoint;
+ TorSocks5EndPoint = DestinationUriAction().IsLoopback ? null : torSocks5EndPoint;
TorSocks5Client = null;
IsolateStream = isolateStream;
}
@@ -58,7 +58,6 @@ namespace WalletWasabi.Tor.Http
public static Exception? LatestTorException { get; private set; } = null;
- public Uri DestinationUri => DestinationUriAction();
public Func<Uri> DestinationUriAction { get; }
public EndPoint? TorSocks5EndPoint { get; private set; }
public bool IsTorUsed => TorSocks5EndPoint is { };
@@ -81,7 +80,7 @@ namespace WalletWasabi.Tor.Http
{
Guard.NotNull(nameof(method), method);
relativeUri = Guard.NotNull(nameof(relativeUri), relativeUri);
- var requestUri = new Uri(DestinationUri, relativeUri);
+ var requestUri = new Uri(DestinationUriAction(), relativeUri);
using var request = new HttpRequestMessage(method, requestUri);
request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));

MODIFY
WalletWasabi/WebClients/PayJoin/PayjoinClient.cs
WalletWasabi/WebClients/PayJoin/PayjoinClient.cs
@@ -29,9 +29,9 @@ namespace WalletWasabi.WebClients.PayJoin
}
// For testing only
- internal PayjoinClient(ITorHttpClient httpClient)
+ internal PayjoinClient(Uri paymentUrl, ITorHttpClient httpClient)
{
- PaymentUrl = httpClient.DestinationUri;
+ PaymentUrl = paymentUrl;
TorHttpClient = Guard.NotNull(nameof(httpClient), httpClient);
}

Slim down ITorHttpClient.