Add expected statuscode to SendAndRetry
MODIFY
MagicalCryptoWallet/Extensions/TorHttpClientExtensions.cs
MagicalCryptoWallet/Extensions/TorHttpClientExtensions.cs
@@ -6,18 +6,17 @@ using MagicalCryptoWallet.TorSocks5;
public static class TorHttpClientExtensions
{
- public static async Task<HttpResponseMessage> SendAndRetryAsync(this TorHttpClient client, HttpMethod method, string relativeUri, int retry = 2, HttpContent content = null)
+ public static async Task<HttpResponseMessage> SendAndRetryAsync(this TorHttpClient client, HttpMethod method, HttpStatusCode expectedCode, string relativeUri, int retry = 2, HttpContent content = null)
{
HttpResponseMessage response = null;
while (retry-- > 0)
{
response = await client.SendAsync(method, relativeUri, content);
- if(response.StatusCode == HttpStatusCode.OK)
+ if (response.StatusCode == expectedCode)
{
break;
}
await Task.Delay(1000);
-
}
return response;
}

MODIFY
MagicalCryptoWallet/Services/WalletService.cs
MagicalCryptoWallet/Services/WalletService.cs
@@ -541,7 +541,7 @@ namespace MagicalCryptoWallet.Services
Logger.LogInfo<WalletService>("Calculating dynamic transaction fee...");
Money feePerBytes = null;
using (var torClient = new TorHttpClient(IndexDownloader.Client.DestinationUri, IndexDownloader.Client.TorSocks5EndPoint, isolateStream: true))
- using (var response = await torClient.SendAndRetryAsync(HttpMethod.Get, $"/api/v1/btc/blockchain/fees/{feeTarget}"))
+ using (var response = await torClient.SendAndRetryAsync(HttpMethod.Get, HttpStatusCode.OK, $"/api/v1/btc/blockchain/fees/{feeTarget}"))
{
if (response.StatusCode != HttpStatusCode.OK)
throw new HttpRequestException($"Couldn't query network fees. Reason: {response.StatusCode.ToReasonString()}");

Add expected statuscode to SendAndRetry