Skip to content

Commit

Permalink
Fix/assets skipped (#870)
Browse files Browse the repository at this point in the history
* chore: fixed missing or skipped assets

* chore: removed unused console logs
  • Loading branch information
Kammerlo committed May 5, 2024
1 parent 6648b82 commit 30563de
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions packages/api-cardano-db-hasura/src/ChainFollower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,10 @@ export class ChainFollower {
for (const tx of b.transactions) {
if (tx.mint !== undefined) {
for (const entry of Object.entries(tx.mint)) {
const [policyId, assetName] = entry[0].split('.')
const assetId = `${policyId}${assetName !== undefined ? assetName : ''}`
if (!(await this.hasuraClient.hasAsset(assetId))) {
const asset = {
assetId,
assetName,
firstAppearedInSlot: b.slot,
fingerprint: assetFingerprint(policyId, assetName),
policyId
}
await this.hasuraClient.insertAssets([asset])
const SIX_HOURS = 21600
const THREE_MONTHS = 365
await this.queue.publish('asset-metadata-fetch-initial', { assetId }, {
retryDelay: SIX_HOURS,
retryLimit: THREE_MONTHS
})
const policyId = entry[0]
const assetNames = Object.keys(entry[1])
for (const assetName of assetNames) {
await this.saveAsset(policyId, assetName, b)
}
}
}
Expand All @@ -103,6 +90,26 @@ export class ChainFollower {
this.logger.info({ module: MODULE_NAME }, 'Initialized')
}

async saveAsset (policyId: string, assetName: string | undefined, b: BlockPraos) {
const assetId = `${policyId}${assetName !== undefined ? assetName : ''}`
if (!(await this.hasuraClient.hasAsset(assetId))) {
const asset = {
assetId,
assetName,
firstAppearedInSlot: b.slot,
fingerprint: assetFingerprint(policyId, assetName),
policyId
}
await this.hasuraClient.insertAssets([asset])
const SIX_HOURS = 21600
const THREE_MONTHS = 365
await this.queue.publish('asset-metadata-fetch-initial', { assetId }, {
retryDelay: SIX_HOURS,
retryLimit: THREE_MONTHS
})
}
}

public async start (points: Schema.PointOrOrigin[]) {
if (this.state !== 'initialized') {
throw new errors.ModuleIsNotInitialized(MODULE_NAME, 'start')
Expand Down

0 comments on commit 30563de

Please sign in to comment.