Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion Discreet/RPC/Endpoints/ReadEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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<Block> blocks = new List<Block>();

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)
{
Expand Down Expand Up @@ -582,7 +615,7 @@ public class GetBlockchainRV
public List<FullTransaction> TxPool { get; set; }
public string Status { get; set; }
public bool Synced { get; set; }


public GetBlockchainRV() { }
}
Expand Down