Skip to content

Commit

Permalink
Added block slot time to all events
Browse files Browse the repository at this point in the history
  • Loading branch information
schwartz-concordium committed Sep 8, 2023
1 parent 282839d commit 3492061
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public void Configure(EntityTypeBuilder<Entities.Contract> builder)
.HasConversion<AccountAddressConverter>();
builder.Property(x => x.Source)
.HasColumnName("source");
builder.Property(x => x.BlockSlotTime)
.HasColumnName("block_slot_time");
builder.Property(x => x.CreatedAt)
.HasColumnName("created_at");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public void Configure(EntityTypeBuilder<ContractEvent> builder)
.HasConversion<TransactionResultEventToJsonConverter>();
builder.Property(x => x.Source)
.HasColumnName("source");
builder.Property(x => x.BlockSlotTime)
.HasColumnName("block_slot_time");
builder.Property(x => x.CreatedAt)
.HasColumnName("created_at");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public void Configure(EntityTypeBuilder<ModuleReferenceContractLinkEvent> 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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public void Configure(EntityTypeBuilder<ModuleReferenceEvent> 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");
}
Expand Down
43 changes: 29 additions & 14 deletions backend/Application/Aggregates/Contract/ContractAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ await StoreEvent(
transactionResultEvent,
AccountAddress.From(details.Sender),
blockInfo.BlockHeight,
blockInfo.BlockSlotTime,
transactionHash,
blockItemSummary.Index,
eventIndex
Expand Down Expand Up @@ -149,6 +150,7 @@ internal static async Task StoreEvent(
TransactionResultEvent transactionResultEvent,
AccountAddress sender,
ulong blockHeight,
DateTimeOffset blockSlotTime,
string transactionHash,
ulong transactionIndex,
uint eventIndex
Expand All @@ -164,7 +166,8 @@ await repository.AddAsync(new Entities.Contract(
eventIndex,
contractInitialized.ContractAddress,
sender,
source
source,
blockSlotTime
));
await repository
.AddAsync(new ContractEvent(
Expand All @@ -174,7 +177,8 @@ await repository
eventIndex,
contractInitialized.ContractAddress,
contractInitialized,
source
source,
blockSlotTime
));
await repository
.AddAsync(new ModuleReferenceContractLinkEvent(
Expand All @@ -185,7 +189,8 @@ await repository
contractInitialized.ModuleRef,
contractInitialized.ContractAddress,
source,
ModuleReferenceContractLinkEvent.ModuleReferenceContractLinkAction.Added
ModuleReferenceContractLinkEvent.ModuleReferenceContractLinkAction.Added,
blockSlotTime
));
break;
case ContractInterrupted contractInterrupted:
Expand All @@ -197,7 +202,8 @@ await repository
eventIndex,
contractInterrupted.ContractAddress,
contractInterrupted,
source
source,
blockSlotTime
));
break;
case ContractResumed contractResumed:
Expand All @@ -209,7 +215,8 @@ await repository
eventIndex,
contractResumed.ContractAddress,
contractResumed,
source
source,
blockSlotTime
));
break;
case ContractUpdated contractUpdated:
Expand All @@ -221,8 +228,9 @@ await repository
eventIndex,
contractUpdated.ContractAddress,
contractUpdated,
source
));
source,
blockSlotTime
));
if (contractUpdated.Instigator is ContractAddress contractInstigator && contractUpdated.Amount != 0)
{
await repository
Expand All @@ -237,7 +245,8 @@ await repository
contractInstigator,
contractUpdated.ContractAddress
),
source
source,
blockSlotTime
));
}
break;
Expand All @@ -250,7 +259,8 @@ await repository
eventIndex,
contractUpgraded.ContractAddress,
contractUpgraded,
source
source,
blockSlotTime
));
await repository
.AddAsync(new ModuleReferenceContractLinkEvent(
Expand All @@ -261,7 +271,8 @@ await repository
contractUpgraded.To,
contractUpgraded.ContractAddress,
source,
ModuleReferenceContractLinkEvent.ModuleReferenceContractLinkAction.Added
ModuleReferenceContractLinkEvent.ModuleReferenceContractLinkAction.Added,
blockSlotTime
));
await repository
.AddAsync(new ModuleReferenceContractLinkEvent(
Expand All @@ -272,7 +283,8 @@ await repository
contractUpgraded.From,
contractUpgraded.ContractAddress,
source,
ModuleReferenceContractLinkEvent.ModuleReferenceContractLinkAction.Removed
ModuleReferenceContractLinkEvent.ModuleReferenceContractLinkAction.Removed,
blockSlotTime
));
break;
case Transferred transferred:
Expand All @@ -286,7 +298,8 @@ await repository
eventIndex,
contractAddressFrom,
transferred,
source
source,
blockSlotTime
));
}
if (transferred.To is ContractAddress contractAddressTo)
Expand All @@ -299,7 +312,8 @@ await repository
eventIndex,
contractAddressTo,
transferred,
source
source,
blockSlotTime
));
}
break;
Expand All @@ -311,7 +325,8 @@ await repository
transactionIndex,
eventIndex,
contractModuleDeployed.ModuleRef,
source
source,
blockSlotTime
));
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public async Task<IList<TransactionResultEventDto>> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
5 changes: 4 additions & 1 deletion backend/Application/Aggregates/Contract/Entities/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContractEvent> ContractEvents { get; set; }

Expand All @@ -40,7 +41,8 @@ internal Contract(
uint eventIndex,
ContractAddress contractAddress,
AccountAddress creator,
ImportSource source)
ImportSource source,
DateTimeOffset blockSlotTime)
{
BlockHeight = blockHeight;
TransactionHash = transactionHash;
Expand All @@ -50,6 +52,7 @@ internal Contract(
ContractAddressIndex = contractAddress.Index;
ContractAddressSubIndex = contractAddress.SubIndex;
Source = source;
BlockSlotTime = blockSlotTime;
}

[ExtendObjectType(typeof(Query))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
Expand All @@ -32,7 +33,8 @@ internal ContractEvent(
uint eventIndex,
ContractAddress contractAddress,
TransactionResultEvent @event,
ImportSource source)
ImportSource source,
DateTimeOffset blockSlotTime)
{
BlockHeight = blockHeight;
TransactionHash = transactionHash;
Expand All @@ -42,5 +44,6 @@ internal ContractEvent(
ContractAddressSubIndex = contractAddress.SubIndex;
Event = @event;
Source = source;
BlockSlotTime = blockSlotTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
Expand All @@ -35,7 +36,8 @@ public ModuleReferenceContractLinkEvent(
string moduleReference,
ContractAddress contractAddress,
ImportSource source,
ModuleReferenceContractLinkAction linkAction
ModuleReferenceContractLinkAction linkAction,
DateTimeOffset blockSlotTime
)
{
BlockHeight = blockHeight;
Expand All @@ -47,6 +49,7 @@ ModuleReferenceContractLinkAction linkAction
ContractAddressSubIndex = contractAddress.SubIndex;
Source = source;
LinkAction = linkAction;
BlockSlotTime = blockSlotTime;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
Expand All @@ -27,7 +28,8 @@ public ModuleReferenceEvent(
ulong transactionIndex,
uint eventIndex,
string moduleReference,
ImportSource source
ImportSource source,
DateTimeOffset blockSlotTime
)
{
BlockHeight = blockHeight;
Expand All @@ -36,5 +38,6 @@ ImportSource source
EventIndex = eventIndex;
ModuleReference = moduleReference;
Source = source;
BlockSlotTime = blockSlotTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ await ContractAggregate.StoreEvent(
eventDto.Event,
eventDto.TransactionSender!,
(ulong)eventDto.BlockHeight,
eventDto.BlockSlotTime.ToUniversalTime(),
eventDto.TransactionHash,
eventDto.TransactionIndex,
eventDto.TransactionEventIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions backend/Tests/Aggregates/Contract/ContractAggregateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ await ContractAggregate.StoreEvent(
transfer,
new AccountAddress(""),
1UL,
DateTimeOffset.Now,
"",
1UL,
1U);
Expand Down Expand Up @@ -77,6 +78,7 @@ await ContractAggregate.StoreEvent(
transfer,
new AccountAddress(""),
1UL,
DateTimeOffset.Now,
"",
1UL,
1U);
Expand Down Expand Up @@ -119,6 +121,7 @@ await ContractAggregate.StoreEvent(
contractUpdated,
new AccountAddress(""),
1UL,
DateTimeOffset.Now,
"",
1UL,
1U);
Expand Down Expand Up @@ -158,6 +161,7 @@ await ContractAggregate.StoreEvent(
contractUpdated,
new AccountAddress(""),
1UL,
DateTimeOffset.Now,
"",
1UL,
1U);
Expand Down

0 comments on commit 3492061

Please sign in to comment.