import { BelongsTo, Column, DataType, ForeignKey, HasMany, HasOne, Index, Model, Table, } from 'sequelize-typescript'; import { LegacyTxTypes, TxStatus, TxTypes } from '../utils/enums'; import { Address } from './address'; import { Block } from './block'; import { Check } from './check'; import { Coin } from './coin'; import { EvmTransaction } from './evmTransaction'; import { MultisendTx } from './multisendTx'; import { MultisigTx } from './multisigTx'; import { TxFee } from './txFee'; @Table export class Tx extends Model { @Index({ name: 'tx-hash-index', using: 'HASH', }) @Column({ type: DataType.STRING }) hash: string; @Index({ name: 'tx-timestamp-index', using: 'BTREE', }) @Column(DataType.DATE) timestamp: Date; @Column(DataType.ENUM({ values: Object.values(TxStatus) })) status: TxStatus; @Column(DataType.ENUM({ values: [...Object.values(TxTypes), ...Object.values(LegacyTxTypes)] })) type: TxTypes | LegacyTxTypes; @HasOne(() => TxFee) fee: TxFee; @Column(DataType.JSONB) data: object; @Column({ type: DataType.INTEGER, allowNull: true }) nonce: number; @Column({ type: DataType.INTEGER, allowNull: true }) code: number; @Column({ type: DataType.TEXT, allowNull: true }) message: string; @Index({ name: 'tx-blockId-index', using: 'HASH', }) @ForeignKey(() => Block) @Column(DataType.INTEGER) blockId: number; @Index({ name: 'tx-from-index', using: 'HASH', }) @ForeignKey(() => Address) @Column(DataType.INTEGER) from: number; @Index({ name: 'tx-to-index', using: 'HASH', }) @ForeignKey(() => Address) @Column({ type: DataType.INTEGER, allowNull: true, defaultValue: null }) to: number; @BelongsTo(() => Block) block: Block; @HasMany(() => Check) hashTxCheck: Check[]; @HasMany(() => MultisendTx) hashTx: MultisendTx[]; @HasMany(() => MultisigTx) hashTxMultisig: MultisigTx[]; @BelongsTo(() => Address, 'from') sender: Address; @BelongsTo(() => Address, 'to') recipient: Address; @HasOne(() => Coin) coin: Coin; @HasOne(() => EvmTransaction) evmTransaction: EvmTransaction; }