-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from CirclesUBI/feature/query-tables-and-cols-b…
…y-name allow to query tables and columns by name
- Loading branch information
Showing
7 changed files
with
120 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.container-state | ||
.state | ||
circles-contracts | ||
circles-contracts-v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,115 +1,8 @@ | ||
using System.Data.Common; | ||
using Circles.Index.Data; | ||
using Circles.Index.Data.Query; | ||
using Circles.Index.Rpc; | ||
using Newtonsoft.Json; | ||
using Npgsql; | ||
|
||
namespace Circles.Index; | ||
|
||
public static class Program | ||
{ | ||
public static void Main() | ||
{ | ||
DbProviderFactory factory = NpgsqlFactory.Instance; | ||
Query.Initialize(factory); | ||
|
||
|
||
CirclesQuery q = new() | ||
{ | ||
Table = Tables.Erc20Transfer, Columns = | ||
[ | ||
Columns.BlockNumber, | ||
Columns.TransactionIndex, | ||
Columns.LogIndex, | ||
Columns.TransactionHash, | ||
Columns.FromAddress, | ||
Columns.ToAddress, | ||
Columns.Amount | ||
], | ||
Conditions = | ||
{ | ||
new Expression | ||
{ | ||
Type = "LessThan", | ||
Column = Columns.Amount, | ||
Value = "500000000000000000000000000000" | ||
}, | ||
new Expression | ||
{ | ||
Type = "Equals", | ||
Column = Columns.FromAddress, | ||
Value = "0x0000000000000000000000000000000000000000" | ||
} | ||
} | ||
}; | ||
|
||
var json = JsonConvert.SerializeObject(q); | ||
Console.WriteLine(json); | ||
|
||
var result = circles_query(q); | ||
|
||
foreach (var row in result) | ||
{ | ||
Console.WriteLine(string.Join(", ", row)); | ||
} | ||
|
||
Console.WriteLine("Hello, Circles!"); | ||
} | ||
|
||
|
||
public static IEnumerable<object[]> circles_query(CirclesQuery query) | ||
{ | ||
using NpgsqlConnection connection = new("Host=localhost;Username=postgres;Database=postgres;Port=7432;Include Error Detail=true;"); | ||
connection.Open(); | ||
|
||
Schema.Migrate(connection); | ||
|
||
var select = Query.Select(query.Table, | ||
query.Columns ?? throw new InvalidOperationException("Columns are null")); | ||
|
||
if (query.Conditions.Any()) | ||
{ | ||
foreach (var condition in query.Conditions) | ||
{ | ||
select.Where(BuildCondition(query.Table, condition)); | ||
} | ||
} | ||
|
||
Console.WriteLine(select.ToString()); | ||
|
||
var result = Query.Execute(connection, select).ToList(); | ||
|
||
return result; | ||
} | ||
|
||
private static IQuery BuildCondition(Tables table, Expression expression) | ||
{ | ||
if (expression.Type == "Equals") | ||
{ | ||
return Query.Equals(table, expression.Column!.Value, expression.Value!); | ||
} | ||
|
||
if (expression.Type == "GreaterThan") | ||
{ | ||
return Query.GreaterThan(table, expression.Column!.Value, expression.Value!); | ||
} | ||
|
||
if (expression.Type == "LessThan") | ||
{ | ||
return Query.LessThan(table, expression.Column!.Value, expression.Value!); | ||
} | ||
|
||
if (expression.Type == "And") | ||
{ | ||
return Query.And(expression.Elements!.Select(o => BuildCondition(table, o)).ToArray()); | ||
} | ||
|
||
if (expression.Type == "Or") | ||
{ | ||
return Query.Or(expression.Elements!.Select(o => BuildCondition(table, o)).ToArray()); | ||
} | ||
|
||
throw new InvalidOperationException($"Unknown expression type: {expression.Type}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
services: | ||
execution: | ||
container_name: execution | ||
#image: jaensen/nethermind-circlesubi:dev-x86_64 | ||
build: | ||
context: . | ||
dockerfile: x64.Dockerfile | ||
restart: unless-stopped | ||
# network_mode: host | ||
networks: | ||
- circles | ||
ports: | ||
- 30303:30303/tcp # p2p | ||
- 30303:30303/udp # p2p | ||
- 8545:8545 | ||
expose: | ||
- 8551 # engine api | ||
volumes: | ||
- .state/execution:/data | ||
- .state/jwtsecret/jwt.hex:/jwt.hex | ||
- /etc/timezone:/etc/timezone:ro | ||
- /etc/localtime:/etc/localtime:ro | ||
command: | | ||
--config=chiado | ||
--datadir=/data | ||
--log=INFO | ||
--Sync.SnapSync=false | ||
--JsonRpc.Enabled=true | ||
--JsonRpc.Host=0.0.0.0 | ||
--JsonRpc.Port=8545 | ||
--JsonRpc.EnabledModules=[Web3,Eth,Subscribe,Net,Circles] | ||
--JsonRpc.JwtSecretFile=/jwt.hex | ||
--JsonRpc.EngineHost=0.0.0.0 | ||
--JsonRpc.EnginePort=8551 | ||
--Network.DiscoveryPort=30303 | ||
--HealthChecks.Enabled=false | ||
logging: | ||
driver: "local" | ||
environment: | ||
- V1_HUB_ADDRESS=0xdbf22d4e8962db3b2f1d9ff55be728a887e47710 | ||
- V2_HUB_ADDRESS=0xDA02CDB5279B3a1eF27Be3d91aE924495E6A5569 | ||
- START_BLOCK=0 | ||
- POSTGRES_CONNECTION_STRING=Server=db;Port=5432;User Id=postgres;Password=;Database=postgres; | ||
|
||
db: | ||
image: postgres:16 | ||
command: -c 'max_connections=100' | ||
restart: unless-stopped | ||
container_name: 'postgres' | ||
# network_mode: host | ||
networks: | ||
- circles | ||
environment: | ||
POSTGRES_PASSWORD: '' | ||
POSTGRES_USER: 'postgres' | ||
POSTGRES_HOST_AUTH_METHOD: 'trust' | ||
volumes: | ||
- ./.state/postgres-data:/var/lib/postgresql/data | ||
|
||
consensus: | ||
container_name: consensus | ||
image: sigp/lighthouse:v5.0.0 | ||
restart: always | ||
# network_mode: host | ||
networks: | ||
- circles | ||
ports: | ||
- 9000:9000/tcp # p2p | ||
- 9000:9000/udp # p2p | ||
- 5054:5054/tcp # metrics | ||
expose: | ||
- 4000 # http | ||
volumes: | ||
- .state/consensus/data:/data | ||
- .state/jwtsecret/jwt.hex:/jwt.hex | ||
- /etc/timezone:/etc/timezone:ro | ||
- /etc/localtime:/etc/localtime:ro | ||
command: | | ||
lighthouse | ||
beacon_node | ||
--network=chiado | ||
--disable-upnp | ||
--datadir=/data | ||
--port=9000 | ||
--http | ||
--http-address=0.0.0.0 | ||
--http-port=4000 | ||
--execution-endpoint=http://execution:8551 | ||
--execution-jwt=/jwt.hex | ||
--checkpoint-sync-url=https://checkpoint.chiadochain.net/ | ||
logging: | ||
driver: "local" | ||
|
||
networks: | ||
circles: | ||
name: circles |