Skip to content

Commit 8f49dea

Browse files
authored
Merge pull request #126 from hack-a-chain-software/fixes-backfill
fix: changes for the backfill
2 parents aceb26c + abcb69b commit 8f49dea

File tree

13 files changed

+205
-266
lines changed

13 files changed

+205
-266
lines changed

indexer/migrations/20241101010452-create-signer.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

indexer/migrations/20241101121618-create-public-keys-account.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

indexer/migrations/20241105001040-add-indexes-to-publickeysaccounts.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
module.exports = {
55
async up(queryInterface) {
66
await queryInterface.addIndex("PublicKeysAccounts", {
7-
name: "publickeysaccounts_publicKey_chainId_account_module_unique_idx",
7+
name: "publickeysaccounts_publickey_chainid_account_module_unique_idx",
88
fields: ["publicKey", "chainId", "account", "module"],
99
unique: true,
1010
});
1111

1212
await queryInterface.addIndex("PublicKeysAccounts", {
13-
name: "publicKey_idx",
13+
name: "publickeysaccounts_publickey_idx",
1414
fields: ["publicKey"],
1515
});
1616
},
@@ -21,6 +21,9 @@ module.exports = {
2121
"publickeysaccounts_publicKey_chainId_account_module_unique_idx",
2222
);
2323

24-
await queryInterface.removeIndex("PublicKeysAccounts", "publicKey_idx");
24+
await queryInterface.removeIndex(
25+
"PublicKeysAccounts",
26+
"publickeysaccounts_publickey_idx",
27+
);
2528
},
2629
};

indexer/src/models/event.ts

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface EventAttributes {
1414
paramtext: object;
1515
qualname: string;
1616
requestkey: string;
17+
orderIndex: number;
1718
}
1819

1920
/**
@@ -53,21 +54,78 @@ class Event extends Model<EventAttributes> implements EventAttributes {
5354
/** The request key of the event (e.g., "vyL1rMR_qbkoi8yUW3ktEeBU9XzdWSEaoe1GdPLL3j4"). */
5455
declare requestkey: string;
5556
declare transaction: Transaction;
57+
58+
declare orderIndex: number;
5659
}
5760

5861
Event.init(
5962
{
60-
id: { type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true, comment: "The unique identifier for the event record (e.g., 5985644)." },
61-
transactionId: { type: DataTypes.INTEGER, allowNull: true, comment: "The ID of the associated transaction (e.g., 4134355)." },
62-
payloadHash: { type: DataTypes.STRING, allowNull: false, comment: "The payload hash of the event (e.g., '3NzEURi0GMMMEwbAbNMrjAwoPR7hDwLROe5aLityoBo')." },
63-
chainId: { type: DataTypes.INTEGER, allowNull: false, comment: "The ID of the blockchain network (e.g., 0)." },
64-
module: { type: DataTypes.STRING, allowNull: false, comment: "The module associated with the event (e.g., 'coin')." },
65-
modulehash: { type: DataTypes.STRING, allowNull: false, comment: "The hash of the module (e.g., 'klFkrLfpyLW-M3xjVPSdqXEMgxPPJibRt_D6qiBws6s')." },
66-
name: { type: DataTypes.STRING, allowNull: false, comment: "The name of the event (e.g., 'TRANSFER')." },
67-
params: { type: DataTypes.JSONB, allowNull: false, comment: "The parameters of the event (e.g., ['k:ec48fcadd0649a4230800668ca5bb17d1a91f14daf87a56cb954964055994031', 'k:e7f7130f359fb1f8c87873bf858a0e9cbc3c1059f62ae715ec72e760b055e9f3', 0.000969])." },
68-
paramtext: { type: DataTypes.JSONB, allowNull: false, comment: "The text representation of the parameters (e.g., ['k:ec48fcadd0649a4230800668ca5bb17d1a91f14daf87a56cb954964055994031', 'k:e7f7130f359fb1f8c87873bf858a0e9cbc3c1059f62ae715ec72e760b055e9f3', 0.000969])." },
69-
qualname: { type: DataTypes.STRING, allowNull: false, comment: "The qualified name of the event (e.g., 'coin')." },
70-
requestkey: { type: DataTypes.STRING, allowNull: false, comment: "The request key of the event (e.g., 'vyL1rMR_qbkoi8yUW3ktEeBU9XzdWSEaoe1GdPLL3j4')." },
63+
id: {
64+
type: DataTypes.INTEGER,
65+
autoIncrement: true,
66+
primaryKey: true,
67+
comment: "The unique identifier for the event record (e.g., 5985644).",
68+
},
69+
transactionId: {
70+
type: DataTypes.INTEGER,
71+
allowNull: true,
72+
comment: "The ID of the associated transaction (e.g., 4134355).",
73+
},
74+
payloadHash: {
75+
type: DataTypes.STRING,
76+
allowNull: false,
77+
comment:
78+
"The payload hash of the event (e.g., '3NzEURi0GMMMEwbAbNMrjAwoPR7hDwLROe5aLityoBo').",
79+
},
80+
chainId: {
81+
type: DataTypes.INTEGER,
82+
allowNull: false,
83+
comment: "The ID of the blockchain network (e.g., 0).",
84+
},
85+
module: {
86+
type: DataTypes.STRING,
87+
allowNull: false,
88+
comment: "The module associated with the event (e.g., 'coin').",
89+
},
90+
modulehash: {
91+
type: DataTypes.STRING,
92+
allowNull: false,
93+
comment:
94+
"The hash of the module (e.g., 'klFkrLfpyLW-M3xjVPSdqXEMgxPPJibRt_D6qiBws6s').",
95+
},
96+
name: {
97+
type: DataTypes.STRING,
98+
allowNull: false,
99+
comment: "The name of the event (e.g., 'TRANSFER').",
100+
},
101+
params: {
102+
type: DataTypes.JSONB,
103+
allowNull: false,
104+
comment:
105+
"The parameters of the event (e.g., ['k:ec48fcadd0649a4230800668ca5bb17d1a91f14daf87a56cb954964055994031', 'k:e7f7130f359fb1f8c87873bf858a0e9cbc3c1059f62ae715ec72e760b055e9f3', 0.000969]).",
106+
},
107+
paramtext: {
108+
type: DataTypes.JSONB,
109+
allowNull: false,
110+
comment:
111+
"The text representation of the parameters (e.g., ['k:ec48fcadd0649a4230800668ca5bb17d1a91f14daf87a56cb954964055994031', 'k:e7f7130f359fb1f8c87873bf858a0e9cbc3c1059f62ae715ec72e760b055e9f3', 0.000969]).",
112+
},
113+
qualname: {
114+
type: DataTypes.STRING,
115+
allowNull: false,
116+
comment: "The qualified name of the event (e.g., 'coin').",
117+
},
118+
requestkey: {
119+
type: DataTypes.STRING,
120+
allowNull: false,
121+
comment:
122+
"The request key of the event (e.g., 'vyL1rMR_qbkoi8yUW3ktEeBU9XzdWSEaoe1GdPLL3j4').",
123+
},
124+
orderIndex: {
125+
type: DataTypes.INTEGER,
126+
allowNull: true,
127+
comment: "The event order.",
128+
},
71129
},
72130
{
73131
sequelize,
@@ -78,7 +136,7 @@ Event.init(
78136
fields: ["transactionId"],
79137
},
80138
],
81-
}
139+
},
82140
);
83141

84142
Event.belongsTo(Transaction, {

indexer/src/models/signer.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ Signer.init(
6060
model: "Transactions",
6161
key: "id",
6262
},
63-
onUpdate: "CASCADE",
64-
onDelete: "CASCADE",
6563
comment: "Foreign key referencing the related transaction ID",
6664
},
6765
},
@@ -70,6 +68,12 @@ Signer.init(
7068
modelName: "Signer",
7169
tableName: "Signers",
7270
timestamps: true,
71+
indexes: [
72+
{
73+
name: "signers_pubkey_transactionid_idx",
74+
fields: ["pubkey", "transactionId"],
75+
},
76+
],
7377
},
7478
);
7579

indexer/src/models/transfer.ts

Lines changed: 96 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ export interface TransferAttributes {
1616
modulename: string;
1717
requestkey: string;
1818
to_acct: string;
19-
network: string;
2019
hasTokenId: boolean;
2120
tokenId?: string;
2221
contractId?: number;
2322
canonical?: boolean;
23+
orderIndex?: number;
2424
}
2525

2626
/**
@@ -60,9 +60,6 @@ class Transfer extends Model<TransferAttributes> implements TransferAttributes {
6060
/** The account to which the transfer was made (e.g., "k:251efb06f3b798dbe7bb3f58f535b67b0a9ed2da9aa4e2367be4abc07cc927fa"). */
6161
declare to_acct: string;
6262

63-
/** The network name (e.g., "mainnet01"). */
64-
declare network: string;
65-
6663
/** Whether the transfer has a token ID (e.g., false). */
6764
declare hasTokenId: boolean;
6865

@@ -74,26 +71,100 @@ class Transfer extends Model<TransferAttributes> implements TransferAttributes {
7471

7572
/* Whether the transfer is canonical */
7673
declare canonical?: boolean;
74+
75+
/* The transfer order */
76+
declare orderIndex?: number;
7777
}
7878

7979
Transfer.init(
8080
{
81-
id: { type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true, comment: "The unique identifier for the transfer record (e.g., 1799984)." },
82-
transactionId: { type: DataTypes.INTEGER, allowNull: true, comment: "The ID of the associated transaction (e.g., 2022215)." },
83-
type: { type: DataTypes.STRING, allowNull: false, comment: "The type of the transfer (e.g., 'fungible')." },
84-
amount: { type: DataTypes.DECIMAL, allowNull: false, comment: "The amount transferred (e.g., 0.0003112)." },
85-
payloadHash: { type: DataTypes.STRING, allowNull: false, comment: "The payload hash of the transfer (e.g., 'UVboyJrggtoJBUSgCvTfCMrfGjxiZ7tvRQ_k_f5Mr6I')." },
86-
chainId: { type: DataTypes.INTEGER, allowNull: false, comment: "The ID of the blockchain network (e.g., 0)." },
87-
from_acct: { type: DataTypes.STRING, allowNull: false, comment: "The account from which the transfer was made (e.g., 'k:6fdc4bdbd5bd319466d7b83d85465d8a5a5546bf3b9aababb77aac7bb44241aa')." },
88-
modulehash: { type: DataTypes.STRING, allowNull: false, comment: "The hash of the module (e.g., 'klFkrLfpyLW-M3xjVPSdqXEMgxPPJibRt_D6qiBws6s')." },
89-
modulename: { type: DataTypes.STRING, allowNull: false, comment: "The name of the module (e.g., 'coin')." },
90-
requestkey: { type: DataTypes.STRING, allowNull: false, comment: "The request key of the transfer (e.g., 'y2XuhnGPkvptF-scYTnMfdcD2zokQf-HyOu-qngAm9s')." },
91-
to_acct: { type: DataTypes.STRING, allowNull: false, comment: "The account to which the transfer was made (e.g., 'k:251efb06f3b798dbe7bb3f58f535b67b0a9ed2da9aa4e2367be4abc07cc927fa')." },
92-
network: { type: DataTypes.STRING, allowNull: false, comment: "The network name (e.g., 'mainnet01')." },
93-
hasTokenId: { type: DataTypes.BOOLEAN, allowNull: true, comment: "Whether the transfer has a token ID (e.g., true)." },
94-
tokenId: { type: DataTypes.STRING, allowNull: true, comment: "The token ID associated with the transfer (optional, e.g., 't:DowR5LB9h6n96kxFRXDLSuSs1yh100Pk6STuUQNpseM')." },
95-
contractId: { type: DataTypes.INTEGER, allowNull: true, comment: "The ID of the associated contract (optional, e.g., 1)." },
96-
canonical: { type: DataTypes.BOOLEAN, allowNull: true, comment: "Whether the transfer is canonical" },
81+
id: {
82+
type: DataTypes.INTEGER,
83+
autoIncrement: true,
84+
primaryKey: true,
85+
comment: "The unique identifier for the transfer record (e.g., 1799984).",
86+
},
87+
transactionId: {
88+
type: DataTypes.INTEGER,
89+
allowNull: true,
90+
comment: "The ID of the associated transaction (e.g., 2022215).",
91+
},
92+
type: {
93+
type: DataTypes.STRING,
94+
allowNull: false,
95+
comment: "The type of the transfer (e.g., 'fungible').",
96+
},
97+
amount: {
98+
type: DataTypes.DECIMAL,
99+
allowNull: false,
100+
comment: "The amount transferred (e.g., 0.0003112).",
101+
},
102+
payloadHash: {
103+
type: DataTypes.STRING,
104+
allowNull: false,
105+
comment:
106+
"The payload hash of the transfer (e.g., 'UVboyJrggtoJBUSgCvTfCMrfGjxiZ7tvRQ_k_f5Mr6I').",
107+
},
108+
chainId: {
109+
type: DataTypes.INTEGER,
110+
allowNull: false,
111+
comment: "The ID of the blockchain network (e.g., 0).",
112+
},
113+
from_acct: {
114+
type: DataTypes.STRING,
115+
allowNull: false,
116+
comment:
117+
"The account from which the transfer was made (e.g., 'k:6fdc4bdbd5bd319466d7b83d85465d8a5a5546bf3b9aababb77aac7bb44241aa').",
118+
},
119+
modulehash: {
120+
type: DataTypes.STRING,
121+
allowNull: false,
122+
comment:
123+
"The hash of the module (e.g., 'klFkrLfpyLW-M3xjVPSdqXEMgxPPJibRt_D6qiBws6s').",
124+
},
125+
modulename: {
126+
type: DataTypes.STRING,
127+
allowNull: false,
128+
comment: "The name of the module (e.g., 'coin').",
129+
},
130+
requestkey: {
131+
type: DataTypes.STRING,
132+
allowNull: false,
133+
comment:
134+
"The request key of the transfer (e.g., 'y2XuhnGPkvptF-scYTnMfdcD2zokQf-HyOu-qngAm9s').",
135+
},
136+
to_acct: {
137+
type: DataTypes.STRING,
138+
allowNull: false,
139+
comment:
140+
"The account to which the transfer was made (e.g., 'k:251efb06f3b798dbe7bb3f58f535b67b0a9ed2da9aa4e2367be4abc07cc927fa').",
141+
},
142+
hasTokenId: {
143+
type: DataTypes.BOOLEAN,
144+
allowNull: true,
145+
comment: "Whether the transfer has a token ID (e.g., true).",
146+
},
147+
tokenId: {
148+
type: DataTypes.STRING,
149+
allowNull: true,
150+
comment:
151+
"The token ID associated with the transfer (optional, e.g., 't:DowR5LB9h6n96kxFRXDLSuSs1yh100Pk6STuUQNpseM').",
152+
},
153+
contractId: {
154+
type: DataTypes.INTEGER,
155+
allowNull: true,
156+
comment: "The ID of the associated contract (optional, e.g., 1).",
157+
},
158+
canonical: {
159+
type: DataTypes.BOOLEAN,
160+
allowNull: true,
161+
comment: "Whether the transfer is canonical",
162+
},
163+
orderIndex: {
164+
type: DataTypes.INTEGER,
165+
allowNull: true,
166+
comment: "The transfer order",
167+
},
97168
},
98169
{
99170
sequelize,
@@ -119,8 +190,12 @@ Transfer.init(
119190
name: "transfers_modulename_idx",
120191
fields: ["modulename"],
121192
},
193+
{
194+
name: "transfers_from_acct_modulename_idx",
195+
fields: ["from_acct", "modulename"],
196+
},
122197
],
123-
}
198+
},
124199
);
125200

126201
Transfer.belongsTo(Transaction, {

0 commit comments

Comments
 (0)