Skip to content

Commit

Permalink
fix: erc721 reindex stats (#882)
Browse files Browse the repository at this point in the history
  • Loading branch information
phamphong9981 committed Aug 7, 2024
1 parent dc9770a commit d1ebe0d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/services/evm/erc721_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export class Erc721Handler {

static async calErc721Stats(addresses?: string[]): Promise<Erc721Contract[]> {
// Get once block height 24h ago.
let blockSince24hAgo = {};
let blockSince24hAgo: any = [];
if (!config.evmOnly) {
blockSince24hAgo = await Block.query()
.select('height')
Expand All @@ -307,6 +307,7 @@ export class Erc721Handler {
.limit(1);
}
// Calculate total activity and transfer_24h of erc721
// not return record if erc721 contract haven't erc721 activities
return Erc721Contract.query()
.count('erc721_activity.id AS total_activity')
.select(
Expand Down
28 changes: 15 additions & 13 deletions src/services/evm/erc721_reindex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,22 @@ export class Erc721Reindexer {
await Erc721Handler.updateErc721(activities, tokens, trx);
});
const erc721Stats = await Erc721Handler.calErc721Stats([address]);
// Upsert erc721 stats
await Erc721Stats.query()
.insert(
erc721Stats.map((e) =>
Erc721Stats.fromJson({
total_activity: e.total_activity,
transfer_24h: e.transfer_24h,
erc721_contract_id: e.erc721_contract_id,
})
if (erc721Stats.length > 0) {
// Upsert erc721 stats
await Erc721Stats.query()
.insert(
erc721Stats.map((e) =>
Erc721Stats.fromJson({
total_activity: e.total_activity,
transfer_24h: e.transfer_24h,
erc721_contract_id: e.erc721_contract_id,
})
)
)
)
.onConflict('erc721_contract_id')
.merge()
.returning('id');
.onConflict('erc721_contract_id')
.merge()
.returning('id');
}
}

async getCurrentTokens(
Expand Down

0 comments on commit d1ebe0d

Please sign in to comment.