Skip to content

Commit

Permalink
feat: add ContractAddress to transaction info
Browse files Browse the repository at this point in the history
  • Loading branch information
petarTxFusion committed Dec 10, 2024
1 parent 8de30cf commit d88f9fb
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export const normalizeAddressTransformer: ValueTransformer = {
if (!hex) {
return null;
}
if (hexTransformer.from(hex) === "0x") {
return "";
}
return getAddress(hexTransformer.from(hex));
},
};
8 changes: 8 additions & 0 deletions packages/api/src/transaction/dtos/transaction.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,12 @@ export class TransactionDto {
nullable: true,
})
public readonly isEvmLike?: boolean;

@ApiProperty({
type: String,
description: "Address of the first deployed EVM contract",
example: "0xc7e0220d02d549c4846A6EC31D89C3B670Ebe35C",
nullable: true,
})
public readonly contractAddress?: string;
}
3 changes: 3 additions & 0 deletions packages/api/src/transaction/entities/transaction.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ export class Transaction extends BaseEntity {
@Column({ type: "boolean", nullable: true })
public readonly isEvmLike?: boolean;

@Column({ type: "bytea", transformer: hexTransformer, nullable: true })
public readonly contractAddress?: string;

public get status(): TransactionStatus {
if (this.receiptStatus === 0) {
return TransactionStatus.Failed;
Expand Down
23 changes: 23 additions & 0 deletions packages/api/test/transaction.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4009",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e19",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: false,
isL1Originated: true,
l1BatchNumber: 9,
Expand Down Expand Up @@ -298,6 +299,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4008",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e18",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: true,
isL1Originated: true,
l1BatchNumber: 8,
Expand Down Expand Up @@ -327,6 +329,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4007",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e17",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: true,
isL1Originated: true,
l1BatchNumber: 7,
Expand Down Expand Up @@ -356,6 +359,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4006",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e16",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: true,
isL1Originated: true,
l1BatchNumber: 6,
Expand Down Expand Up @@ -385,6 +389,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4005",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e15",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: true,
isL1Originated: true,
l1BatchNumber: 5,
Expand Down Expand Up @@ -414,6 +419,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4004",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e14",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: true,
isL1Originated: true,
l1BatchNumber: 4,
Expand Down Expand Up @@ -443,6 +449,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4003",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e13",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: true,
isL1Originated: true,
l1BatchNumber: 3,
Expand Down Expand Up @@ -472,6 +479,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4002",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e12",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: false,
isL1Originated: true,
l1BatchNumber: 1,
Expand Down Expand Up @@ -501,6 +509,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4001",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e11",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: false,
isL1Originated: true,
l1BatchNumber: 1,
Expand Down Expand Up @@ -530,6 +539,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4000",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e10",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: false,
isL1Originated: true,
l1BatchNumber: 1,
Expand Down Expand Up @@ -569,6 +579,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4008",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e18",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: true,
isL1Originated: true,
l1BatchNumber: 8,
Expand Down Expand Up @@ -598,6 +609,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4007",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e17",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: true,
isL1Originated: true,
l1BatchNumber: 7,
Expand Down Expand Up @@ -627,6 +639,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4006",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e16",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: true,
isL1Originated: true,
l1BatchNumber: 6,
Expand Down Expand Up @@ -712,6 +725,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4001",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e11",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: false,
isL1Originated: true,
l1BatchNumber: 1,
Expand Down Expand Up @@ -766,6 +780,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4001",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e11",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: false,
isL1Originated: true,
l1BatchNumber: 1,
Expand Down Expand Up @@ -820,6 +835,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4007",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e17",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: true,
isL1Originated: true,
l1BatchNumber: 7,
Expand Down Expand Up @@ -849,6 +865,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4006",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e16",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: true,
isL1Originated: true,
l1BatchNumber: 6,
Expand Down Expand Up @@ -940,6 +957,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4008",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e18",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: true,
isL1Originated: true,
l1BatchNumber: 8,
Expand Down Expand Up @@ -978,6 +996,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4005",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e15",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: true,
isL1Originated: true,
l1BatchNumber: 5,
Expand Down Expand Up @@ -1016,6 +1035,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4003",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e13",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: true,
isL1Originated: true,
l1BatchNumber: 3,
Expand Down Expand Up @@ -1054,6 +1074,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4000",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e10",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: true,
isL1Originated: true,
l1BatchNumber: 1,
Expand Down Expand Up @@ -1092,6 +1113,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4009",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e19",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: true,
isL1Originated: true,
l1BatchNumber: 9,
Expand Down Expand Up @@ -1130,6 +1152,7 @@ describe("TransactionController (e2e)", () => {
maxPriorityFeePerGas: "4000",
hash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e10",
isEvmLike: null,
contractAddress: null,
isL1BatchSealed: true,
isL1Originated: true,
l1BatchNumber: 1,
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/composables/common/Api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ declare namespace Api {
error: string | null;
revertReason: string | null;
isEvmLike: boolean;
contractAddress: string | null;
};

type Transfer = {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/composables/useTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export function mapTransaction(
},
value: transaction.value,
from: transaction.from,
to: transaction.to,
to: transaction.isEvmLike && transaction.contractAddress ? transaction.contractAddress : transaction.to,
ethCommitTxHash: transaction.commitTxHash ?? null,
ethExecuteTxHash: transaction.executeTxHash ?? null,
ethProveTxHash: transaction.proveTxHash ?? null,
Expand Down
1 change: 1 addition & 0 deletions packages/app/tests/components/transactions/Table.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const transaction: TransactionListItem = {
maxFeePerGas: "7000",
maxPriorityFeePerGas: "8000",
isEvmLike: true,
contractAddress: null,
error: null,
revertReason: null,
};
Expand Down
1 change: 1 addition & 0 deletions packages/app/tests/composables/useTransactions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const transaction: TransactionListItem = {
maxFeePerGas: "7000",
maxPriorityFeePerGas: "8000",
isEvmLike: true,
contractAddress: null,
error: null,
revertReason: null,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ describe("TransactionService", () => {
revertReason: traceTransactionResult.revertReason,
isEvmLike: false,
to: undefined,
contractAddress: null,
});
});
});
Expand All @@ -200,6 +201,7 @@ describe("TransactionService", () => {
receiptStatus: 0,
isEvmLike: false,
to: undefined,
contractAddress: null,
});
});
});
Expand Down
7 changes: 5 additions & 2 deletions packages/data-fetcher/src/transaction/transaction.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface TransactionInfo extends types.TransactionResponse {
error?: string;
revertReason?: string;
isEvmLike?: boolean;
contractAddress?: string;
}

export interface TransactionData extends LogsData {
Expand Down Expand Up @@ -81,13 +82,15 @@ export class TransactionService {
);

const isEvmLike = transactionInfo.to === null;
const toAddress =
isEvmLike && logsData.contractAddresses?.length > 0 ? logsData.contractAddresses[0].address : transactionInfo.to;
const toAddress = isEvmLike ? "0x" : transactionInfo.to;
const contractAddress =
isEvmLike && logsData.contractAddresses?.length > 0 ? logsData.contractAddresses[0].address : "";

const updatedTransactionInfo = {
...transactionInfo,
isEvmLike,
to: toAddress,
contractAddress,
} as unknown as TransactionInfo;

stopTransactionProcessingMeasuring();
Expand Down
1 change: 1 addition & 0 deletions packages/worker/src/dataFetcher/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export interface TransactionInfo
error?: string;
revertReason?: string;
isEvmLike?: boolean;
contractAddress?: string;
}

export type TransactionReceipt = Modify<
Expand Down
3 changes: 3 additions & 0 deletions packages/worker/src/entities/transaction.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,7 @@ export class Transaction extends CountableEntity {

@Column({ type: "boolean", nullable: true })
public readonly isEvmLike?: boolean;

@Column({ type: "bytea", transformer: hexTransformer, nullable: true })
public readonly contractAddress?: string;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class AddContractAddressFieldToTransaction1733778459691 implements MigrationInterface {
name = "AddContractAddressFieldToTransaction1733778459691";

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "transactions" ADD "contractAddress" bytea`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "transactions" DROP COLUMN "contractAddress"`);
}
}
2 changes: 2 additions & 0 deletions packages/worker/src/transaction/transaction.processor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ describe("TransactionProcessor", () => {
receivedAt: "2023-12-29T06:52:51.438Z",
type: 3,
isEvmLike: false,
contractAddress: null,
},
transactionReceipt: {
hash: "transactionHash",
Expand Down Expand Up @@ -137,6 +138,7 @@ describe("TransactionProcessor", () => {
effectiveGasPrice: transactionData.transactionReceipt.gasPrice,
type: transactionData.transaction.type,
isEvmLike: transactionData.transaction.isEvmLike,
contractAddress: transactionData.transaction.contractAddress,
});
});

Expand Down
1 change: 1 addition & 0 deletions packages/worker/src/transaction/transaction.processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class TransactionProcessor {
...transactionData.transaction,
transactionIndex: transactionData.transaction.index,
isEvmLike: transactionData.transaction.isEvmLike,
contractAddress: transactionData.transaction.contractAddress,
});

this.logger.debug({
Expand Down

0 comments on commit d88f9fb

Please sign in to comment.