From b01ef3d72f89440462995f4f234a78d743790661 Mon Sep 17 00:00:00 2001 From: Raman Shekhawat Date: Sat, 21 Oct 2023 21:59:53 +0530 Subject: [PATCH 1/3] bugfix: add approvals to collection accounts in populate block --- src/populateBlock.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/populateBlock.ts b/src/populateBlock.ts index 003809012..fc8ed3f36 100644 --- a/src/populateBlock.ts +++ b/src/populateBlock.ts @@ -39,6 +39,7 @@ import { ListingStatus, CollectionFlags, CollectionSocials, + CollectionApproval, } from './model' import { getCapType, getFreezeState } from './mappings/multiTokens/events' import { isNonFungible } from './mappings/multiTokens/utils/helpers' @@ -308,10 +309,21 @@ async function syncCollectionAccounts(ctx: CommonContext, block: SubstrateBlock) if (!account) throw Errors.accountNotFound() + let approvals = null + + if (data.approvals && data.approvals.length > 0) { + approvals = data.approvals.map((approval) => { + return new CollectionApproval({ + account: u8aToHex(approval[0]), + expiration: approval[1], + }) + }) + } + return new CollectionAccount({ id: `${collectionId}-${accountId}`, isFrozen: data.isFrozen, - approvals: null, + approvals, accountCount: data.accountCount, account, collection: new Collection({ id: collectionId }), From ec0ed57d2f6facaa0cc9ff1a3e2c52c42592b356 Mon Sep 17 00:00:00 2001 From: Raman Shekhawat Date: Sat, 21 Oct 2023 23:18:28 +0530 Subject: [PATCH 2/3] fix --- src/mappings/multiTokens/events/collection_created.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mappings/multiTokens/events/collection_created.ts b/src/mappings/multiTokens/events/collection_created.ts index 804b96b15..3c96da821 100644 --- a/src/mappings/multiTokens/events/collection_created.ts +++ b/src/mappings/multiTokens/events/collection_created.ts @@ -213,7 +213,7 @@ export async function collectionCreated( }) .map((rc) => ctx.store.insert(RoyaltyCurrency, rc as any)) - Promise.all(royaltyPromises) + await Promise.all(royaltyPromises) return getEvent(item, eventData) } From 0918fe696ed0f6ed3c552abc2c57c68391ffff9d Mon Sep 17 00:00:00 2001 From: Raman Shekhawat Date: Sat, 21 Oct 2023 23:49:38 +0530 Subject: [PATCH 3/3] fix token.isFrozen --- src/mappings/multiTokens/events/frozen.ts | 5 +++-- src/mappings/multiTokens/events/token_created.ts | 6 +++++- src/populateBlock.ts | 8 +++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/mappings/multiTokens/events/frozen.ts b/src/mappings/multiTokens/events/frozen.ts index 9b6f7db13..846f3cf34 100644 --- a/src/mappings/multiTokens/events/frozen.ts +++ b/src/mappings/multiTokens/events/frozen.ts @@ -16,6 +16,7 @@ import { } from '../../../model' import { CommonContext } from '../../types/contexts' import { Event } from '../../../types/generated/support' +import { isTokenFrozen } from './token_created' function getEventData(ctx: CommonContext, event: Event) { const data = new MultiTokensFrozenEvent(ctx, event) @@ -116,8 +117,6 @@ export async function frozen( where: { id: `${data.collectionId}-${data.tokenId}` }, }) - token.isFrozen = true - switch (data.freezeState?.__kind) { case 'Permanent': token.freezeState = FreezeState.Permanent @@ -133,6 +132,8 @@ export async function frozen( break } + token.isFrozen = isTokenFrozen(token.freezeState) + ctx.store.save(token) } else { const collection = await ctx.store.findOneOrFail(Collection, { diff --git a/src/mappings/multiTokens/events/token_created.ts b/src/mappings/multiTokens/events/token_created.ts index 51332ec78..c004b0036 100644 --- a/src/mappings/multiTokens/events/token_created.ts +++ b/src/mappings/multiTokens/events/token_created.ts @@ -72,6 +72,10 @@ export function getFreezeState(state: FreezeState_v500): FreezeState | null { } } +export function isTokenFrozen(freezeState: FreezeState | null | undefined): boolean { + return freezeState === FreezeState.Permanent || freezeState === FreezeState.Temporary +} + async function getBehavior( ctx: CommonContext, behavior: TokenMarketBehavior @@ -595,7 +599,7 @@ export async function tokenCreated( supply: 0n, // Supply is updated on Mint/Burn events cap: callData.cap, behavior: callData.behavior, - isFrozen: false, + isFrozen: isTokenFrozen(callData.freezeState), freezeState: callData.freezeState, minimumBalance: callData.minimumBalance, unitPrice: callData.unitPrice, diff --git a/src/populateBlock.ts b/src/populateBlock.ts index fc8ed3f36..938c69f8a 100644 --- a/src/populateBlock.ts +++ b/src/populateBlock.ts @@ -41,7 +41,7 @@ import { CollectionSocials, CollectionApproval, } from './model' -import { getCapType, getFreezeState } from './mappings/multiTokens/events' +import { getCapType, getFreezeState, isTokenFrozen } from './mappings/multiTokens/events' import { isNonFungible } from './mappings/multiTokens/utils/helpers' import { safeString } from './common/tools' import { addAccountsToSet, saveAccounts } from './mappings/balances/processor' @@ -375,16 +375,18 @@ async function syncTokens(ctx: CommonContext, block: SubstrateBlock) { minimumBalance = BigInt(Math.max(1, Number(10n ** 16n / unitPrice))) } + const freezeState = data.freezeState ? getFreezeState(data.freezeState) : undefined + const token = new Token({ id: `${collectionId}-${tokenId}`, tokenId, collection, attributeCount: data.attributeCount, supply: data.supply, - isFrozen: false, + isFrozen: isTokenFrozen(freezeState), cap: data.cap ? getCapType(data.cap) : null, behavior, - freezeState: data.freezeState ? getFreezeState(data.freezeState) : undefined, + freezeState, listingForbidden: 'listingForbidden' in data ? data.listingForbidden : false, minimumBalance, unitPrice,