Skip to content

Commit

Permalink
add possibility to sort circles_events asc or desc
Browse files Browse the repository at this point in the history
  • Loading branch information
jaensen committed Sep 10, 2024
1 parent afc191e commit fc745c8
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions Circles.Index.Rpc/QueryEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class QueryEvents(Context context)
/// <returns>An array of CirclesEvent objects</returns>
/// <exception cref="Exception">Thrown when the zero address is queried, fromBlock is less than 0, toBlock is less than fromBlock, or toBlock is greater than the current head</exception>
public CirclesEvent[] CirclesEvents(Address? address, long? fromBlock, long? toBlock = null,
FilterPredicateDto[]? additionalFilters = null)
FilterPredicateDto[]? additionalFilters = null, bool? sortAscending = false)
{
long currentHead = context.NethermindApi.BlockTree?.Head?.Number
?? throw new Exception("BlockTree or Head is null");
Expand Down Expand Up @@ -131,9 +131,9 @@ IFilterPredicate ToFilterPredicate(IFilterPredicateDto dto)
new OrderBy("logIndex", "ASC")
],
null, true, int.MaxValue);

queries.Add(query);

context.Logger.Info(query.ToSql(context.Database).Sql);
}

Expand Down Expand Up @@ -169,8 +169,19 @@ IFilterPredicate ToFilterPredicate(IFilterPredicateDto dto)
}

private CirclesEvent[] SortEvents(
ConcurrentDictionary<(long BlockNo, long TransactionIndex, long LogIndex), CirclesEvent> events)
ConcurrentDictionary<(long BlockNo, long TransactionIndex, long LogIndex), CirclesEvent> events,
bool? sortAscending = false)
{
if (sortAscending == null || sortAscending == false)
{
return events
.OrderByDescending(o => o.Key.BlockNo)
.ThenByDescending(o => o.Key.TransactionIndex)
.ThenByDescending(o => o.Key.LogIndex)
.Select(o => o.Value)
.ToArray();
}

return events
.OrderBy(o => o.Key.BlockNo)
.ThenBy(o => o.Key.TransactionIndex)
Expand Down

0 comments on commit fc745c8

Please sign in to comment.