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

feature: add table introspection #30

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
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
25 changes: 25 additions & 0 deletions Circles.Index.Rpc/CirclesRpcModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,31 @@ public Task<ResultWrapper<string>> circles_health()
return Task.FromResult(ResultWrapper<string>.Success("Healthy"));
}

public Task<ResultWrapper<IEnumerable<Namespace>>> circles_tables()
{
var namespaces = new List<Namespace>();
foreach (var namepsace in _indexerContext.Database.Schema.Tables.GroupBy(o => o.Key.Namespace))
{
var namespaceDto = new Namespace(namepsace.Key);
namespaces.Add(namespaceDto);

foreach (var table in namepsace)
{
var topic = table.Value.Topic.ToHexString(true);
var tableDto = new Table(table.Key.Table, topic);
namespaceDto.Tables = namespaceDto.Tables.Append(tableDto).ToArray();

foreach (var column in table.Value.Columns)
{
var columnDto = new Column(column.Column, column.Type.ToString());
tableDto.Columns = tableDto.Columns.Append(columnDto).ToArray();
}
}
}

return Task.FromResult(ResultWrapper<IEnumerable<Namespace>>.Success(namespaces));
}

private string[] GetTokenExposureIds(Address address)
{
var selectTokenExposure = new Select(
Expand Down
17 changes: 17 additions & 0 deletions Circles.Index.Rpc/ICirclesRpcModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ public record CirclesTrustRelations(Address User, CirclesTrustRelation[] Trusts,

public record CirclesEvent(string Event, IDictionary<string, object?> Values);

public record Column(string Name, string Type);

public class Table(string Name, string Topic)
{
public Column[] Columns { get; set; } = [];
}

public class Namespace(string Name)
{
public Table[] Tables { get; set; } = [];
}

#endregion

[RpcModule("Circles")]
Expand Down Expand Up @@ -70,4 +82,9 @@ ResultWrapper<CirclesEvent[]> circles_events(Address? address, long? fromBlock,
Description = "Checks if the database is available and indexing progresses as expected",
IsImplemented = true)]
Task<ResultWrapper<string>> circles_health();

[JsonRpcMethod(
Description = "Returns all indexed tables and columns grouped by namespace",
IsImplemented = true)]
Task<ResultWrapper<IEnumerable<Namespace>>> circles_tables();
}
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.11.14</AssemblyVersion>
<FileVersion>1.11.14</FileVersion>
<AssemblyVersion>1.11.15</AssemblyVersion>
<FileVersion>1.11.15</FileVersion>
</PropertyGroup>


Expand Down
15 changes: 15 additions & 0 deletions v2-example-requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,19 @@ curl -X POST --data '{
},
"id": 1
}
```

#### Get the max flow between two nodes
```shell
curl 'https://rpc.aboutcircles.com/' \
-H 'Content-Type: application/json' \
--data-raw '{"jsonrpc":"2.0","id":0,"method":"circlesV2_findPath","params":[{"Source":"0x749c930256b47049cb65adcd7c25e72d5de44b3b","Sink":"0xde374ece6fa50e781e81aac78e811b33d16912c7","TargetFlow":"99999999999999999999999999999999999"}]}'
```


#### Show all tables available for queries
```shell
curl 'https://rpc.aboutcircles.com/' \
-H 'Content-Type: application/json' \
--data-raw '{"jsonrpc":"2.0","id":0,"method":"circles_tables","params":[]}'
```
Loading