Skip to content

Commit

Permalink
add a 'tokenAddress' to all CrcV2 event tables that only have a token…
Browse files Browse the repository at this point in the history
… 'id'.

add the 'tokenType' to the transfers views
  • Loading branch information
jaensen committed Sep 11, 2024
1 parent be6f1fa commit a22bc20
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 85 deletions.
1 change: 1 addition & 0 deletions Circles.Index.CirclesV2/Circles.Index.CirclesV2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ItemGroup>
<ProjectReference Include="..\Circles.Index.Common\Circles.Index.Common.csproj" />
<ProjectReference Include="..\Circles.Index.Postgres\Circles.Index.Postgres.csproj" />
<ProjectReference Include="..\Circles.Index.Utils\Circles.Index.Utils.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
60 changes: 46 additions & 14 deletions Circles.Index.CirclesV2/DatabaseSchema.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Numerics;
using Circles.Index.Common;
using Circles.Index.Utils;
using Nethermind.Core.Crypto;

namespace Circles.Index.CirclesV2;
Expand Down Expand Up @@ -32,13 +33,38 @@ public class DatabaseSchema : IDatabaseSchema
public static readonly EventSchema Trust =
EventSchema.FromSolidity("CrcV2",
"event Trust(address indexed truster, address indexed trustee, uint256 expiryTime)");

public static readonly EventSchema TransferSingle = EventSchema.FromSolidity(
"CrcV2",
"event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 indexed id, uint256 value)");

public static readonly EventSchema URI =
EventSchema.FromSolidity("CrcV2", "event URI(string value, uint256 indexed id)");
//
// public static readonly EventSchema TransferSingle = EventSchema.FromSolidity(
// "CrcV2",
// "event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 indexed id, uint256 value)");
public static readonly EventSchema TransferSingle = new("CrcV2", "TransferSingle",
Keccak.Compute("TransferSingle(address,address,address,uint256,uint256)").BytesToArray(), [
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("operator", ValueTypes.Address, true),
new("from", ValueTypes.Address, true),
new("to", ValueTypes.Address, true),
new("id", ValueTypes.BigInt, true),
new("value", ValueTypes.BigInt, false),
new("tokenAddress", ValueTypes.Address, true)
]);

// public static readonly EventSchema URI =
// EventSchema.FromSolidity("CrcV2", "event URI(string value, uint256 indexed id)");

public static readonly EventSchema URI = new EventSchema("CrcV2", "URI",
Keccak.Compute("URI(string,uint256)").BytesToArray(), [
new("blockNumber", ValueTypes.Int, true),
new("timestamp", ValueTypes.Int, true),
new("transactionIndex", ValueTypes.Int, true),
new("logIndex", ValueTypes.Int, true),
new("value", ValueTypes.String, true),
new("id", ValueTypes.BigInt, true),
new("tokenAddress", ValueTypes.Address, true)
]);

public static readonly EventSchema ApprovalForAll =
EventSchema.FromSolidity(
Expand All @@ -57,7 +83,8 @@ public class DatabaseSchema : IDatabaseSchema
new("from", ValueTypes.Address, true),
new("to", ValueTypes.Address, true),
new("id", ValueTypes.BigInt, true),
new("value", ValueTypes.BigInt, false)
new("value", ValueTypes.BigInt, false),
new("tokenAddress", ValueTypes.Address, true)
]);

public static readonly EventSchema Erc20WrapperTransfer = new("CrcV2", "Erc20WrapperTransfer",
Expand Down Expand Up @@ -101,8 +128,9 @@ public class DatabaseSchema : IDatabaseSchema
new("operator", ValueTypes.Address, true),
new("from", ValueTypes.Address, true),
new("to", ValueTypes.Address, true),
new("id", ValueTypes.BigInt, false),
new("amount", ValueTypes.BigInt, false)
new("id", ValueTypes.BigInt, true),
new("amount", ValueTypes.BigInt, false),
new("tokenAddress", ValueTypes.Address, true)
]);

public IDictionary<(string Namespace, string Table), EventSchema> Tables { get; } =
Expand Down Expand Up @@ -306,7 +334,8 @@ public DatabaseSchema()
{ "from", e => e.From },
{ "to", e => e.To },
{ "id", e => (BigInteger)e.Id },
{ "value", e => (BigInteger)e.Value }
{ "value", e => (BigInteger)e.Value },
{ "tokenAddress", e => ConversionUtils.UInt256ToAddress(e.Id).ToString(true, false) }
});

EventDtoTableMap.Add<TransferBatch>(("CrcV2", "TransferBatch"));
Expand All @@ -323,7 +352,8 @@ public DatabaseSchema()
{ "from", e => e.From },
{ "to", e => e.To },
{ "id", e => (BigInteger)e.Id },
{ "value", e => (BigInteger)e.Value }
{ "value", e => (BigInteger)e.Value },
{ "tokenAddress", e => ConversionUtils.UInt256ToAddress(e.Id).ToString(true, false) }
});

EventDtoTableMap.Add<URI>(("CrcV2", "URI"));
Expand All @@ -336,7 +366,8 @@ public DatabaseSchema()
{ "logIndex", e => e.LogIndex },
{ "transactionHash", e => e.TransactionHash },
{ "value", e => e.Value },
{ "id", e => (BigInteger)e.Id }
{ "id", e => (BigInteger)e.Id },
{ "tokenAddress", e => ConversionUtils.UInt256ToAddress(e.Id).ToString(true, false) }
});

EventDtoTableMap.Add<ERC20WrapperDeployed>(("CrcV2", "ERC20WrapperDeployed"));
Expand Down Expand Up @@ -438,7 +469,8 @@ public DatabaseSchema()
{ "from", e => e.From },
{ "to", e => e.To },
{ "id", e => (BigInteger)e.Id },
{ "amount", e => (BigInteger)e.Amount }
{ "amount", e => (BigInteger)e.Amount },
{ "tokenAddress", e => ConversionUtils.UInt256ToAddress(e.Id).ToString(true, false) }
});
}
}
152 changes: 82 additions & 70 deletions Circles.Index.CirclesViews/DatabaseSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,42 +103,45 @@ UNION ALL
{
SqlMigrationItem = new SqlMigrationItem(@"
create or replace view public.""V_CrcV1_Transfers""
(""blockNumber"", timestamp, ""transactionIndex"", ""logIndex"", ""transactionHash"", ""from"", ""to"", ""tokenAddress"",
amount, type) as
(""blockNumber"", timestamp, ""transactionIndex"", ""logIndex"", ""transactionHash"", ""from"", ""to"", ""tokenAddress"",
amount, type)
as
WITH ""allTransfers"" AS (SELECT ""CrcV1_HubTransfer"".""blockNumber"",
""CrcV1_HubTransfer"".""timestamp"",
""CrcV1_HubTransfer"".""transactionIndex"",
""CrcV1_HubTransfer"".""logIndex"",
""CrcV1_HubTransfer"".""transactionHash"",
""CrcV1_HubTransfer"".""from"",
""CrcV1_HubTransfer"".""to"",
NULL::text AS ""tokenAddress"",
""CrcV1_HubTransfer"".amount,
'CrcV1_HubTransfer' as type
FROM ""CrcV1_HubTransfer""
UNION ALL
SELECT t.""blockNumber"",
t.""timestamp"",
t.""transactionIndex"",
t.""logIndex"",
t.""transactionHash"",
t.""from"",
t.""to"",
t.""tokenAddress"",
t.amount,
'CrcV1_Transfer' as type
FROM ""CrcV1_Transfer"" t)
SELECT ""blockNumber"",
""timestamp"",
""transactionIndex"",
""logIndex"",
""transactionHash"",
""from"",
""to"",
""tokenAddress"",
amount,
type
FROM ""allTransfers""
""CrcV1_HubTransfer"".""timestamp"",
""CrcV1_HubTransfer"".""transactionIndex"",
""CrcV1_HubTransfer"".""logIndex"",
""CrcV1_HubTransfer"".""transactionHash"",
""CrcV1_HubTransfer"".""from"",
""CrcV1_HubTransfer"".""to"",
NULL::text AS ""tokenAddress"",
""CrcV1_HubTransfer"".amount,
'CrcV1_HubTransfer'::text AS type
FROM ""CrcV1_HubTransfer""
UNION ALL
SELECT t.""blockNumber"",
t.""timestamp"",
t.""transactionIndex"",
t.""logIndex"",
t.""transactionHash"",
t.""from"",
t.""to"",
t.""tokenAddress"",
t.amount,
'CrcV1_Transfer'::text AS type
FROM ""CrcV1_Transfer"" t)
SELECT t.""blockNumber"",
t.""timestamp"",
t.""transactionIndex"",
t.""logIndex"",
t.""transactionHash"",
t.""from"",
t.""to"",
t.""tokenAddress"",
t.amount,
t.type,
tt.type as ""tokenType""
FROM ""allTransfers"" t
LEFT JOIN ""V_Crc_Tokens"" tt on tt.token = t.""tokenAddress""
ORDER BY ""blockNumber"" DESC, ""transactionIndex"" DESC, ""logIndex"" DESC;
")
};
Expand Down Expand Up @@ -235,9 +238,9 @@ LEFT JOIN (SELECT cid_1.avatar,
])
{
SqlMigrationItem = new SqlMigrationItem(@"
create or replace view public.""V_CrcV2_Transfers""
(""blockNumber"", timestamp, ""transactionIndex"", ""logIndex"", ""batchIndex"", ""transactionHash"", operator,
""from"", ""to"", id, value, type)
create or replace view public.""V_CrcV2_Transfers""
(""blockNumber"", timestamp, ""transactionIndex"", ""logIndex"", ""batchIndex"", ""transactionHash"", operator,
""from"", ""to"", id, value, type)
as
WITH ""allTransfers"" AS (SELECT ""CrcV2_TransferSingle"".""blockNumber"",
""CrcV2_TransferSingle"".""timestamp"",
Expand All @@ -250,7 +253,8 @@ create or replace view public.""V_CrcV2_Transfers""
""CrcV2_TransferSingle"".""to"",
""CrcV2_TransferSingle"".id::text AS id,
""CrcV2_TransferSingle"".value,
'CrcV2_TransferSingle'::text AS type
'CrcV2_TransferSingle'::text AS type,
""tokenAddress""
FROM ""CrcV2_TransferSingle""
UNION ALL
SELECT ""CrcV2_TransferBatch"".""blockNumber"",
Expand All @@ -264,7 +268,8 @@ UNION ALL
""CrcV2_TransferBatch"".""to"",
""CrcV2_TransferBatch"".id::text AS id,
""CrcV2_TransferBatch"".value,
'CrcV2_TransferBatch'::text AS type
'CrcV2_TransferBatch'::text AS type,
""tokenAddress""
FROM ""CrcV2_TransferBatch""
UNION ALL
SELECT ""CrcV2_Erc20WrapperTransfer"".""blockNumber"",
Expand All @@ -278,21 +283,25 @@ UNION ALL
""CrcV2_Erc20WrapperTransfer"".""to"",
""CrcV2_Erc20WrapperTransfer"".""tokenAddress"" AS id,
""CrcV2_Erc20WrapperTransfer"".amount AS value,
'CrcV2_Erc20WrapperTransfer'::text AS type
'CrcV2_Erc20WrapperTransfer'::text AS type,
""tokenAddress""
FROM ""CrcV2_Erc20WrapperTransfer"")
SELECT ""blockNumber"",
""timestamp"",
""transactionIndex"",
""logIndex"",
""batchIndex"",
""transactionHash"",
operator,
""from"",
""to"",
id,
value,
type
FROM ""allTransfers""
SELECT t.""blockNumber"",
t.""timestamp"",
t.""transactionIndex"",
t.""logIndex"",
t.""batchIndex"",
t.""transactionHash"",
t.operator,
t.""from"",
t.""to"",
t.id,
t.value,
t.type,
t.""tokenAddress"",
tt.type as ""tokenType""
FROM ""allTransfers"" t
JOIN ""V_Crc_Tokens"" tt on tt.token = t.""tokenAddress""
ORDER BY ""blockNumber"" DESC, ""transactionIndex"" DESC, ""logIndex"" DESC, ""batchIndex"" DESC;
")
};
Expand Down Expand Up @@ -498,7 +507,8 @@ create or replace view public.""V_Crc_Transfers""
""V_CrcV1_Transfers"".""to"",
""V_CrcV1_Transfers"".""tokenAddress"" AS id,
""V_CrcV1_Transfers"".amount AS value,
""V_CrcV1_Transfers"".type
""V_CrcV1_Transfers"".type,
""V_CrcV1_Transfers"".""tokenType""
FROM ""V_CrcV1_Transfers""
UNION ALL
SELECT ""V_CrcV2_Transfers"".""blockNumber"",
Expand All @@ -513,7 +523,8 @@ UNION ALL
""V_CrcV2_Transfers"".""to"",
""V_CrcV2_Transfers"".id,
""V_CrcV2_Transfers"".value,
""V_CrcV2_Transfers"".type
""V_CrcV2_Transfers"".type,
""V_CrcV2_Transfers"".""tokenType""
FROM ""V_CrcV2_Transfers"")
SELECT ""blockNumber"",
""timestamp"",
Expand All @@ -527,8 +538,9 @@ UNION ALL
""to"",
id,
value,
type
FROM ""allTransfers"";
type,
""tokenType""
FROM ""allTransfers"" t;
")
};

Expand Down Expand Up @@ -717,18 +729,10 @@ union all
("V_CrcV1", "Avatars"),
V_CrcV1_Avatars
},
{
("V_CrcV1", "Transfers"),
V_CrcV1_Transfers
},
{
("V_CrcV2", "Avatars"),
V_CrcV2_Avatars
},
{
("V_CrcV2", "Transfers"),
V_CrcV2_Transfers
},
{
("V_CrcV2", "TrustRelations"),
V_CrcV2_TrustRelations
Expand All @@ -741,6 +745,18 @@ union all
("V_Crc", "Avatars"),
V_Crc_Avatars
},
{
("V_Crc", "Tokens"),
V_Crc_Tokens
},
{
("V_CrcV1", "Transfers"),
V_CrcV1_Transfers
},
{
("V_CrcV2", "Transfers"),
V_CrcV2_Transfers
},
{
("V_Crc", "TrustRelations"),
V_Crc_TrustRelations
Expand All @@ -756,10 +772,6 @@ union all
{
("V_CrcV2", "BalancesByAccountAndToken"),
V_CrcV2_BalancesByAccountAndToken
},
{
("V_Crc", "Tokens"),
V_Crc_Tokens
}
};
}
2 changes: 1 addition & 1 deletion docker-compose.gnosis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ services:
- V2_STANDARD_TREASURY_ADDRESS=0xbb76CF35ec106c5c7a447246257dcfCB7244cA04
- V2_ERC20_LIFT_ADDRESS=0xB6B79BeEfd58cf33b298A456934554cf440354aD
- POSTGRES_CONNECTION_STRING=Server=postgres-gnosis;Port=5432;Database=postgres;User Id=${POSTGRES_USER};Password=${POSTGRES_PASSWORD};
- START_BLOCK=12000000
- START_BLOCK=35700000

postgres-gnosis:
image: postgres:16
Expand Down

0 comments on commit a22bc20

Please sign in to comment.