Skip to content

Commit

Permalink
fix: fetch infusion data token storage (#1276)
Browse files Browse the repository at this point in the history
fetch infusion data token storage
  • Loading branch information
justraman authored Sep 11, 2024
1 parent b2f814f commit b5b3d40
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions src/mappings/multiTokens/events/token_created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,37 @@ function getEvent(item: EventItem, data: ReturnType<typeof getEventData>) {
}

async function getTokenId(ctx: CommonContext, block: BlockHeader, collectionId: bigint, tokenId: bigint) {
if (storage.multiTokens.tokens.matrixEnjinV1012.is(block)) {
const data = await storage.multiTokens.tokens.matrixEnjinV1012.get(block, collectionId, tokenId)

if (data) {
const cap = data.cap ? getCapType(data.cap) : null
const behavior = data.marketBehavior ? await getBehavior(ctx, data.marketBehavior) : null
const freezeState = data.freezeState ? getFreezeState(data.freezeState) : null
const unitPrice: bigint = 10_000_000_000_000_000n

return {
collectionId,
tokenId,
infusion: data.infusion,
initialSupply: data.supply,
minimumBalance: 1n,
anyoneCanInfuse: data.anyoneCanInfuse,
unitPrice,
cap,
nativeMetadata: new NativeTokenMetadata({
decimalCount: data.metadata.decimalCount,
name: hexToString(data.metadata.name),
symbol: hexToString(data.metadata.symbol),
}),
accountDepositCount: data.accountCount,
behavior,
freezeState,
listingForbidden: data.listingForbidden ?? false,
}
}
}

if (storage.multiTokens.tokens.matrixEnjinV603.is(block)) {
const data = await storage.multiTokens.tokens.matrixEnjinV603.get(block, collectionId, tokenId)

Expand All @@ -663,17 +694,7 @@ async function getTokenId(ctx: CommonContext, block: BlockHeader, collectionId:
}
}

return {
collectionId,
tokenId,
initialSupply: 0n,
minimumBalance: 1n,
unitPrice: 10_000_000_000_000_000n,
cap: null,
behavior: null,
freezeState: null,
listingForbidden: false,
}
throw new UnknownVersionError('storage.multiTokens.token')
}

export async function tokenCreated(
Expand Down

0 comments on commit b5b3d40

Please sign in to comment.