import { BelongsTo, Column, DataType, ForeignKey, HasMany, HasOne, Index, Model, Table, } from 'sequelize-typescript'; import { IExtraData } from '../utils/interfaces'; import { EvmAccount } from './evmAccount'; import { EvmBlock } from './evmBlock'; import { EvmContract } from './evmContract'; import { EvmReceipt } from './evmReceipt'; import { EvmReceiptLog } from './evmReceiptLog'; import { EvmTokenEvent } from './evmTokenEvent'; import { Tx } from './tx'; @Table export class EvmTransaction extends Model { @Index({ name: 'evmTx-hash-index', using: 'HASH', }) @Column({ type: DataType.STRING }) hash: string; @Column(DataType.STRING) v: string; @Column(DataType.STRING) r: string; @Column(DataType.STRING) s: string; @Column(DataType.INTEGER) gas: number; @Column(DataType.SMALLINT) type: number; @Column(DataType.TEXT) input: string; @Column(DataType.INTEGER) nonce: number; @Column(DataType.STRING(64)) value: string; @Column(DataType.INTEGER) chainId: number; @Column(DataType.STRING) gasPrice: string; @Column({ type: DataType.JSONB, allowNull: true, defaultValue: null }) accessList: IExtraData[]; @Column(DataType.STRING) maxFeePerGas: string; @Column(DataType.STRING) maxPriorityFeePerGas: string; @Column({ type: DataType.JSONB, allowNull: true, defaultValue: null }) extraData: IExtraData; // relations M-1 @Index({ name: 'evmTx-from-index', using: 'HASH', }) @ForeignKey(() => EvmAccount) @Column(DataType.INTEGER) fromAccountId: number; @ForeignKey(() => Tx) @Column(DataType.INTEGER) txId: number; @Index({ name: 'evmTx-to-index', using: 'HASH', }) @ForeignKey(() => EvmAccount) @Column(DataType.INTEGER) toAccountId: number; @Index({ name: 'evmTx-block-index', using: 'BTREE', }) @ForeignKey(() => EvmBlock) @Column(DataType.INTEGER) evmBlockHeight: number; @BelongsTo(() => Tx, 'txId') tx: Tx; @BelongsTo(() => EvmAccount, 'fromAccountId') evmAccountFrom: EvmAccount; @BelongsTo(() => EvmAccount, 'toAccountId') evmAccountTo: EvmAccount; @BelongsTo(() => EvmBlock, 'evmBlockHeight') evmBlock: EvmBlock; // relations 1-M @HasMany(() => EvmReceiptLog, { foreignKey: 'evmTransactionId' }) evmReceiptLogs: EvmReceiptLog[]; @HasMany(() => EvmTokenEvent, { foreignKey: 'evmTransactionId' }) evmTokenEvents: EvmTokenEvent[]; // relations 1-1 @HasOne(() => EvmReceipt, { foreignKey: 'evmTransactionId' }) evmReceipt: EvmReceipt; @HasOne(() => EvmContract, { foreignKey: 'deploymentEvmTransactionId', constraints: false }) deployedEvmContract: EvmContract; @HasOne(() => EvmAccount, { foreignKey: 'creationEvmTransactionId', constraints: false }) createdEvmAccount: EvmAccount; }