Skip to content

Commit fc745c8

Browse files
committed
add possibility to sort circles_events asc or desc
1 parent afc191e commit fc745c8

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

‎Circles.Index.Rpc/QueryEvents.cs‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class QueryEvents(Context context)
2626
/// <returns>An array of CirclesEvent objects</returns>
2727
/// <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>
2828
public CirclesEvent[] CirclesEvents(Address? address, long? fromBlock, long? toBlock = null,
29-
FilterPredicateDto[]? additionalFilters = null)
29+
FilterPredicateDto[]? additionalFilters = null, bool? sortAscending = false)
3030
{
3131
long currentHead = context.NethermindApi.BlockTree?.Head?.Number
3232
?? throw new Exception("BlockTree or Head is null");
@@ -131,9 +131,9 @@ IFilterPredicate ToFilterPredicate(IFilterPredicateDto dto)
131131
new OrderBy("logIndex", "ASC")
132132
],
133133
null, true, int.MaxValue);
134-
134+
135135
queries.Add(query);
136-
136+
137137
context.Logger.Info(query.ToSql(context.Database).Sql);
138138
}
139139

@@ -169,8 +169,19 @@ IFilterPredicate ToFilterPredicate(IFilterPredicateDto dto)
169169
}
170170

171171
private CirclesEvent[] SortEvents(
172-
ConcurrentDictionary<(long BlockNo, long TransactionIndex, long LogIndex), CirclesEvent> events)
172+
ConcurrentDictionary<(long BlockNo, long TransactionIndex, long LogIndex), CirclesEvent> events,
173+
bool? sortAscending = false)
173174
{
175+
if (sortAscending == null || sortAscending == false)
176+
{
177+
return events
178+
.OrderByDescending(o => o.Key.BlockNo)
179+
.ThenByDescending(o => o.Key.TransactionIndex)
180+
.ThenByDescending(o => o.Key.LogIndex)
181+
.Select(o => o.Value)
182+
.ToArray();
183+
}
184+
174185
return events
175186
.OrderBy(o => o.Key.BlockNo)
176187
.ThenBy(o => o.Key.TransactionIndex)

0 commit comments

Comments
 (0)