-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adapt Indexer to Mempool Endpoints #223
Open
theDRB123
wants to merge
14
commits into
block-core:master
Choose a base branch
from
theDRB123:adapt-to-mempool-endpoints
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4914d1f
Modified IStorage & Implementation for additional method
theDRB123 a4881dd
Added Models for MempoolSpace entities
theDRB123 d456df0
Added mempoolSpaceApi controller and helper methods
theDRB123 7dda5c3
Modified the GetAddressTransactions to use async and the MempoolModel…
theDRB123 45cd60d
Modified MempoolSpaceControllers to be in Angor namespace, Added addi…
theDRB123 3852443
Implemented GetTransactionOutspends
theDRB123 92c02f1
Modified GetAddressTransactions to return outpoint data correctly
theDRB123 3fab126
Added fees/recommended
theDRB123 8d65711
Shifted mempoolHelpers outside of the controller
theDRB123 de7f1d5
Minor cleanup
theDRB123 388d4c1
Modified Transaction List function to be Async in MongoData
theDRB123 17240b5
fixed block height api to only return blockhash
theDRB123 b54eb8c
Modified GetTransactionOutspends to be Async
theDRB123 a8301ca
minor fix
theDRB123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
src/Blockcore.Indexer.Angor/Controllers/MempoolSpaceController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Blockcore.Indexer.Core.Storage; | ||
using Blockcore.Indexer.Core.Models; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Text.Json; | ||
using Blockcore.Indexer.Core.Storage.Types; | ||
using Blockcore.Indexer.Core.Handlers; | ||
|
||
|
||
|
||
namespace Blockcore.Indexer.Angor.Controllers | ||
{ | ||
[ApiController] | ||
[Route("api/mempoolspace")] | ||
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, StatsHandler statsHandler) | ||
{ | ||
this.storage = storage; | ||
this.statsHandler = statsHandler; | ||
} | ||
|
||
[HttpGet] | ||
[Route("address/{address}")] | ||
public IActionResult GetAddress([MinLength(4)][MaxLength(100)] string address) | ||
{ | ||
AddressResponse addressResponse = storage.AddressResponseBalance(address); | ||
return Ok(JsonSerializer.Serialize(addressResponse, serializeOption)); | ||
} | ||
|
||
[HttpGet] | ||
[Route("address/{address}/txs")] | ||
public async Task<IActionResult> GetAddressTransactions(string address) | ||
{ | ||
var transactions = storage.AddressHistory(address, null, 50).Items.Select(t => t.TransactionHash).ToList(); | ||
List<MempoolTransaction> txns = await storage.GetMempoolTransactionListAsync(transactions); | ||
return Ok(JsonSerializer.Serialize(txns, serializeOption)); | ||
} | ||
|
||
[HttpGet] | ||
[Route("tx/{txid}/outspends")] | ||
public async Task<IActionResult> GetTransactionOutspends(string txid) | ||
{ | ||
List<OutspentResponse> responses = await storage.GetTransactionOutspendsAsync(txid); | ||
return Ok(JsonSerializer.Serialize(responses, serializeOption)); | ||
} | ||
|
||
[HttpGet] | ||
[Route("fees/recommended")] | ||
public IActionResult GetRecommendedFees() | ||
{ | ||
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] | ||
[Route("tx/{txid}/hex")] | ||
public IActionResult GetTransactionHex(string txid) | ||
{ | ||
var txn = storage.GetRawTransaction(txid); | ||
if (txn == null) | ||
{ | ||
return NotFound(); | ||
} | ||
return Ok(txn); | ||
} | ||
|
||
[HttpGet] | ||
[Route("block-height/{height}")] | ||
public IActionResult GetBlockHeight(int height) | ||
{ | ||
return Ok(storage.BlockByIndex(height).BlockHash); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using System.Net.Http.Json; | ||
|
||
|
||
namespace Blockcore.Indexer.Core.Models | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer having each model in a seperate file under the same namespace |
||
{ | ||
|
||
public class AddressStats | ||
{ | ||
public int FundedTxoCount { get; set; } | ||
public long FundedTxoSum { get; set; } | ||
public int SpentTxoCount { get; set; } | ||
public long SpentTxoSum { get; set; } | ||
public int TxCount { get; set; } | ||
} | ||
public class AddressResponse | ||
{ | ||
public string Address { get; set; } | ||
public AddressStats ChainStats { get; set; } | ||
public AddressStats MempoolStats { get; set; } | ||
} | ||
|
||
public class OutspentResponse{ | ||
public bool spent { get; set; } | ||
public string txid { get; set; } | ||
public int vin { get; set; } | ||
public UtxoStatus status { get; set; } | ||
} | ||
|
||
public class AddressUtxo | ||
{ | ||
public string Txid { get; set; } | ||
public int Vout { get; set; } | ||
public UtxoStatus Status { get; set; } | ||
public long Value { get; set; } | ||
} | ||
|
||
public class UtxoStatus | ||
{ | ||
public bool Confirmed { get; set; } | ||
public int BlockHeight { get; set; } | ||
public string BlockHash { get; set; } | ||
public long BlockTime { get; set; } | ||
} | ||
|
||
public class RecommendedFees | ||
{ | ||
public int FastestFee { get; set; } | ||
public int HalfHourFee { get; set; } | ||
public int HourFee { get; set; } | ||
public int EconomyFee { get; set; } | ||
public int MinimumFee { get; set; } | ||
} | ||
|
||
public class Vin | ||
{ | ||
public bool IsCoinbase { get; set; } | ||
public PrevOut Prevout { get; set; } | ||
public string Scriptsig { get; set; } | ||
public string Asm { get; set; } | ||
public long Sequence { get; set; } | ||
public string Txid { get; set; } | ||
public int Vout { get; set; } | ||
public List<string> Witness { get; set; } | ||
public string InnserRedeemscriptAsm { get; set; } | ||
public string InnerWitnessscriptAsm { get; set; } | ||
} | ||
public class PrevOut | ||
{ | ||
public long Value { get; set; } | ||
public string Scriptpubkey { get; set; } | ||
public string ScriptpubkeyAddress { get; set; } | ||
public string ScriptpubkeyAsm { get; set; } | ||
public string ScriptpubkeyType { get; set; } | ||
} | ||
|
||
public class MempoolTransaction | ||
{ | ||
public string Txid { get; set; } | ||
|
||
public int Version { get; set; } | ||
|
||
public int Locktime { get; set; } | ||
public int Size { get; set; } | ||
public int Weight { get; set; } | ||
public int Fee { get; set; } | ||
public List<Vin> Vin { get; set; } | ||
public List<PrevOut> Vout { get; set; } | ||
public UtxoStatus Status { get; set; } | ||
} | ||
|
||
public class Outspent | ||
{ | ||
public bool Spent { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is done in another branch so I'll ignore it here