Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
justraman committed Oct 12, 2023
1 parent 540dc75 commit a26a28d
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/mappings/multiTokens/events/approved.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export async function approved(

tokenAccount.approvals = approvals
tokenAccount.updatedAt = new Date(block.timestamp)
ctx.store.save(tokenAccount)
await ctx.store.save(tokenAccount)
} else {
const collectionAccount = await ctx.store.findOneOrFail<CollectionAccount>(CollectionAccount, {
where: { id: `${data.collectionId}-${address}` },
Expand All @@ -91,7 +91,7 @@ export async function approved(

collectionAccount.approvals = approvals
collectionAccount.updatedAt = new Date(block.timestamp)
ctx.store.save(collectionAccount)
await ctx.store.save(collectionAccount)
}

return getEvent(item, data)
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/multiTokens/events/attribute_removed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export async function attributeRemoved(
processMetadata(collection.id, 'collection', true)
}

ctx.store.remove(attribute)
await ctx.store.remove(attribute)
}
return getEvent(item, data)
}
2 changes: 1 addition & 1 deletion src/mappings/multiTokens/events/attribute_set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export async function attributeSet(
updatedAt: new Date(block.timestamp),
})

ctx.store.insert(Attribute, attribute as any)
await ctx.store.insert(Attribute, attribute as any)

if (token) {
if (!token.metadata) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function collectionAccountDestroyed(
where: { id: `${data.collectionId}-${address}` },
})
if (collectionAccount) {
ctx.store.remove(collectionAccount)
await ctx.store.remove(collectionAccount)
}

return getEvent(item, data)
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/multiTokens/events/collection_destroyed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function collectionDestroyed(
ctx.store.delete(Attribute, { collection: { id: collectionId } }),
])

ctx.store.delete(Collection, { id: collectionId })
await ctx.store.delete(Collection, { id: collectionId })

return getEvent(item, data)
}
8 changes: 1 addition & 7 deletions src/mappings/multiTokens/events/minted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export async function minted(

const tokenAccount = await ctx.store.findOneOrFail<TokenAccount>(TokenAccount, {
where: { id: `${u8aToHex(data.recipient)}-${data.collectionId}-${data.tokenId}` },
relations: { account: true },
})

if (token.supply !== 0n && token.metadata?.attributes) {
Expand All @@ -106,15 +105,10 @@ export async function minted(

token.supply += data.amount
token.nonFungible = isNonFungible(token)
ctx.store.save(token)

tokenAccount.balance += data.amount
tokenAccount.updatedAt = new Date(block.timestamp)
ctx.store.save(tokenAccount)

const { account } = tokenAccount
account.tokenValues += data.amount * (token.unitPrice ?? 10_000_000_000_000n)
ctx.store.save(account)
await Promise.all([ctx.store.save(tokenAccount), ctx.store.save(token)])

syncCollectionStats(data.collectionId.toString())

Expand Down
2 changes: 1 addition & 1 deletion src/mappings/multiTokens/events/token_account_created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export async function tokenAccountCreated(
updatedAt: new Date(block.timestamp),
})

ctx.store.insert(TokenAccount, tokenAccount as any)
await ctx.store.insert(TokenAccount, tokenAccount as any)

return getEvent(item, data)
}
2 changes: 1 addition & 1 deletion src/mappings/multiTokens/events/token_account_destroyed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function tokenAccountDestroyed(
where: { id: `${u8aToHex(data.accountId)}-${data.collectionId}-${data.tokenId}` },
})
if (tokenAccount) {
ctx.store.remove(tokenAccount)
await ctx.store.remove(tokenAccount)
}

return getEvent(item, data)
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/multiTokens/events/token_created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export async function tokenCreated(
createdAt: new Date(block.timestamp),
})

ctx.store.insert(Token, token as any)
await ctx.store.insert(Token, token as any)

return getEvent(item, eventData)
}
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/multiTokens/events/token_destroyed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export async function tokenDestroyed(
])
}

ctx.store.remove(token)
await ctx.store.remove(token)
syncCollectionStats(data.collectionId.toString())
computeTraits(data.collectionId.toString())

Expand Down
14 changes: 2 additions & 12 deletions src/mappings/multiTokens/events/transferred.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,32 +79,22 @@ export async function transferred(
const [fromTokenAccount, toTokenAccount] = await Promise.all([
ctx.store.findOne<TokenAccount>(TokenAccount, {
where: { id: `${fromAddress}-${data.collectionId}-${data.tokenId}` },
relations: { account: true, token: true },
}),
ctx.store.findOne<TokenAccount>(TokenAccount, {
where: { id: `${toAddress}-${data.collectionId}-${data.tokenId}` },
relations: { account: true, token: true },
}),
])

if (fromTokenAccount) {
fromTokenAccount.balance -= data.amount
fromTokenAccount.updatedAt = new Date(block.timestamp)
ctx.store.save(fromTokenAccount)

const { account, token } = fromTokenAccount
account.tokenValues -= data.amount * (token.unitPrice ?? 10_000_000_000_000n)
ctx.store.save(account)
await ctx.store.save(fromTokenAccount)
}

if (toTokenAccount) {
toTokenAccount.balance += data.amount
toTokenAccount.updatedAt = new Date(block.timestamp)
ctx.store.save(toTokenAccount)

const { account, token } = toTokenAccount
account.tokenValues += data.amount * (token.unitPrice ?? 10_000_000_000_000n)
ctx.store.save(account)
await ctx.store.save(toTokenAccount)
}

syncCollectionStats(data.collectionId.toString())
Expand Down

0 comments on commit a26a28d

Please sign in to comment.