Add new controllers
MODIFY
WalletWasabi.Backend/Controllers/BlockchainController.cs
WalletWasabi.Backend/Controllers/BlockchainController.cs
@@ -18,19 +18,17 @@ using NBitcoin.RPC;
namespace WalletWasabi.Backend.Controllers
{
/// <summary>
- /// To interact with the Bitcoin blockchain.
+ /// To interact with the Bitcoin Blockchain.
/// </summary>
[Produces("application/json")]
[Route("api/v1/btc/[controller]")]
public class BlockchainController : Controller
{
- private readonly IMemoryCache _cache;
- private readonly IExchangeRateProvider _exchangeRateProvider;
+ private IMemoryCache Cache { get; }
- public BlockchainController(IMemoryCache memoryCache, IExchangeRateProvider exchangeRateProvider)
+ public BlockchainController(IMemoryCache memoryCache)
{
- _cache = memoryCache;
- _exchangeRateProvider = exchangeRateProvider;
+ Cache = memoryCache;
}
private static RPCClient RpcClient => Global.RpcClient;
@@ -81,10 +79,9 @@ namespace WalletWasabi.Backend.Controllers
{
if (Network != Network.RegTest)
{
- // ToDo: This is the most naive way to implement this.
// 1. Use the sanity check that under 5 satoshi per bytes should not be displayed.
// 2. Use the RPCResponse.Blocks output to avoid redundant RPC queries.
- // 3. Implement caching.
+ // 3. Use caching.
var conservativeResponse = await GetEstimateSmartFeeAsync(target, EstimateSmartFeeMode.Conservative);
var economicalResponse = await GetEstimateSmartFeeAsync(target, EstimateSmartFeeMode.Economical);
var conservativeFee = conservativeResponse.FeeRate.FeePerK.Satoshi / 1000;
@@ -158,35 +155,6 @@ namespace WalletWasabi.Backend.Controllers
return Ok("Transaction is successfully broadcasted.");
}
- /// <summary>
- /// Gets exchange rates for one Bitcoin.
- /// </summary>
- /// <returns>ExchangeRates[] contains ticker and exchange rate pairs.</returns>
- /// <response code="200">Returns an array of exchange rates.</response>
- [HttpGet("exchange-rates")]
- [ProducesResponseType(typeof(IEnumerable<ExchangeRate>), 200)]
- [ResponseCache(Duration = 60, Location=ResponseCacheLocation.Client)]
- public async Task<IEnumerable<ExchangeRate>> GetExchangeRatesAsync()
- {
-
- if (!_cache.TryGetValue(nameof(GetExchangeRatesAsync), out List<ExchangeRate> exchangeRates))
- {
- exchangeRates = await _exchangeRateProvider.GetExchangeRateAsync();
-
- if (exchangeRates == null)
- {
- throw new HttpRequestException("BTC/USD exchange rate is not available.");
- }
-
- var cacheEntryOptions = new MemoryCacheEntryOptions()
- .SetAbsoluteExpiration(TimeSpan.FromSeconds(20));
-
- _cache.Set(nameof(GetExchangeRatesAsync), exchangeRates, cacheEntryOptions);
- }
-
- return exchangeRates;
- }
-
/// <summary>
/// Gets block filters from the specified block hash.
/// </summary>
@@ -235,17 +203,16 @@ namespace WalletWasabi.Backend.Controllers
private async Task<EstimateSmartFeeResponse> GetEstimateSmartFeeAsync(int target, EstimateSmartFeeMode mode)
{
-
var cacheKey = $"{nameof(GetEstimateSmartFeeAsync)}_{target}_{Enum.GetName(typeof(EstimateSmartFeeMode), mode)}";
- if (!_cache.TryGetValue(cacheKey, out EstimateSmartFeeResponse feeResponse))
+ if (!Cache.TryGetValue(cacheKey, out EstimateSmartFeeResponse feeResponse))
{
feeResponse = await RpcClient.EstimateSmartFeeAsync(target, mode);
var cacheEntryOptions = new MemoryCacheEntryOptions()
.SetAbsoluteExpiration(TimeSpan.FromSeconds(20));
- _cache.Set(cacheKey, feeResponse, cacheEntryOptions);
+ Cache.Set(cacheKey, feeResponse, cacheEntryOptions);
}
return feeResponse;

MODIFY
WalletWasabi.Tests/RegTests.cs
WalletWasabi.Tests/RegTests.cs
@@ -47,7 +47,7 @@ namespace WalletWasabi.Tests
while (true)
{
using (var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint)))
- using (var response = await client.SendAsync(HttpMethod.Get, "/api/v1/btc/Blockchain/filters/" + firstHash))
+ using (var response = await client.SendAsync(HttpMethod.Get, "/api/v1/btc/blockchain/filters/" + firstHash))
{
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var filters = await response.Content.ReadAsJsonAsync<List<string>>();
@@ -70,7 +70,7 @@ namespace WalletWasabi.Tests
public async void GetExchangeRatesAsyncAsync()
{
using (var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint)))
- using (var response = await client.SendAsync(HttpMethod.Get, "/api/v1/btc/Blockchain/exchange-rates"))
+ using (var response = await client.SendAsync(HttpMethod.Get, "/api/v1/btc/offchain/exchange-rates"))
{
Assert.True(response.StatusCode == HttpStatusCode.OK);
@@ -97,7 +97,7 @@ namespace WalletWasabi.Tests
var content = new StringContent($"'{signedTx.ToHex()}'", Encoding.UTF8, "application/json");
using (var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint)))
- using (var response = await client.SendAsync(HttpMethod.Post, "/api/v1/btc/Blockchain/broadcast", content))
+ using (var response = await client.SendAsync(HttpMethod.Post, "/api/v1/btc/blockchain/broadcast", content))
{
Assert.NotEqual(HttpStatusCode.OK, response.StatusCode);
@@ -114,7 +114,7 @@ namespace WalletWasabi.Tests
var tx = await Global.RpcClient.GetRawTransactionAsync(utxo.OutPoint.Hash);
var content = new StringContent($"'{tx.ToHex()}'", Encoding.UTF8, "application/json");
using (var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint)))
- using (var response = await client.SendAsync(HttpMethod.Post, "/api/v1/btc/Blockchain/broadcast", content))
+ using (var response = await client.SendAsync(HttpMethod.Post, "/api/v1/btc/blockchain/broadcast", content))
{
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("\"Transaction is already in the blockchain.\"", await response.Content.ReadAsStringAsync());
@@ -126,7 +126,7 @@ namespace WalletWasabi.Tests
{
var content = new StringContent($"''", Encoding.UTF8, "application/json");
using (var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint)))
- using (var response = await client.SendAsync(HttpMethod.Post, "/api/v1/btc/Blockchain/broadcast", content))
+ using (var response = await client.SendAsync(HttpMethod.Post, "/api/v1/btc/blockchain/broadcast", content))
{
Assert.NotEqual(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);

MODIFY
WalletWasabi/Services/IndexDownloader.cs
WalletWasabi/Services/IndexDownloader.cs
@@ -128,7 +128,7 @@ namespace WalletWasabi.Services
bestKnownFilter = Index.Last();
}
- var response = await Client.SendAsync(HttpMethod.Get, $"/api/v1/btc/Blockchain/filters/{bestKnownFilter.BlockHash}");
+ var response = await Client.SendAsync(HttpMethod.Get, $"/api/v1/btc/blockchain/filters/{bestKnownFilter.BlockHash}");
if (response.StatusCode == HttpStatusCode.NoContent)
{

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -320,7 +320,7 @@ namespace WalletWasabi.Services
if (hash == new uint256(fileName))
{
var blockBytes = await File.ReadAllBytesAsync(filePath);
- return new Block(blockBytes);
+ return new Block(blockBytes, IndexDownloader.Network.Consensus);
}
}
}
@@ -749,7 +749,7 @@ namespace WalletWasabi.Services
{
using (var torClient = new TorHttpClient(IndexDownloader.Client.DestinationUri, IndexDownloader.Client.TorSocks5EndPoint, isolateStream: true))
using (var content = new StringContent($"'{transaction.Transaction.ToHex()}'", Encoding.UTF8, "application/json"))
- using (var response = await torClient.SendAsync(HttpMethod.Post, "/api/v1/btc/Blockchain/broadcast", content))
+ using (var response = await torClient.SendAsync(HttpMethod.Post, "/api/v1/btc/blockchain/broadcast", content))
{
if (response.StatusCode == HttpStatusCode.BadRequest)
{

Add new controllers