Skip to content

Commit

Permalink
Merge pull request stratisproject#168 from quantumagi/dltremapis
Browse files Browse the repository at this point in the history
Remove Balances + AddressIndexer related APIs from BlockStore controller
  • Loading branch information
fassadlr authored Feb 3, 2020
2 parents ec30e48 + 4db12a2 commit 9903623
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 111 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Net.Http;
using Microsoft.Extensions.Logging;
using Stratis.Bitcoin.Controllers;
using Stratis.Bitcoin.Controllers.Models;

namespace Stratis.Bitcoin.Features.BlockStore.Controllers
{
/// <summary>Rest client for <see cref="BlockStoreController"/>.</summary>
public interface IBlockStoreClient : IRestApiClientBase
{
/// <summary><see cref="BlockStoreController.GetAddressesBalances"/></summary>
Task<AddressBalancesResult> GetAddressBalancesAsync(IEnumerable<string> addresses, int minConfirmations, CancellationToken cancellation = default(CancellationToken));

/// <summary><see cref="BlockStoreController.GetVerboseAddressesBalancesData"/></summary>
Task<VerboseAddressBalancesResult> GetVerboseAddressesBalancesDataAsync(IEnumerable<string> addresses, CancellationToken cancellation = default(CancellationToken));
}

/// <inheritdoc cref="IBlockStoreClient"/>
public class BlockStoreClient : RestApiClientBase, IBlockStoreClient
public class BlockStoreClient : RestApiClientBase
{
/// <summary>
/// Currently the <paramref name="url"/> is required as it needs to be configurable for testing.
Expand All @@ -31,25 +17,5 @@ public BlockStoreClient(ILoggerFactory loggerFactory, IHttpClientFactory httpCli
: base(loggerFactory, httpClientFactory, port, "BlockStore", url)
{
}

/// <inheritdoc />
public Task<AddressBalancesResult> GetAddressBalancesAsync(IEnumerable<string> addresses, int minConfirmations, CancellationToken cancellation = default(CancellationToken))
{
string addrString = string.Join(",", addresses);

string arguments = $"{nameof(addresses)}={addrString}&{nameof(minConfirmations)}={minConfirmations}";

return this.SendGetRequestAsync<AddressBalancesResult>(BlockStoreRouteEndPoint.GetAddressesBalances, arguments, cancellation);
}

/// <inheritdoc />
public Task<VerboseAddressBalancesResult> GetVerboseAddressesBalancesDataAsync(IEnumerable<string> addresses, CancellationToken cancellation = default(CancellationToken))
{
string addrString = string.Join(",", addresses);

string arguments = $"{nameof(addresses)}={addrString}";

return this.SendGetRequestAsync<VerboseAddressBalancesResult>(BlockStoreRouteEndPoint.GetVerboseAddressesBalances, arguments, cancellation);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ namespace Stratis.Bitcoin.Features.BlockStore.Controllers
{
public static class BlockStoreRouteEndPoint
{
public const string GetAddressesBalances = "getaddressesbalances";
public const string GetVerboseAddressesBalances = "getverboseaddressesbalances";
public const string GetAddressIndexerTip = "addressindexertip";
public const string GetBlock = "block";
public const string GetBlockCount = "GetBlockCount";
}
Expand Down Expand Up @@ -66,26 +63,6 @@ public BlockStoreController(
this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
}

/// <summary>
/// Retrieves the <see cref="addressIndexer"/>'s tip.
/// </summary>
/// <returns>An instance of <see cref="AddressIndexerTipModel"/> containing the tip's hash and height.</returns>
[Route(BlockStoreRouteEndPoint.GetAddressIndexerTip)]
[HttpGet]
public IActionResult GetAddressIndexerTip()
{
try
{
ChainedHeader addressIndexerTip = this.addressIndexer.IndexerTip;
return this.Json(new AddressIndexerTipModel() { TipHash = addressIndexerTip?.HashBlock, TipHeight = addressIndexerTip?.Height });
}
catch (Exception e)
{
this.logger.LogError("Exception occurred: {0}", e.ToString());
return ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString());
}
}

/// <summary>
/// Retrieves the block which matches the supplied block hash.
/// </summary>
Expand Down Expand Up @@ -160,57 +137,5 @@ public IActionResult GetBlockCount()
return ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString());
}
}

/// <summary>Provides balance of the given addresses confirmed with at least <paramref name="minConfirmations"/> confirmations.</summary>
/// <param name="addresses">A comma delimited set of addresses that will be queried.</param>
/// <param name="minConfirmations">Only blocks below consensus tip less this parameter will be considered.</param>
/// <returns>A result object containing the balance for each requested address and if so, a meesage stating why the indexer is not queryable.</returns>
[Route(BlockStoreRouteEndPoint.GetAddressesBalances)]
[HttpGet]
public IActionResult GetAddressesBalances(string addresses, int minConfirmations)
{
try
{
string[] addressesArray = addresses.Split(',');

this.logger.LogDebug("Asking data for {0} addresses.", addressesArray.Length);

AddressBalancesResult result = this.addressIndexer.GetAddressBalances(addressesArray, minConfirmations);

this.logger.LogDebug("Sending data for {0} addresses.", result.Balances.Count);

return this.Json(result);
}
catch (Exception e)
{
this.logger.LogError("Exception occurred: {0}", e.ToString());
return ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString());
}
}


/// <summary>Provides verbose balance data of the given addresses.</summary>
/// <param name="addresses">A comma delimited set of addresses that will be queried.</param>
/// <returns>A result object containing the balance for each requested address and if so, a meesage stating why the indexer is not queryable.</returns>
[Route(BlockStoreRouteEndPoint.GetVerboseAddressesBalances)]
[HttpGet]
public IActionResult GetVerboseAddressesBalancesData(string addresses)
{
try
{
string[] addressesArray = addresses?.Split(',') ?? new string[] { };

this.logger.LogDebug("Asking data for {0} addresses.", addressesArray.Length);

VerboseAddressBalancesResult result = this.addressIndexer.GetAddressIndexerState(addressesArray);

return this.Json(result);
}
catch (Exception e)
{
this.logger.LogError("Exception occurred: {0}", e.ToString());
return ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString());
}
}
}
}

0 comments on commit 9903623

Please sign in to comment.