Skip to content

Commit

Permalink
Added fees/recommended
Browse files Browse the repository at this point in the history
  • Loading branch information
theDRB123 committed Jan 25, 2025
1 parent 92c02f1 commit 3fab126
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/Blockcore.Indexer.Angor/Controllers/MempoolSpaceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Json;
using Blockcore.Indexer.Core.Storage.Types;
using Blockcore.Indexer.Core.Handlers;


static class MempoolSpaceHelpers
Expand Down Expand Up @@ -87,16 +88,18 @@ namespace Blockcore.Indexer.Angor.Controllers
public class MempoolSpaceController : Controller
{
private readonly IStorage storage;
private readonly StatsHandler statsHandler;

private readonly JsonSerializerOptions serializeOption = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
WriteIndented = true
};

public MempoolSpaceController(IStorage storage)
public MempoolSpaceController(IStorage storage, StatsHandler statsHandler)
{
this.storage = storage;
this.statsHandler = statsHandler;
}

[HttpGet]
Expand Down Expand Up @@ -129,7 +132,26 @@ public IActionResult GetTransactionOutspends(string txid)
[Route("fees/recommended")]
public IActionResult GetRecommendedFees()
{
return Ok();
RecommendedFees recommendedFees = new();
var statsFees = statsHandler.GetFeeEstimation([1, 3, 6, 12, 48]);
statsFees.Wait();
var Fees = statsFees.Result.Fees.Select(fee => ConvertToSatsPerVByte(fee.FeeRate)).ToList();
recommendedFees.FastestFee = (int)Fees[0];
recommendedFees.HalfHourFee = (int)Fees[1];
recommendedFees.HourFee = (int)Fees[2];
recommendedFees.EconomyFee = (int)Fees[3];
recommendedFees.MinimumFee = (int)Fees[4];

return Ok(JsonSerializer.Serialize(recommendedFees, new JsonSerializerOptions()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true
}));
}

private double ConvertToSatsPerVByte(double fee)
{
return fee / 1_000;
}

[HttpGet]
Expand Down

0 comments on commit 3fab126

Please sign in to comment.