/ src / models / SqueezedStreamsEventModel.ts
SqueezedStreamsEventModel.ts
 1  import type {
 2    InferAttributes,
 3    InferCreationAttributes,
 4    Sequelize,
 5  } from 'sequelize';
 6  import { DataTypes, Model } from 'sequelize';
 7  import getSchema from '../utils/getSchema';
 8  import type { IEventModel } from '../events/types';
 9  import type {
10    AccountId,
11    Address,
12    BigIntString,
13    StreamHistoryHashes,
14  } from '../core/types';
15  import { COMMON_EVENT_INIT_ATTRIBUTES } from '../core/constants';
16  
17  export default class SqueezedStreamsEventModel
18    extends Model<
19      InferAttributes<SqueezedStreamsEventModel>,
20      InferCreationAttributes<SqueezedStreamsEventModel>
21    >
22    implements IEventModel
23  {
24    declare public accountId: AccountId;
25    declare public erc20: Address;
26    declare public senderId: AccountId;
27    declare public amount: BigIntString;
28    declare public streamsHistoryHashes: StreamHistoryHashes;
29    declare public logIndex: number;
30    declare public blockNumber: number;
31    declare public blockTimestamp: Date;
32    declare public transactionHash: string;
33  
34    public static toStreamHistoryHashes(
35      streamsHistoryHashes: string[],
36    ): StreamHistoryHashes {
37      return JSON.stringify(streamsHistoryHashes) as StreamHistoryHashes;
38    }
39  
40    public static initialize(sequelize: Sequelize): void {
41      this.init(
42        {
43          accountId: {
44            allowNull: false,
45            type: DataTypes.STRING,
46          },
47          erc20: {
48            allowNull: false,
49            type: DataTypes.STRING,
50          },
51          senderId: {
52            allowNull: false,
53            type: DataTypes.STRING,
54          },
55          amount: {
56            allowNull: false,
57            type: DataTypes.STRING,
58          },
59          streamsHistoryHashes: {
60            allowNull: false,
61            type: DataTypes.JSON,
62          },
63          ...COMMON_EVENT_INIT_ATTRIBUTES,
64        },
65        {
66          sequelize,
67          schema: getSchema(),
68          tableName: 'squeezed_streams_events',
69          underscored: true,
70          timestamps: true,
71        },
72      );
73    }
74  }