Add batch request
MODIFY
WalletWasabi.Backend/Controllers/BlockchainController.cs
WalletWasabi.Backend/Controllers/BlockchainController.cs
@@ -123,11 +123,27 @@ namespace WalletWasabi.Backend.Controllers
return BadRequest("Invalid estimation mode is provided, possible values: ECONOMICAL/CONSERVATIVE.");
}
- AllFeeEstimate estimation = await RpcClient.EstimateAllFeeAsync(mode, simulateIfRegTest: true, tolerateBitcoinCoreBrainfuck: true);
+ AllFeeEstimate estimation = await GetAllFeeEstimateAsync(mode);
return Ok(estimation.Estimations);
}
+ internal async Task<AllFeeEstimate> GetAllFeeEstimateAsync(EstimateSmartFeeMode mode)
+ {
+ var cacheKey = $"{nameof(GetAllFeeEstimateAsync)}_{mode}";
+
+ if (!Cache.TryGetValue(cacheKey, out AllFeeEstimate allFee))
+ {
+ allFee = await RpcClient.EstimateAllFeeAsync(mode, simulateIfRegTest: true, tolerateBitcoinCoreBrainfuck: true);
+
+ var cacheEntryOptions = new MemoryCacheEntryOptions()
+ .SetAbsoluteExpiration(TimeSpan.FromSeconds(500));
+
+ Cache.Set(cacheKey, allFee, cacheEntryOptions);
+ }
+ return allFee;
+ }
+
/// <summary>
/// Attempts to broadcast a transaction.
/// </summary>
@@ -235,14 +251,14 @@ namespace WalletWasabi.Backend.Controllers
private async Task<EstimateSmartFeeResponse> GetEstimateSmartFeeAsync(int target, EstimateSmartFeeMode mode)
{
- var cacheKey = $"{nameof(GetEstimateSmartFeeAsync)}_{target}_{Enum.GetName(typeof(EstimateSmartFeeMode), mode)}";
+ var cacheKey = $"{nameof(GetEstimateSmartFeeAsync)}_{target}_{mode}";
if (!Cache.TryGetValue(cacheKey, out EstimateSmartFeeResponse feeResponse))
{
feeResponse = await RpcClient.EstimateSmartFeeAsync(target, mode, simulateIfRegTest: true, tryOtherFeeRates: true);
var cacheEntryOptions = new MemoryCacheEntryOptions()
- .SetAbsoluteExpiration(TimeSpan.FromSeconds(20));
+ .SetAbsoluteExpiration(TimeSpan.FromSeconds(300));
Cache.Set(cacheKey, feeResponse, cacheEntryOptions);
}

MODIFY
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
@@ -45,6 +45,13 @@ namespace WalletWasabi.Backend.Controllers
[HttpGet("states")]
[ProducesResponseType(200)]
public IActionResult GetStates()
+ {
+ IEnumerable<CcjRunningRoundState> response = GetStatesCollection();
+
+ return Ok(response);
+ }
+
+ public static IEnumerable<CcjRunningRoundState> GetStatesCollection()
{
var response = new List<CcjRunningRoundState>();
@@ -68,7 +75,7 @@ namespace WalletWasabi.Backend.Controllers
response.Add(state);
}
- return Ok(response);
+ return response;
}
private static AsyncLock InputsLock { get; } = new AsyncLock();

MODIFY
WalletWasabi.Backend/Controllers/OffchainController.cs
WalletWasabi.Backend/Controllers/OffchainController.cs
using Microsoft.Extensions.Caching.Memory;
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using WalletWasabi.Backend.Models;
@@ -30,26 +31,40 @@ namespace WalletWasabi.Backend.Controllers
/// </summary>
/// <returns>ExchangeRates[] contains ticker and exchange rate pairs.</returns>
/// <response code="200">Returns an array of exchange rates.</response>
+ /// <response code="404">Exchange rates are not available.</response>
[HttpGet("exchange-rates")]
- [ProducesResponseType(typeof(IEnumerable<ExchangeRate>), 200)]
- [ResponseCache(Duration = 500, Location = ResponseCacheLocation.Client)]
- public async Task<IEnumerable<ExchangeRate>> GetExchangeRatesAsync()
+ [ProducesResponseType(200)]
+ [ProducesResponseType(404)]
+ public async Task<IActionResult> GetExchangeRatesAsync()
{
- if (Cache.TryGetValue(nameof(GetExchangeRatesAsync), out List<ExchangeRate> exchangeRates))
- return exchangeRates;
+ IEnumerable<ExchangeRate> exchangeRates = await GetExchangeRatesCollectionAsync();
+
+ if (!exchangeRates.Any())
+ {
+ return NotFound("Exchange rates are not available.");
+ }
+
+ return Ok(exchangeRates);
+ }
+ internal async Task<IEnumerable<ExchangeRate>> GetExchangeRatesCollectionAsync()
+ {
+ var cacheKey = nameof(GetExchangeRatesCollectionAsync);
+
+ if (!Cache.TryGetValue(cacheKey, out IEnumerable<ExchangeRate> exchangeRates))
+ {
exchangeRates = await ExchangeRateProvider.GetExchangeRateAsync();
if (exchangeRates is null)
{
- throw new HttpRequestException("BTC/USD exchange rate is not available.");
+ return Enumerable.Empty<ExchangeRate>();
}
var cacheEntryOptions = new MemoryCacheEntryOptions()
- .SetAbsoluteExpiration(TimeSpan.FromSeconds(20));
-
- Cache.Set(nameof(GetExchangeRatesAsync), exchangeRates, cacheEntryOptions);
+ .SetAbsoluteExpiration(TimeSpan.FromSeconds(500));
+ Cache.Set(cacheKey, exchangeRates, cacheEntryOptions);
+ }
return exchangeRates;
}
}

Add batch request