From 4708fb8b292388a72675e85cec3a7fd5abd12a92 Mon Sep 17 00:00:00 2001 From: Brandon Koerner Date: Tue, 9 Jul 2024 18:49:26 -0400 Subject: [PATCH] add get_blocks_range endpoint --- Discreet/RPC/Endpoints/ReadEndpoints.cs | 35 ++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Discreet/RPC/Endpoints/ReadEndpoints.cs b/Discreet/RPC/Endpoints/ReadEndpoints.cs index d156a51..8309074 100644 --- a/Discreet/RPC/Endpoints/ReadEndpoints.cs +++ b/Discreet/RPC/Endpoints/ReadEndpoints.cs @@ -10,6 +10,8 @@ using System.Text.Json; using Discreet.Coin.Models; using Discreet.Common.Serialize; +using System.Data; +using static System.Reflection.Metadata.BlobBuilder; namespace Discreet.RPC.Endpoints { @@ -174,6 +176,37 @@ public static object GetBlockHeight(string hash) } } + [RPCEndpoint("get_blocks_range", APISet.READ)] + public static object GetBlocksRange(long start, long count) + { + List blocks = new List(); + + try + { + var iter = DB.DataView.GetView().GetBlocks(start, count + 1); + var enumr = iter.GetEnumerator(); + + while (enumr.MoveNext()) + { + if (enumr.Current == null) break; + + if (blocks.Count == count) + { + break; + } + blocks.Add(enumr.Current); + } + + return blocks; + } + catch (Exception ex) + { + Daemon.Logger.Error($"RPC call to GetBlocksRange failed: {ex.Message}", ex); + + return new RPCError(-1, $"Could not get blocks with specified range", blocks); + } + } + [RPCEndpoint("get_blocks", APISet.READ)] public static object GetBlocks(object[] idxs) { @@ -582,7 +615,7 @@ public class GetBlockchainRV public List TxPool { get; set; } public string Status { get; set; } public bool Synced { get; set; } - + public GetBlockchainRV() { } }