Skip to content

Commit 30563de

Browse files
authored
Fix/assets skipped (#870)
* chore: fixed missing or skipped assets * chore: removed unused console logs
1 parent 6648b82 commit 30563de

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

packages/api-cardano-db-hasura/src/ChainFollower.ts

+24-17
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,10 @@ export class ChainFollower {
6565
for (const tx of b.transactions) {
6666
if (tx.mint !== undefined) {
6767
for (const entry of Object.entries(tx.mint)) {
68-
const [policyId, assetName] = entry[0].split('.')
69-
const assetId = `${policyId}${assetName !== undefined ? assetName : ''}`
70-
if (!(await this.hasuraClient.hasAsset(assetId))) {
71-
const asset = {
72-
assetId,
73-
assetName,
74-
firstAppearedInSlot: b.slot,
75-
fingerprint: assetFingerprint(policyId, assetName),
76-
policyId
77-
}
78-
await this.hasuraClient.insertAssets([asset])
79-
const SIX_HOURS = 21600
80-
const THREE_MONTHS = 365
81-
await this.queue.publish('asset-metadata-fetch-initial', { assetId }, {
82-
retryDelay: SIX_HOURS,
83-
retryLimit: THREE_MONTHS
84-
})
68+
const policyId = entry[0]
69+
const assetNames = Object.keys(entry[1])
70+
for (const assetName of assetNames) {
71+
await this.saveAsset(policyId, assetName, b)
8572
}
8673
}
8774
}
@@ -103,6 +90,26 @@ export class ChainFollower {
10390
this.logger.info({ module: MODULE_NAME }, 'Initialized')
10491
}
10592

93+
async saveAsset (policyId: string, assetName: string | undefined, b: BlockPraos) {
94+
const assetId = `${policyId}${assetName !== undefined ? assetName : ''}`
95+
if (!(await this.hasuraClient.hasAsset(assetId))) {
96+
const asset = {
97+
assetId,
98+
assetName,
99+
firstAppearedInSlot: b.slot,
100+
fingerprint: assetFingerprint(policyId, assetName),
101+
policyId
102+
}
103+
await this.hasuraClient.insertAssets([asset])
104+
const SIX_HOURS = 21600
105+
const THREE_MONTHS = 365
106+
await this.queue.publish('asset-metadata-fetch-initial', { assetId }, {
107+
retryDelay: SIX_HOURS,
108+
retryLimit: THREE_MONTHS
109+
})
110+
}
111+
}
112+
106113
public async start (points: Schema.PointOrOrigin[]) {
107114
if (this.state !== 'initialized') {
108115
throw new errors.ModuleIsNotInitialized(MODULE_NAME, 'start')

0 commit comments

Comments
 (0)