From 9238c889a45aedbc7c294039debc7ad01c241df0 Mon Sep 17 00:00:00 2001
From: daniel <4954577+jaensen@users.noreply.github.com>
Date: Sun, 19 May 2024 21:54:45 +0200
Subject: [PATCH] * Added more views: V_CrcV1_Transfers, V_Crc_Transfers *
Added missing 'transactionHash' column to CrcV1_Transfer
---
Circles.Index.CirclesV1/DatabaseSchema.cs | 48 +++++++++++++
Circles.Index.CirclesViews/DatabaseSchema.cs | 55 +++++++++++++++
Circles.Index.Common/IDatabaseQueryResult.cs | 12 ++--
Circles.Index.Rpc/CirclesRpcModule.cs | 37 ++++------
general-example-requests.md | 72 ++++++++++++++++++++
5 files changed, 195 insertions(+), 29 deletions(-)
diff --git a/Circles.Index.CirclesV1/DatabaseSchema.cs b/Circles.Index.CirclesV1/DatabaseSchema.cs
index 7dbc5f5..dc23516 100644
--- a/Circles.Index.CirclesV1/DatabaseSchema.cs
+++ b/Circles.Index.CirclesV1/DatabaseSchema.cs
@@ -29,6 +29,7 @@ public class DatabaseSchema : IDatabaseSchema
new("timestamp", ValueTypes.Int, true),
new("transactionIndex", ValueTypes.Int, true),
new("logIndex", ValueTypes.Int, true),
+ new("transactionHash", ValueTypes.String, true),
new("tokenAddress", ValueTypes.Address, true),
new("from", ValueTypes.Address, true),
new("to", ValueTypes.Address, true),
@@ -109,6 +110,53 @@ null as ""token""
")
};
+ ///
+ /// All Circles v1 hub transfers + personal minting
+ ///
+ public static readonly EventSchema Transfers = new("V_CrcV1", "Transfers",
+ new byte[32],
+ [
+ new("blockNumber", ValueTypes.Int, true),
+ new("timestamp", ValueTypes.Int, true),
+ new("transactionIndex", ValueTypes.Int, true),
+ new("logIndex", ValueTypes.Int, true),
+ new("transactionHash", ValueTypes.String, true),
+ new("from", ValueTypes.Address, true),
+ new("to", ValueTypes.Address, true),
+ new("amount", ValueTypes.BigInt, false)
+ ])
+ {
+ SqlMigrationItem = new SqlMigrationItem(@"
+ create or replace view ""V_CrcV1_Transfers"" as
+ with ""allTransfers"" as (
+ select ""blockNumber"",
+ ""timestamp"",
+ ""transactionIndex"",
+ ""logIndex"",
+ ""transactionHash"",
+ ""from"",
+ ""to"",
+ ""amount""
+ from ""CrcV1_HubTransfer""
+ union all
+ select t.""blockNumber"",
+ t.""timestamp"",
+ t.""transactionIndex"",
+ t.""logIndex"",
+ t.""transactionHash"",
+ t.""from"",
+ t.""to"",
+ t.""amount""
+ from ""CrcV1_Transfer"" t
+ join public.""CrcV1_Signup"" s on s.""token"" = t.""tokenAddress"" and s.""user"" = t.""to""
+ where ""from"" = '0x0000000000000000000000000000000000000000'
+ )
+ select *
+ from ""allTransfers""
+ order by ""blockNumber"" desc, ""transactionIndex"" desc, ""logIndex"" desc;
+ ")
+ };
+
public IDictionary<(string Namespace, string Table), EventSchema> Tables { get; } =
new Dictionary<(string Namespace, string Table), EventSchema>
{
diff --git a/Circles.Index.CirclesViews/DatabaseSchema.cs b/Circles.Index.CirclesViews/DatabaseSchema.cs
index 5e250ce..e3ba099 100644
--- a/Circles.Index.CirclesViews/DatabaseSchema.cs
+++ b/Circles.Index.CirclesViews/DatabaseSchema.cs
@@ -96,6 +96,57 @@ null as ""cidV0Digest""
")
};
+ public static readonly EventSchema Transfers = new("V_Crc", "Transfers",
+ new byte[32],
+ [
+ new("blockNumber", ValueTypes.Int, true),
+ new("timestamp", ValueTypes.Int, true),
+ new("transactionIndex", ValueTypes.Int, true),
+ new("logIndex", ValueTypes.Int, true),
+ new("batchIndex", ValueTypes.Int, true, true),
+ new("transactionHash", ValueTypes.String, true),
+ new("version", ValueTypes.Int, false),
+ new("operator", ValueTypes.Address, true),
+ new("from", ValueTypes.Address, true),
+ new("to", ValueTypes.Address, true),
+ new("id", ValueTypes.BigInt, true),
+ new("value", ValueTypes.BigInt, false)
+ ])
+ {
+ SqlMigrationItem = new SqlMigrationItem(@"
+ create or replace view ""V_Crc_Transfers"" as
+ with ""allTransfers"" as (select ""blockNumber"",
+ ""timestamp"",
+ ""transactionIndex"",
+ ""logIndex"",
+ 0 as ""batchIndex"",
+ ""transactionHash"",
+ 1 as ""version"",
+ null as ""operator"",
+ ""from"",
+ ""to"",
+ null as ""id"",
+ ""amount"" as ""value""
+ from ""V_CrcV1_Transfers""
+ union all
+ select ""blockNumber"",
+ ""timestamp"",
+ ""transactionIndex"",
+ ""logIndex"",
+ ""batchIndex"",
+ ""transactionHash"",
+ 2 as ""version"",
+ ""operator"",
+ ""from"",
+ ""to"",
+ ""id"",
+ ""value""
+ from ""V_CrcV2_Transfers"")
+ select *
+ from ""allTransfers"";
+ ")
+ };
+
public IDictionary<(string Namespace, string Table), EventSchema> Tables { get; } =
new Dictionary<(string Namespace, string Table), EventSchema>
{
@@ -106,6 +157,10 @@ null as ""cidV0Digest""
{
("V_Crc", "TrustRelations"),
TrustRelations
+ },
+ {
+ ("V_Crc", "Transfers"),
+ Transfers
}
};
}
\ No newline at end of file
diff --git a/Circles.Index.Common/IDatabaseQueryResult.cs b/Circles.Index.Common/IDatabaseQueryResult.cs
index ccb0d81..564af7c 100644
--- a/Circles.Index.Common/IDatabaseQueryResult.cs
+++ b/Circles.Index.Common/IDatabaseQueryResult.cs
@@ -6,8 +6,8 @@ namespace Circles.Index.Common;
[JsonConverter(typeof(DatabaseQueryResultConverter))]
public record DatabaseQueryResult(
- string[] columns,
- IEnumerable