import { BelongsTo, Column, DataType, ForeignKey, HasMany, Index, Model, Table, } from 'sequelize-typescript'; import { Coin } from './coin'; import { Tx } from './tx'; import { Validator } from './validator'; @Table({ defaultScope: { attributes: { exclude: ['signedBy'], }, }, }) export class Block extends Model { @Column({ primaryKey: true, type: DataType.INTEGER }) height: number; @Column(DataType.DATE) date: Date; @Index({ name: 'block-hash-index', using: 'HASH', }) @Column(DataType.STRING) hash: string; @Column(DataType.DECIMAL) emission: string; @Column(DataType.INTEGER) size: number; @Column(DataType.DECIMAL) reward: string; @Column(DataType.FLOAT) blockTime: number; @Column(DataType.INTEGER) txsCount: number; @Column(DataType.INTEGER) validatorsCount: number; @HasMany(() => Validator) validators: Validator[]; @ForeignKey(() => Validator) @Column(DataType.INTEGER) proposerId: number; @HasMany(() => Tx) txs: Tx[]; @BelongsTo(() => Validator, { foreignKey: 'proposerId', constraints: false, }) proposer: Validator; @HasMany(() => Coin) coins: Coin[]; }