Skip to content

Commit

Permalink
Add contract code hash to events
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed Sep 19, 2022
1 parent 3125a07 commit 7cf428d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Tzkt.Data/Migrations/20220819172957_Kathmandu.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Tzkt.Data/Migrations/20220819172957_Kathmandu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Level = table.Column<int>(type: "integer", nullable: false),
ContractId = table.Column<int>(type: "integer", nullable: false),
ContractCodeHash = table.Column<int>(type: "integer", nullable: false),
TransactionId = table.Column<int>(type: "integer", nullable: false),
Tag = table.Column<string>(type: "text", nullable: true),
Type = table.Column<byte[]>(type: "bytea", nullable: true),
Expand Down Expand Up @@ -145,6 +146,16 @@ protected override void Up(MigrationBuilder migrationBuilder)
onDelete: ReferentialAction.Cascade);
});

migrationBuilder.CreateIndex(
name: "IX_Events_ContractCodeHash",
table: "Events",
column: "ContractCodeHash");

migrationBuilder.CreateIndex(
name: "IX_Events_ContractCodeHash_Tag",
table: "Events",
columns: new[] { "ContractCodeHash", "Tag" });

migrationBuilder.CreateIndex(
name: "IX_Events_ContractId",
table: "Events",
Expand Down
7 changes: 7 additions & 0 deletions Tzkt.Data/Migrations/TzktContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);

b.Property<int>("ContractCodeHash")
.HasColumnType("integer");

b.Property<int>("ContractId")
.HasColumnType("integer");

Expand All @@ -1037,6 +1040,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("Id");

b.HasIndex("ContractCodeHash");

b.HasIndex("ContractId");

b.HasIndex("Id")
Expand All @@ -1052,6 +1057,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasIndex("TransactionId");

b.HasIndex("ContractCodeHash", "Tag");

b.HasIndex("ContractId", "Tag");

b.ToTable("Events");
Expand Down
7 changes: 7 additions & 0 deletions Tzkt.Data/Models/Scripts/ContractEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class ContractEvent
public int Id { get; set; }
public int Level { get; set; }
public int ContractId { get; set; }
public int ContractCodeHash { get; set; }
public int TransactionId { get; set; }

public string Tag { get; set; }
Expand Down Expand Up @@ -41,6 +42,9 @@ public static void BuildContractEventModel(this ModelBuilder modelBuilder)
modelBuilder.Entity<ContractEvent>()
.HasIndex(x => x.ContractId);

modelBuilder.Entity<ContractEvent>()
.HasIndex(x => x.ContractCodeHash);

modelBuilder.Entity<ContractEvent>()
.HasIndex(x => x.TransactionId);

Expand All @@ -50,6 +54,9 @@ public static void BuildContractEventModel(this ModelBuilder modelBuilder)
modelBuilder.Entity<ContractEvent>()
.HasIndex(x => new { x.ContractId, x.Tag });

modelBuilder.Entity<ContractEvent>()
.HasIndex(x => new { x.ContractCodeHash, x.Tag });

modelBuilder.Entity<ContractEvent>()
.HasIndex(x => x.JsonPayload)
.HasMethod("gin")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public virtual async Task Apply(Block block, JsonElement content)
Id = Cache.AppState.NextOperationId(),
Level = block.Level,
ContractId = contract.Id,
ContractCodeHash = contract.CodeHash,
TransactionId = parentTx.Id,
Tag = content.RequiredString("tag")
};
Expand Down

0 comments on commit 7cf428d

Please sign in to comment.