Fix potential NREs in WasabiClient.
MODIFY
WalletWasabi.Tests/RegressionTests/Common.cs
WalletWasabi.Tests/RegressionTests/Common.cs
@@ -53,7 +53,7 @@ namespace WalletWasabi.Tests.RegressionTests
while (true)
{
using var client = new WasabiClient(new Uri(regTestFixture.BackendEndPoint), torSocks5EndPoint: null);
- FiltersResponse filtersResponse = await client.GetFiltersAsync(firstHash, 1000);
+ FiltersResponse? filtersResponse = await client.GetFiltersAsync(firstHash, 1000);
Assert.NotNull(filtersResponse);
var filterCount = filtersResponse.Filters.Count();

MODIFY
WalletWasabi/WebClients/Wasabi/WasabiClient.cs
WalletWasabi/WebClients/Wasabi/WasabiClient.cs
@@ -56,7 +56,12 @@ namespace WalletWasabi.WebClients.Wasabi
relativeUri = $"{relativeUri}&estimateSmartFeeMode={estimateMode}";
}
- using var response = await TorClient.SendAndRetryAsync(HttpMethod.Get, relativeUri, token: cancel).ConfigureAwait(false);
+ using HttpResponseMessage? response = await TorClient.SendAndRetryAsync(HttpMethod.Get, relativeUri, token: cancel).ConfigureAwait(false);
+
+ if (response is null)
+ {
+ throw new HttpRequestException("No HTTP response received.");
+ }
if (response.StatusCode != HttpStatusCode.OK)
{
@@ -65,6 +70,7 @@ namespace WalletWasabi.WebClients.Wasabi
using HttpContent content = response.Content;
var ret = await content.ReadAsJsonAsync<SynchronizeResponse>().ConfigureAwait(false);
+
return ret;
}
@@ -75,17 +81,23 @@ namespace WalletWasabi.WebClients.Wasabi
/// <remarks>
/// Throws OperationCancelledException if <paramref name="cancel"/> is set.
/// </remarks>
- public async Task<FiltersResponse> GetFiltersAsync(uint256 bestKnownBlockHash, int count, CancellationToken cancel = default)
+ public async Task<FiltersResponse?> GetFiltersAsync(uint256 bestKnownBlockHash, int count, CancellationToken cancel = default)
{
- using var response = await TorClient.SendAndRetryAsync(
+ using HttpResponseMessage? response = await TorClient.SendAndRetryAsync(
HttpMethod.Get,
$"/api/v{ApiVersion}/btc/blockchain/filters?bestKnownBlockHash={bestKnownBlockHash}&count={count}",
token: cancel).ConfigureAwait(false);
+ if (response is null)
+ {
+ throw new HttpRequestException("No HTTP response received.");
+ }
+
if (response.StatusCode == HttpStatusCode.NoContent)
{
return null;
}
+
if (response.StatusCode != HttpStatusCode.OK)
{
await response.ThrowRequestExceptionFromContentAsync().ConfigureAwait(false);
@@ -93,6 +105,7 @@ namespace WalletWasabi.WebClients.Wasabi
using HttpContent content = response.Content;
var ret = await content.ReadAsJsonAsync<FiltersResponse>().ConfigureAwait(false);
+
return ret;
}
@@ -111,11 +124,16 @@ namespace WalletWasabi.WebClients.Wasabi
{
cancel.ThrowIfCancellationRequested();
- using var response = await TorClient.SendAndRetryAsync(
+ using HttpResponseMessage? response = await TorClient.SendAndRetryAsync(
HttpMethod.Get,
$"/api/v{ApiVersion}/btc/blockchain/transaction-hexes?&transactionIds={string.Join("&transactionIds=", chunk.Select(x => x.ToString()))}",
token: cancel).ConfigureAwait(false);
+ if (response is null)
+ {
+ throw new HttpRequestException("No HTTP response received.");
+ }
+
if (response.StatusCode != HttpStatusCode.OK)
{
await response.ThrowRequestExceptionFromContentAsync().ConfigureAwait(false);
@@ -150,7 +168,8 @@ namespace WalletWasabi.WebClients.Wasabi
public async Task BroadcastAsync(string hex)
{
using var content = new StringContent($"'{hex}'", Encoding.UTF8, "application/json");
- using var response = await TorClient.SendAsync(HttpMethod.Post, $"/api/v{ApiVersion}/btc/blockchain/broadcast", content).ConfigureAwait(false);
+ using HttpResponseMessage response = await TorClient.SendAsync(HttpMethod.Post, $"/api/v{ApiVersion}/btc/blockchain/broadcast", content).ConfigureAwait(false);
+
if (response.StatusCode != HttpStatusCode.OK)
{
await response.ThrowRequestExceptionFromContentAsync().ConfigureAwait(false);
@@ -169,11 +188,16 @@ namespace WalletWasabi.WebClients.Wasabi
public async Task<IEnumerable<uint256>> GetMempoolHashesAsync(CancellationToken cancel = default)
{
- using var response = await TorClient.SendAndRetryAsync(
+ using HttpResponseMessage? response = await TorClient.SendAndRetryAsync(
HttpMethod.Get,
$"/api/v{ApiVersion}/btc/blockchain/mempool-hashes",
token: cancel).ConfigureAwait(false);
+ if (response is null)
+ {
+ throw new HttpRequestException("No HTTP response received.");
+ }
+
if (response.StatusCode != HttpStatusCode.OK)
{
await response.ThrowRequestExceptionFromContentAsync().ConfigureAwait(false);
@@ -182,6 +206,7 @@ namespace WalletWasabi.WebClients.Wasabi
using HttpContent content = response.Content;
var strings = await content.ReadAsJsonAsync<IEnumerable<string>>().ConfigureAwait(false);
var ret = strings.Select(x => new uint256(x));
+
return ret;
}
@@ -191,11 +216,16 @@ namespace WalletWasabi.WebClients.Wasabi
/// <param name="compactness">1 to 64</param>
public async Task<ISet<string>> GetMempoolHashesAsync(int compactness, CancellationToken cancel = default)
{
- using var response = await TorClient.SendAndRetryAsync(
+ using HttpResponseMessage? response = await TorClient.SendAndRetryAsync(
HttpMethod.Get,
$"/api/v{ApiVersion}/btc/blockchain/mempool-hashes?compactness={compactness}",
token: cancel).ConfigureAwait(false);
+ if (response is null)
+ {
+ throw new HttpRequestException("No HTTP response received.");
+ }
+
if (response.StatusCode != HttpStatusCode.OK)
{
await response.ThrowRequestExceptionFromContentAsync().ConfigureAwait(false);
@@ -203,6 +233,7 @@ namespace WalletWasabi.WebClients.Wasabi
using HttpContent content = response.Content;
var strings = await content.ReadAsJsonAsync<ISet<string>>().ConfigureAwait(false);
+
return strings;
}
@@ -212,7 +243,12 @@ namespace WalletWasabi.WebClients.Wasabi
public async Task<IEnumerable<ExchangeRate>> GetExchangeRatesAsync()
{
- using var response = await TorClient.SendAndRetryAsync(HttpMethod.Get, $"/api/v{ApiVersion}/btc/offchain/exchange-rates").ConfigureAwait(false);
+ using HttpResponseMessage? response = await TorClient.SendAndRetryAsync(HttpMethod.Get, $"/api/v{ApiVersion}/btc/offchain/exchange-rates").ConfigureAwait(false);
+
+ if (response is null)
+ {
+ throw new HttpRequestException("No HTTP response received.");
+ }
if (response.StatusCode != HttpStatusCode.OK)
{
@@ -221,6 +257,7 @@ namespace WalletWasabi.WebClients.Wasabi
using HttpContent content = response.Content;
var ret = await content.ReadAsJsonAsync<IEnumerable<ExchangeRate>>().ConfigureAwait(false);
+
return ret;
}
@@ -230,7 +267,12 @@ namespace WalletWasabi.WebClients.Wasabi
public async Task<(Version ClientVersion, ushort BackendMajorVersion, Version LegalDocumentsVersion)> GetVersionsAsync(CancellationToken cancel)
{
- using var response = await TorClient.SendAndRetryAsync(HttpMethod.Get, "/api/software/versions", token: cancel).ConfigureAwait(false);
+ using HttpResponseMessage? response = await TorClient.SendAndRetryAsync(HttpMethod.Get, "/api/software/versions", token: cancel).ConfigureAwait(false);
+
+ if (response is null)
+ {
+ throw new HttpRequestException("No HTTP response received.");
+ }
if (response.StatusCode != HttpStatusCode.OK)
{
@@ -265,19 +307,25 @@ namespace WalletWasabi.WebClients.Wasabi
public async Task<string> GetLegalDocumentsAsync(CancellationToken cancel)
{
- using var response = await TorClient.SendAndRetryAsync(
+ using HttpResponseMessage? response = await TorClient.SendAndRetryAsync(
HttpMethod.Get,
$"/api/v{ApiVersion}/wasabi/legaldocuments",
token: cancel).ConfigureAwait(false);
+ if (response is null)
+ {
+ throw new HttpRequestException("No HTTP response received.");
+ }
+
if (response.StatusCode != HttpStatusCode.OK)
{
await response.ThrowRequestExceptionFromContentAsync().ConfigureAwait(false);
}
using HttpContent content = response.Content;
- var ret = await content.ReadAsStringAsync().ConfigureAwait(false);
- return ret;
+ string result = await content.ReadAsStringAsync().ConfigureAwait(false);
+
+ return result;
}
#endregion wasabi

Fix potential NREs in WasabiClient.