Skip to content
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

add get_blocks_range endpoint #127

Merged
merged 1 commit into from
Jul 9, 2024
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
Loading