Skip to content

Commit 7792ea8

Browse files
committed
fixes for event insertion
1 parent 25bdb72 commit 7792ea8

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

run/lib/rpc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class ContractConnector {
176176
this.abi = abi || ALL_ABIS;
177177
this.address = address;
178178
this.provider = getProvider(server);
179-
this.contract = new ethers.Contract(address, this. abi, this.provider);
179+
this.contract = new ethers.Contract(address, this.abi, this.provider);
180180
}
181181

182182
// This should be improved by testing functions like transfer/allowance/approve/transferFrom

run/lib/utils.js

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ const _sanitize = (obj, numberization = true) => {
6969
};
7070

7171
const stringify = (obj) => {
72+
if (!obj)
73+
return null;
7274
if (ethers.BigNumber.isBigNumber(obj) || isStringifiedBN(obj))
7375
return ethers.BigNumber.from(obj).toString();
7476
else if (typeof obj.toString == 'function')

run/seeders/20240111221413-seed-blocks-timescale.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const ethers = require('ethers');
33
const { stringify } = require('../lib/utils');
44
const BigNumber = ethers.BigNumber;
5-
const { TransactionReceipt, TransactionEvent, TokenTransfer, TokenTransferEvent, TokenBalanceChange, TokenBalanceChangeEvent } = require('../models');
5+
const { Transaction, TransactionReceipt, TransactionEvent, TokenTransfer, TokenTransferEvent, TokenBalanceChange, TokenBalanceChangeEvent } = require('../models');
66

77
/** @type {import('sequelize-cli').Migration} */
88
module.exports = {
@@ -11,15 +11,20 @@ module.exports = {
1111
let receipts;
1212
let offset = 0, limit = parseInt(process.env.MAX_NUMBER_TO_INSERT || 1);
1313
do {
14+
1415
receipts = await TransactionReceipt.findAll({
15-
include: 'transaction',
16+
include: [{
17+
model: Transaction,
18+
as: 'transaction',
19+
}],
1620
order: [['id', 'ASC']],
1721
offset, limit
1822
});
23+
1924
const events = [];
2025
for (let i = 0; i < receipts.length; i++) {
2126
const receipt = receipts[i];
22-
const gasPrice = stringify(receipt.raw.effectiveGasPrice) || stringify(receipt.raw.gasPrice);
27+
const gasPrice = stringify(receipt.raw.effectiveGasPrice) || stringify(receipt.raw.gasPrice) || stringify(receipt.transaction.gasPrice);
2328
const transactionFee = BigNumber.from(receipt.gasUsed).mul(BigNumber.from(gasPrice))
2429

2530
try {
@@ -48,7 +53,8 @@ module.exports = {
4853
offset = 0;
4954
do {
5055
transfers = await TokenTransfer.findAll({
51-
include: 'transaction',
56+
include: { model: Transaction, as: 'transaction', attributes: ['blockNumber', 'timestamp'] },
57+
attributes: ['token', 'id', 'workspaceId', 'amount', 'src', 'dst'],
5258
order: [['id', 'ASC']],
5359
offset, limit
5460
});

0 commit comments

Comments
 (0)