From 3492061f15db6a9f358b5995799800c209a1abe0 Mon Sep 17 00:00:00 2001 From: schwartz-concordium <132270889+schwartz-concordium@users.noreply.github.com> Date: Fri, 8 Sep 2023 14:27:21 +0200 Subject: [PATCH] Added block slot time to all events --- .../ContractEntityTypeConfigurations.cs | 2 + .../ContractEventEntityTypeConfigurations.cs | 2 + ...ntractLinkEventEntityTypeConfigurations.cs | 2 + ...eReferenceEventEntityTypeConfigurations.cs | 2 + .../Aggregates/Contract/ContractAggregate.cs | 43 +++++++++++++------ .../Aggregates/Contract/ContractRepository.cs | 1 + .../Contract/Dto/TransactionResultEventDto.cs | 1 + .../Aggregates/Contract/Entities/Contract.cs | 5 ++- .../Contract/Entities/ContractEvent.cs | 5 ++- .../ModuleReferenceContractLinkEvent.cs | 5 ++- .../Contract/Entities/ModuleReferenceEvent.cs | 5 ++- .../Jobs/ContractDatabaseImportJob.cs | 1 + ...CreateTables_Smart_Contract_Aggregates.sql | 10 +++-- .../Contract/ContractAggregateTests.cs | 4 ++ 14 files changed, 67 insertions(+), 21 deletions(-) diff --git a/backend/Application/Aggregates/Contract/Configurations/ContractEntityTypeConfigurations.cs b/backend/Application/Aggregates/Contract/Configurations/ContractEntityTypeConfigurations.cs index 84bd55e33..e507169f2 100644 --- a/backend/Application/Aggregates/Contract/Configurations/ContractEntityTypeConfigurations.cs +++ b/backend/Application/Aggregates/Contract/Configurations/ContractEntityTypeConfigurations.cs @@ -32,6 +32,8 @@ public void Configure(EntityTypeBuilder builder) .HasConversion(); builder.Property(x => x.Source) .HasColumnName("source"); + builder.Property(x => x.BlockSlotTime) + .HasColumnName("block_slot_time"); builder.Property(x => x.CreatedAt) .HasColumnName("created_at"); diff --git a/backend/Application/Aggregates/Contract/Configurations/ContractEventEntityTypeConfigurations.cs b/backend/Application/Aggregates/Contract/Configurations/ContractEventEntityTypeConfigurations.cs index f66bf7bec..40e4ccbf7 100644 --- a/backend/Application/Aggregates/Contract/Configurations/ContractEventEntityTypeConfigurations.cs +++ b/backend/Application/Aggregates/Contract/Configurations/ContractEventEntityTypeConfigurations.cs @@ -36,6 +36,8 @@ public void Configure(EntityTypeBuilder builder) .HasConversion(); builder.Property(x => x.Source) .HasColumnName("source"); + builder.Property(x => x.BlockSlotTime) + .HasColumnName("block_slot_time"); builder.Property(x => x.CreatedAt) .HasColumnName("created_at"); } diff --git a/backend/Application/Aggregates/Contract/Configurations/ModuleReferenceContractLinkEventEntityTypeConfigurations.cs b/backend/Application/Aggregates/Contract/Configurations/ModuleReferenceContractLinkEventEntityTypeConfigurations.cs index 29501f386..faee09327 100644 --- a/backend/Application/Aggregates/Contract/Configurations/ModuleReferenceContractLinkEventEntityTypeConfigurations.cs +++ b/backend/Application/Aggregates/Contract/Configurations/ModuleReferenceContractLinkEventEntityTypeConfigurations.cs @@ -37,6 +37,8 @@ public void Configure(EntityTypeBuilder builde .HasColumnName("source"); builder.Property(x => x.LinkAction) .HasColumnName("link_action"); + builder.Property(x => x.BlockSlotTime) + .HasColumnName("block_slot_time"); builder.Property(x => x.CreatedAt) .HasColumnName("created_at"); } diff --git a/backend/Application/Aggregates/Contract/Configurations/ModuleReferenceEventEntityTypeConfigurations.cs b/backend/Application/Aggregates/Contract/Configurations/ModuleReferenceEventEntityTypeConfigurations.cs index 429bd11bb..522ddcdfa 100644 --- a/backend/Application/Aggregates/Contract/Configurations/ModuleReferenceEventEntityTypeConfigurations.cs +++ b/backend/Application/Aggregates/Contract/Configurations/ModuleReferenceEventEntityTypeConfigurations.cs @@ -25,6 +25,8 @@ public void Configure(EntityTypeBuilder builder) .HasColumnName("module_reference"); builder.Property(x => x.Source) .HasColumnName("source"); + builder.Property(x => x.BlockSlotTime) + .HasColumnName("block_slot_time"); builder.Property(x => x.CreatedAt) .HasColumnName("created_at"); } diff --git a/backend/Application/Aggregates/Contract/ContractAggregate.cs b/backend/Application/Aggregates/Contract/ContractAggregate.cs index 2cb124102..7087b15ec 100644 --- a/backend/Application/Aggregates/Contract/ContractAggregate.cs +++ b/backend/Application/Aggregates/Contract/ContractAggregate.cs @@ -107,6 +107,7 @@ await StoreEvent( transactionResultEvent, AccountAddress.From(details.Sender), blockInfo.BlockHeight, + blockInfo.BlockSlotTime, transactionHash, blockItemSummary.Index, eventIndex @@ -149,6 +150,7 @@ internal static async Task StoreEvent( TransactionResultEvent transactionResultEvent, AccountAddress sender, ulong blockHeight, + DateTimeOffset blockSlotTime, string transactionHash, ulong transactionIndex, uint eventIndex @@ -164,7 +166,8 @@ await repository.AddAsync(new Entities.Contract( eventIndex, contractInitialized.ContractAddress, sender, - source + source, + blockSlotTime )); await repository .AddAsync(new ContractEvent( @@ -174,7 +177,8 @@ await repository eventIndex, contractInitialized.ContractAddress, contractInitialized, - source + source, + blockSlotTime )); await repository .AddAsync(new ModuleReferenceContractLinkEvent( @@ -185,7 +189,8 @@ await repository contractInitialized.ModuleRef, contractInitialized.ContractAddress, source, - ModuleReferenceContractLinkEvent.ModuleReferenceContractLinkAction.Added + ModuleReferenceContractLinkEvent.ModuleReferenceContractLinkAction.Added, + blockSlotTime )); break; case ContractInterrupted contractInterrupted: @@ -197,7 +202,8 @@ await repository eventIndex, contractInterrupted.ContractAddress, contractInterrupted, - source + source, + blockSlotTime )); break; case ContractResumed contractResumed: @@ -209,7 +215,8 @@ await repository eventIndex, contractResumed.ContractAddress, contractResumed, - source + source, + blockSlotTime )); break; case ContractUpdated contractUpdated: @@ -221,8 +228,9 @@ await repository eventIndex, contractUpdated.ContractAddress, contractUpdated, - source - )); + source, + blockSlotTime + )); if (contractUpdated.Instigator is ContractAddress contractInstigator && contractUpdated.Amount != 0) { await repository @@ -237,7 +245,8 @@ await repository contractInstigator, contractUpdated.ContractAddress ), - source + source, + blockSlotTime )); } break; @@ -250,7 +259,8 @@ await repository eventIndex, contractUpgraded.ContractAddress, contractUpgraded, - source + source, + blockSlotTime )); await repository .AddAsync(new ModuleReferenceContractLinkEvent( @@ -261,7 +271,8 @@ await repository contractUpgraded.To, contractUpgraded.ContractAddress, source, - ModuleReferenceContractLinkEvent.ModuleReferenceContractLinkAction.Added + ModuleReferenceContractLinkEvent.ModuleReferenceContractLinkAction.Added, + blockSlotTime )); await repository .AddAsync(new ModuleReferenceContractLinkEvent( @@ -272,7 +283,8 @@ await repository contractUpgraded.From, contractUpgraded.ContractAddress, source, - ModuleReferenceContractLinkEvent.ModuleReferenceContractLinkAction.Removed + ModuleReferenceContractLinkEvent.ModuleReferenceContractLinkAction.Removed, + blockSlotTime )); break; case Transferred transferred: @@ -286,7 +298,8 @@ await repository eventIndex, contractAddressFrom, transferred, - source + source, + blockSlotTime )); } if (transferred.To is ContractAddress contractAddressTo) @@ -299,7 +312,8 @@ await repository eventIndex, contractAddressTo, transferred, - source + source, + blockSlotTime )); } break; @@ -311,7 +325,8 @@ await repository transactionIndex, eventIndex, contractModuleDeployed.ModuleRef, - source + source, + blockSlotTime )); break; } diff --git a/backend/Application/Aggregates/Contract/ContractRepository.cs b/backend/Application/Aggregates/Contract/ContractRepository.cs index 5210eece5..df5c3570e 100644 --- a/backend/Application/Aggregates/Contract/ContractRepository.cs +++ b/backend/Application/Aggregates/Contract/ContractRepository.cs @@ -67,6 +67,7 @@ public async Task> FromBlockHeightRangeGetContr const string sql = @" SELECT gb.block_height as BlockHeight, + gb.block_slot_time as BlockSlotTime, gt.transaction_type as TransactionType, gt.sender as TransactionSender, gt.transaction_hash as TransactionHash, diff --git a/backend/Application/Aggregates/Contract/Dto/TransactionResultEventDto.cs b/backend/Application/Aggregates/Contract/Dto/TransactionResultEventDto.cs index b61d50b51..4c58b28a5 100644 --- a/backend/Application/Aggregates/Contract/Dto/TransactionResultEventDto.cs +++ b/backend/Application/Aggregates/Contract/Dto/TransactionResultEventDto.cs @@ -9,6 +9,7 @@ namespace Application.Aggregates.Contract.Dto; public class TransactionResultEventDto { public int BlockHeight { get; init; } + public DateTimeOffset BlockSlotTime { get; init; } public TransactionTypeUnion TransactionType { get; init; } public AccountAddress? TransactionSender { get; init; } public string TransactionHash { get; init; } diff --git a/backend/Application/Aggregates/Contract/Entities/Contract.cs b/backend/Application/Aggregates/Contract/Entities/Contract.cs index 5489344f4..beb0193a8 100644 --- a/backend/Application/Aggregates/Contract/Entities/Contract.cs +++ b/backend/Application/Aggregates/Contract/Entities/Contract.cs @@ -24,6 +24,7 @@ public sealed class Contract public ulong ContractAddressSubIndex { get; init; } public AccountAddress Creator { get; init; } = null!; public ImportSource Source { get; init; } + public DateTimeOffset BlockSlotTime { get; init; } public DateTimeOffset CreatedAt { get; init; } = DateTime.UtcNow; public ICollection ContractEvents { get; set; } @@ -40,7 +41,8 @@ internal Contract( uint eventIndex, ContractAddress contractAddress, AccountAddress creator, - ImportSource source) + ImportSource source, + DateTimeOffset blockSlotTime) { BlockHeight = blockHeight; TransactionHash = transactionHash; @@ -50,6 +52,7 @@ internal Contract( ContractAddressIndex = contractAddress.Index; ContractAddressSubIndex = contractAddress.SubIndex; Source = source; + BlockSlotTime = blockSlotTime; } [ExtendObjectType(typeof(Query))] diff --git a/backend/Application/Aggregates/Contract/Entities/ContractEvent.cs b/backend/Application/Aggregates/Contract/Entities/ContractEvent.cs index 7d5fec284..f99822651 100644 --- a/backend/Application/Aggregates/Contract/Entities/ContractEvent.cs +++ b/backend/Application/Aggregates/Contract/Entities/ContractEvent.cs @@ -17,6 +17,7 @@ public sealed class ContractEvent public ulong ContractAddressSubIndex { get; init; } public TransactionResultEvent Event { get; init; } = null!; public ImportSource Source { get; init; } + public DateTimeOffset BlockSlotTime { get; init; } public DateTimeOffset CreatedAt { get; init; } = DateTime.UtcNow; /// @@ -32,7 +33,8 @@ internal ContractEvent( uint eventIndex, ContractAddress contractAddress, TransactionResultEvent @event, - ImportSource source) + ImportSource source, + DateTimeOffset blockSlotTime) { BlockHeight = blockHeight; TransactionHash = transactionHash; @@ -42,5 +44,6 @@ internal ContractEvent( ContractAddressSubIndex = contractAddress.SubIndex; Event = @event; Source = source; + BlockSlotTime = blockSlotTime; } } \ No newline at end of file diff --git a/backend/Application/Aggregates/Contract/Entities/ModuleReferenceContractLinkEvent.cs b/backend/Application/Aggregates/Contract/Entities/ModuleReferenceContractLinkEvent.cs index c0bd23614..3f0f8b7f2 100644 --- a/backend/Application/Aggregates/Contract/Entities/ModuleReferenceContractLinkEvent.cs +++ b/backend/Application/Aggregates/Contract/Entities/ModuleReferenceContractLinkEvent.cs @@ -19,6 +19,7 @@ public sealed class ModuleReferenceContractLinkEvent public ulong ContractAddressSubIndex { get; init; } public ImportSource Source { get; init; } public ModuleReferenceContractLinkAction LinkAction { get; init; } + public DateTimeOffset BlockSlotTime { get; init; } public DateTimeOffset CreatedAt { get; init; } = DateTime.UtcNow; /// @@ -35,7 +36,8 @@ public ModuleReferenceContractLinkEvent( string moduleReference, ContractAddress contractAddress, ImportSource source, - ModuleReferenceContractLinkAction linkAction + ModuleReferenceContractLinkAction linkAction, + DateTimeOffset blockSlotTime ) { BlockHeight = blockHeight; @@ -47,6 +49,7 @@ ModuleReferenceContractLinkAction linkAction ContractAddressSubIndex = contractAddress.SubIndex; Source = source; LinkAction = linkAction; + BlockSlotTime = blockSlotTime; } /// diff --git a/backend/Application/Aggregates/Contract/Entities/ModuleReferenceEvent.cs b/backend/Application/Aggregates/Contract/Entities/ModuleReferenceEvent.cs index b320e8db7..e63e55f15 100644 --- a/backend/Application/Aggregates/Contract/Entities/ModuleReferenceEvent.cs +++ b/backend/Application/Aggregates/Contract/Entities/ModuleReferenceEvent.cs @@ -13,6 +13,7 @@ public sealed class ModuleReferenceEvent public uint EventIndex { get; init; } public string ModuleReference { get; init; } = null!; public ImportSource Source { get; init; } + public DateTimeOffset BlockSlotTime { get; init; } public DateTimeOffset CreatedAt { get; init; } = DateTime.UtcNow; /// @@ -27,7 +28,8 @@ public ModuleReferenceEvent( ulong transactionIndex, uint eventIndex, string moduleReference, - ImportSource source + ImportSource source, + DateTimeOffset blockSlotTime ) { BlockHeight = blockHeight; @@ -36,5 +38,6 @@ ImportSource source EventIndex = eventIndex; ModuleReference = moduleReference; Source = source; + BlockSlotTime = blockSlotTime; } } \ No newline at end of file diff --git a/backend/Application/Aggregates/Contract/Jobs/ContractDatabaseImportJob.cs b/backend/Application/Aggregates/Contract/Jobs/ContractDatabaseImportJob.cs index 10a440fdb..a5fb488c3 100644 --- a/backend/Application/Aggregates/Contract/Jobs/ContractDatabaseImportJob.cs +++ b/backend/Application/Aggregates/Contract/Jobs/ContractDatabaseImportJob.cs @@ -178,6 +178,7 @@ await ContractAggregate.StoreEvent( eventDto.Event, eventDto.TransactionSender!, (ulong)eventDto.BlockHeight, + eventDto.BlockSlotTime.ToUniversalTime(), eventDto.TransactionHash, eventDto.TransactionIndex, eventDto.TransactionEventIndex diff --git a/backend/DatabaseScripts/SqlScripts/0044_CreateTables_Smart_Contract_Aggregates.sql b/backend/DatabaseScripts/SqlScripts/0044_CreateTables_Smart_Contract_Aggregates.sql index ce2a5b78b..289acb1f0 100644 --- a/backend/DatabaseScripts/SqlScripts/0044_CreateTables_Smart_Contract_Aggregates.sql +++ b/backend/DatabaseScripts/SqlScripts/0044_CreateTables_Smart_Contract_Aggregates.sql @@ -10,7 +10,8 @@ create table graphql_contracts contract_address_index bigint not null, contract_address_sub_index bigint not null, creator text not null, - source int not null, + source int not null, + block_slot_time TIMESTAMPTZ not null, created_at TIMESTAMPTZ not null, PRIMARY KEY ( contract_address_index, @@ -27,7 +28,8 @@ create table graphql_contract_events contract_address_index bigint not null, contract_address_sub_index bigint not null, event json not null, - source int not null, + source int not null, + block_slot_time TIMESTAMPTZ not null, created_at TIMESTAMPTZ not null, PRIMARY KEY ( block_height, @@ -45,7 +47,8 @@ create table graphql_module_reference_events transaction_index bigint not null, event_index bigint not null, module_reference text not null, - source int not null, + source int not null, + block_slot_time TIMESTAMPTZ not null, created_at TIMESTAMPTZ not null, PRIMARY KEY ( module_reference @@ -63,6 +66,7 @@ create table graphql_module_reference_contract_link_events contract_address_sub_index bigint not null, source int not null, link_action int not null, + block_slot_time TIMESTAMPTZ not null, created_at TIMESTAMPTZ not null, PRIMARY KEY ( block_height, diff --git a/backend/Tests/Aggregates/Contract/ContractAggregateTests.cs b/backend/Tests/Aggregates/Contract/ContractAggregateTests.cs index ed9699dc9..30e731371 100644 --- a/backend/Tests/Aggregates/Contract/ContractAggregateTests.cs +++ b/backend/Tests/Aggregates/Contract/ContractAggregateTests.cs @@ -43,6 +43,7 @@ await ContractAggregate.StoreEvent( transfer, new AccountAddress(""), 1UL, + DateTimeOffset.Now, "", 1UL, 1U); @@ -77,6 +78,7 @@ await ContractAggregate.StoreEvent( transfer, new AccountAddress(""), 1UL, + DateTimeOffset.Now, "", 1UL, 1U); @@ -119,6 +121,7 @@ await ContractAggregate.StoreEvent( contractUpdated, new AccountAddress(""), 1UL, + DateTimeOffset.Now, "", 1UL, 1U); @@ -158,6 +161,7 @@ await ContractAggregate.StoreEvent( contractUpdated, new AccountAddress(""), 1UL, + DateTimeOffset.Now, "", 1UL, 1U);