Skip to content

Commit

Permalink
feat: update erc721 reindex log; erc721 index
Browse files Browse the repository at this point in the history
  • Loading branch information
fibonacci998 committed Nov 12, 2024
1 parent 2c0aa4c commit 6446c8c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion migrations/evm/20240409065017_erc721_token_init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ export async function up(knex: Knex): Promise<void> {
await knex.schema.createTable('erc721_token', (table) => {
table.increments('id').primary();
table.string('token_id').index();
table.string('owner');
table.string('owner').index();
table.string('erc721_contract_address').index().notNullable();
table.integer('last_updated_height').index();
table.unique(['token_id', 'erc721_contract_address']);
table
.foreign('erc721_contract_address')
.references('erc721_contract.address');
table.timestamp('created_at').notNullable().defaultTo(knex.raw('now()'));
table.index(['erc721_contract_address', 'token_id']);
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/services/evm/erc721_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class Erc721Handler {
BigInt(erc721Contract.total_supply) + BigInt(1)
).toString();
} else {
throw new Error('Handle erc721 tranfer error');
throw new Error(`Handle erc721 tranfer error, address: ${erc721Contract.address}`);
}
// update erc721 holder statistics
const erc721HolderStatFrom =
Expand Down Expand Up @@ -328,7 +328,7 @@ export class Erc721Handler {
(erc721Contract) =>
`(${erc721Contract.id}, ${
erc721Contract.total_supply
}, '${JSON.stringify(erc721Contract.total_actions)}'::jsonb)`
}, '${JSON.stringify(erc721Contract.total_actions ?? {})}'::jsonb)`
)
.join(',');
await knex
Expand Down
11 changes: 10 additions & 1 deletion src/services/evm/erc721_media_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,21 @@ export class Erc721MediaHandler {
if (fileName) {
// case media uri is ipfs supported
try {
const s3Object = await s3Client
let s3Object = await s3Client
.headObject({
Bucket: BUCKET,
Key: fileName,
})
.promise();
if (s3Object.ContentType === 'application/octet-stream'){
s3Object = await s3Client.copyObject({
Bucket: BUCKET,
CopySource: `${BUCKET}/${fileName}`,
Key: fileName,
MetadataDirective: 'REPLACE',
ContentType: 'image/svg+xml'
}).promise();
}
return {
linkS3: S3_GATEWAY + fileName,
contentType: s3Object.ContentType,
Expand Down
1 change: 1 addition & 0 deletions src/services/evm/erc721_reindex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export class Erc721Reindexer {
contract.read.tokenByIndex([i])
)
)) as bigint[];
// const tokensId = [...Array(9).keys()];
const [height, ...owners]: [bigint, ...string[]] = await Promise.all([
this.viemClient.getBlockNumber(),
...tokensId.map(
Expand Down

0 comments on commit 6446c8c

Please sign in to comment.