Skip to content

Commit

Permalink
* add event type filter for circles_events.
Browse files Browse the repository at this point in the history
* add ILike filter
  • Loading branch information
jaensen committed Sep 24, 2024
1 parent 4536a1e commit 879909a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions Circles.Index.Query/FilterPredicate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public ParameterizedSql ToSql(IDatabaseUtils database)
FilterType.LessThan => $"{database.QuoteIdentifier(Column)} < {parameterName}_0",
FilterType.LessThanOrEquals => $"{database.QuoteIdentifier(Column)} <= {parameterName}_0",
FilterType.Like => $"{database.QuoteIdentifier(Column)} LIKE {parameterName}_0",
FilterType.ILike => $"{database.QuoteIdentifier(Column)} ILIKE {parameterName}_0",
FilterType.NotLike => $"{database.QuoteIdentifier(Column)} NOT LIKE {parameterName}_0",
FilterType.In => ConvertToEnumerable(Value)?.Any() ?? false
? $"{database.QuoteIdentifier(Column)} IN ({FormatArrayParameter(Value, parameterName)})"
Expand Down
3 changes: 3 additions & 0 deletions Circles.Index.Query/FilterType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public enum FilterType
[JsonConverter(typeof(JsonStringEnumConverter))]
Like,

[JsonConverter(typeof(JsonStringEnumConverter))]
ILike,

[JsonConverter(typeof(JsonStringEnumConverter))]
NotLike,

Expand Down
4 changes: 2 additions & 2 deletions Circles.Index.Rpc/CirclesRpcModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,11 @@ public ResultWrapper<DatabaseQueryResult> circles_query(SelectDto query)
}

public ResultWrapper<CirclesEvent[]> circles_events(Address? address, long? fromBlock, long? toBlock = null,
FilterPredicateDto[]? filterPredicates = null, bool? sortAscending = false)
string[]? eventTypes = null, FilterPredicateDto[]? filterPredicates = null, bool? sortAscending = false)
{
var queryEvents = new QueryEvents(_indexerContext);
return ResultWrapper<CirclesEvent[]>.Success(queryEvents.CirclesEvents(address, fromBlock, toBlock,
filterPredicates, sortAscending));
eventTypes, filterPredicates, sortAscending));
}

private string[] GetTokenExposureIds(Address address)
Expand Down
3 changes: 2 additions & 1 deletion Circles.Index.Rpc/ICirclesRpcModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ public interface ICirclesRpcModule : IRpcModule

[JsonRpcMethod(Description = "Returns all events affecting the specified account since block N",
IsImplemented = true)]
ResultWrapper<CirclesEvent[]> circles_events(Address? address, long? fromBlock, long? toBlock = null, FilterPredicateDto[]? filters = null, bool? sortAscending = false);
ResultWrapper<CirclesEvent[]> circles_events(Address? address, long? fromBlock, long? toBlock = null,
string[]? eventTypes = null, FilterPredicateDto[]? filters = null, bool? sortAscending = false);
}
16 changes: 12 additions & 4 deletions Circles.Index.Rpc/QueryEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ public class QueryEvents(Context context)
/// <param name="address">If specified, only events concerning this account are queried</param>
/// <param name="fromBlock">HEAD - 1000 if not specified otherwise</param>
/// <param name="toBlock">HEAD if not specified otherwise</param>
/// <param name="additionalFilters">Additional filters to apply to the query</param>
/// <param name="onlyTheseTypes">An array of event types to include in the query</param>
/// <param name="additionalFilters">Additional filters to apply to the query. The filtered columns must be present in all queried events!</param>
/// <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, bool? sortAscending = false)
string[]? onlyTheseTypes = null, FilterPredicateDto[]? additionalFilters = null, bool? sortAscending = false)
{
long currentHead = context.NethermindApi.BlockTree?.Head?.Number
?? throw new Exception("BlockTree or Head is null");
Expand All @@ -37,7 +38,7 @@ public CirclesEvent[] CirclesEvents(Address? address, long? fromBlock, long? toB

ValidateInputs(addressString, fromBlock.Value, toBlock, currentHead);

var queries = BuildQueries(addressString, fromBlock.Value, toBlock, additionalFilters);
var queries = BuildQueries(addressString, fromBlock.Value, toBlock, onlyTheseTypes, additionalFilters);

var events = ExecuteQueries(queries);

Expand All @@ -63,14 +64,21 @@ private void ValidateInputs(string? address, long fromBlock, long? toBlock, long
}

private List<Select> BuildQueries(string? address, long fromBlock, long? toBlock,
FilterPredicateDto[]? additionalFilters = null)
string[]? onlyTheseTypes = null, FilterPredicateDto[]? additionalFilters = null)
{
var queries = new List<Select>();

foreach (var table in context.Database.Schema.Tables)
{
if (table.Key.Namespace.StartsWith("V_") || table.Key.Namespace == "System")
{
continue;
}

if (onlyTheseTypes != null && !onlyTheseTypes.Contains($"{table.Key.Namespace}_{table.Key.Table}"))
{
continue;
}

var addressColumnFilters = address == null
? []
Expand Down
4 changes: 2 additions & 2 deletions Circles.Index/Circles.Index.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<Authors>Daniel Janz (Gnosis Service GmbH)</Authors>
<Copyright>Gnosis Service GmbH</Copyright>
<Product>Circles</Product>
<AssemblyVersion>1.8.1</AssemblyVersion>
<FileVersion>1.8.1</FileVersion>
<AssemblyVersion>1.8.2</AssemblyVersion>
<FileVersion>1.8.2</FileVersion>
</PropertyGroup>


Expand Down

0 comments on commit 879909a

Please sign in to comment.