From ab8bb292d6a2065919d4ac9616ad501968e235d4 Mon Sep 17 00:00:00 2001 From: Martynas Kazlauskas Date: Mon, 7 Aug 2023 12:31:22 +0300 Subject: [PATCH] feat(projection): ignore burn transactions when projecting cip25 metadata https://github.com/cardano-foundation/CIPs/pull/527 --- .../src/operators/Mappers/withNftMetadata.ts | 3 ++- .../test/operators/Mappers/withNftMetadata.test.ts | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/projection/src/operators/Mappers/withNftMetadata.ts b/packages/projection/src/operators/Mappers/withNftMetadata.ts index ae6ea7e0de8..259cf166320 100644 --- a/packages/projection/src/operators/Mappers/withNftMetadata.ts +++ b/packages/projection/src/operators/Mappers/withNftMetadata.ts @@ -30,7 +30,8 @@ const getNftMetadataFromCip67 = ({ cip67 }: WithCIP67, logger: Logger) => ); const getNftMetadataFromCip25 = ({ mint }: WithMint, logger: Logger) => - mint.map(({ assetId, txMetadata, policyId, assetName }): ProjectedNftMetadata | null => { + mint.map(({ assetId, txMetadata, policyId, assetName, quantity }): ProjectedNftMetadata | null => { + if (quantity < 1n) return null; const nftMetadata = Asset.NftMetadata.fromMetadatum({ name: assetName, policyId }, txMetadata, logger); if (!nftMetadata) return null; diff --git a/packages/projection/test/operators/Mappers/withNftMetadata.test.ts b/packages/projection/test/operators/Mappers/withNftMetadata.test.ts index 7a2369e5931..b5bdfaa140e 100644 --- a/packages/projection/test/operators/Mappers/withNftMetadata.test.ts +++ b/packages/projection/test/operators/Mappers/withNftMetadata.test.ts @@ -53,6 +53,7 @@ const datumNftmetadata = { describe('withNftMetadata', () => { const assetId1 = Cardano.AssetId('7d878696b149b529807aa01b8e20785e0a0d470c32c13f53f08a55e344455630303032'); const assetId2 = Cardano.AssetId('7d878696b149b529807aa01b8e20785e0a0d470c32c13f53f08a55e344455638393230'); + const assetId3 = Cardano.AssetId('7d878696b149b529807aa01b8e20785e0a0d470c32c13f53f08a55e344455638393233'); const otherProperties1 = new Map([ ['Background', 'Ocean'], ['Body', 'Pale'], @@ -97,6 +98,14 @@ describe('withNftMetadata', () => { ['name', 'DEV 0002'] ]) ], + [ + Buffer.from(Cardano.AssetId.getAssetName(assetId3), 'hex').toString('utf8'), + new Map([ + ['image', 'ipfs://QmWmB37VZ9uc2cVe2fG31Xqjxw5VbUu4DMLkGt9LW6z7Up'], + ['mediaType', 'image/jpeg'], + ['name', 'Burned'] + ]) + ], [ 'DEV8920', new Map([ @@ -121,7 +130,8 @@ describe('withNftMetadata', () => { body: { mint: new Map([ [assetId1, 1n], - [assetId2, 1n] + [assetId2, 1n], + [assetId3, -1n] ]) } }