From 48e1e28bdafaf9844ffb33d86ff3a32f806999eb Mon Sep 17 00:00:00 2001 From: bogdan-rosianu Date: Wed, 12 Feb 2025 17:46:40 +0200 Subject: [PATCH 1/8] export hash of a metaesdt/nft/sft --- src/endpoints/nfts/entities/nft.ts | 3 +++ src/endpoints/nfts/nft.service.ts | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/endpoints/nfts/entities/nft.ts b/src/endpoints/nfts/entities/nft.ts index d8af5956c..8470e4ebd 100644 --- a/src/endpoints/nfts/entities/nft.ts +++ b/src/endpoints/nfts/entities/nft.ts @@ -20,6 +20,9 @@ export class Nft { @ApiProperty({ type: String }) collection: string = ''; + @ApiProperty({ type: String }) + hash: string = ''; + @ApiProperty({ type: Number, nullable: true }) timestamp?: number = undefined; diff --git a/src/endpoints/nfts/nft.service.ts b/src/endpoints/nfts/nft.service.ts index e0af78f6b..e775100e2 100644 --- a/src/endpoints/nfts/nft.service.ts +++ b/src/endpoints/nfts/nft.service.ts @@ -18,13 +18,12 @@ import { EsdtDataSource } from "../esdt/entities/esdt.data.source"; import { EsdtAddressService } from "../esdt/esdt.address.service"; import { PersistenceService } from "src/common/persistence/persistence.service"; import { MexTokenService } from "../mex/mex.token.service"; -import { BinaryUtils, NumberUtils, RecordUtils, BatchUtils, TokenUtils } from "@multiversx/sdk-nestjs-common"; +import { BinaryUtils, NumberUtils, RecordUtils, BatchUtils, TokenUtils, OriginLogger } from "@multiversx/sdk-nestjs-common"; import { ApiUtils } from "@multiversx/sdk-nestjs-http"; import { CacheService } from "@multiversx/sdk-nestjs-cache"; import { IndexerService } from "src/common/indexer/indexer.service"; import { LockedAssetService } from "../../common/locked-asset/locked-asset.service"; import { CollectionAccount } from "../collections/entities/collection.account"; -import { OriginLogger } from "@multiversx/sdk-nestjs-common"; import { NftRankAlgorithm } from "src/common/assets/entities/nft.rank.algorithm"; import { NftRarity } from "./entities/nft.rarity"; import { NftRarities } from "./entities/nft.rarities"; @@ -349,6 +348,7 @@ export class NftService { const elasticNftData = elasticNft.data; if (elasticNftData) { nft.name = elasticNftData.name; + nft.hash = elasticNftData.hash; nft.creator = elasticNftData.creator; nft.royalties = elasticNftData.royalties ? elasticNftData.royalties / 100 : undefined; // 10.000 => 100% nft.attributes = elasticNftData.attributes; @@ -595,6 +595,16 @@ export class NftService { return await this.indexerService.getAccountsEsdtByCollection([identifier], pagination); } + // TODO: use this function to determine if a MetaESDT is a proof if we decide to add API filters to extract all the proofs + getNftProofHash(nft: Nft): string | undefined{ + const hashField = BinaryUtils.base64Decode(nft.hash); + if (nft.type !== NftType.MetaESDT || !hashField.startsWith('proof:')) { + return undefined; + } + + return hashField.split('proof:')[1]; + } + private getNftRarity(elasticNft: any, algorithm: NftRankAlgorithm): NftRarity | undefined { const score = elasticNft[this.getNftScoreElasticKey(algorithm)]; const rank = elasticNft[this.getNftRankElasticKey(algorithm)]; From 051e3ab8d4233e6fc7711dd602c3059503b10ef9 Mon Sep 17 00:00:00 2001 From: bogdan-rosianu Date: Wed, 12 Feb 2025 17:50:59 +0200 Subject: [PATCH 2/8] base64 decode hash --- src/endpoints/nfts/nft.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/endpoints/nfts/nft.service.ts b/src/endpoints/nfts/nft.service.ts index e775100e2..4d7834864 100644 --- a/src/endpoints/nfts/nft.service.ts +++ b/src/endpoints/nfts/nft.service.ts @@ -348,7 +348,7 @@ export class NftService { const elasticNftData = elasticNft.data; if (elasticNftData) { nft.name = elasticNftData.name; - nft.hash = elasticNftData.hash; + nft.hash = BinaryUtils.base64Decode(elasticNftData.hash); nft.creator = elasticNftData.creator; nft.royalties = elasticNftData.royalties ? elasticNftData.royalties / 100 : undefined; // 10.000 => 100% nft.attributes = elasticNftData.attributes; From ef6b936d1c64ccd159ad019560d252db73237fe3 Mon Sep 17 00:00:00 2001 From: bogdan-rosianu Date: Thu, 13 Feb 2025 13:53:49 +0200 Subject: [PATCH 3/8] hotfix --- src/endpoints/nfts/nft.service.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/endpoints/nfts/nft.service.ts b/src/endpoints/nfts/nft.service.ts index 4d7834864..1eeb67aef 100644 --- a/src/endpoints/nfts/nft.service.ts +++ b/src/endpoints/nfts/nft.service.ts @@ -348,7 +348,9 @@ export class NftService { const elasticNftData = elasticNft.data; if (elasticNftData) { nft.name = elasticNftData.name; - nft.hash = BinaryUtils.base64Decode(elasticNftData.hash); + if (elasticNftData.hash) { + nft.hash = BinaryUtils.base64Decode(elasticNftData.hash); + } nft.creator = elasticNftData.creator; nft.royalties = elasticNftData.royalties ? elasticNftData.royalties / 100 : undefined; // 10.000 => 100% nft.attributes = elasticNftData.attributes; From ff60cc5664f6920052c55248cba6bea5a6b20a8c Mon Sep 17 00:00:00 2001 From: bogdan-rosianu Date: Wed, 26 Feb 2025 14:58:36 +0200 Subject: [PATCH 4/8] update proof hash decoding --- src/endpoints/nfts/nft.service.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/endpoints/nfts/nft.service.ts b/src/endpoints/nfts/nft.service.ts index 1eeb67aef..5d4ec1a6a 100644 --- a/src/endpoints/nfts/nft.service.ts +++ b/src/endpoints/nfts/nft.service.ts @@ -349,7 +349,12 @@ export class NftService { if (elasticNftData) { nft.name = elasticNftData.name; if (elasticNftData.hash) { - nft.hash = BinaryUtils.base64Decode(elasticNftData.hash); + const decodedHex = BinaryUtils.base64Decode(elasticNftData.hash); + if (decodedHex.startsWith('proof:')) { + nft.hash = decodedHex; + } else { + nft.hash = elasticNftData.hash; + } } nft.creator = elasticNftData.creator; nft.royalties = elasticNftData.royalties ? elasticNftData.royalties / 100 : undefined; // 10.000 => 100% From 2d06a89345dc0401f6d600f0aaacc1058fde5392 Mon Sep 17 00:00:00 2001 From: bogdan-rosianu Date: Wed, 26 Feb 2025 15:27:45 +0200 Subject: [PATCH 5/8] added hash for gateway fetched nfts --- src/endpoints/esdt/esdt.address.service.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/endpoints/esdt/esdt.address.service.ts b/src/endpoints/esdt/esdt.address.service.ts index 817598c2c..4c6e61206 100644 --- a/src/endpoints/esdt/esdt.address.service.ts +++ b/src/endpoints/esdt/esdt.address.service.ts @@ -262,6 +262,14 @@ export class EsdtAddressService { nft.uris = dataSourceNft.uris ? dataSourceNft.uris.filter((x: any) => x) : []; nft.name = dataSourceNft.name; nft.timestamp = dataSourceNft.timestamp; + if (dataSourceNft.hash) { + const decodedHex = BinaryUtils.base64Decode(dataSourceNft.hash); + if (decodedHex.startsWith('proof:')) { + nft.hash = decodedHex; + } else { + nft.hash = dataSourceNft.hash; + } + } if (nft.uris && nft.uris.length > 0) { try { From aace90e263d31a9dd1b336c93205704195cb4111 Mon Sep 17 00:00:00 2001 From: bogdan-rosianu Date: Wed, 26 Feb 2025 15:36:43 +0200 Subject: [PATCH 6/8] extract common code --- src/endpoints/esdt/esdt.address.service.ts | 9 +-------- src/endpoints/nfts/nft.service.ts | 9 +-------- src/utils/token.helpers.ts | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/endpoints/esdt/esdt.address.service.ts b/src/endpoints/esdt/esdt.address.service.ts index 4c6e61206..be4a63318 100644 --- a/src/endpoints/esdt/esdt.address.service.ts +++ b/src/endpoints/esdt/esdt.address.service.ts @@ -262,14 +262,7 @@ export class EsdtAddressService { nft.uris = dataSourceNft.uris ? dataSourceNft.uris.filter((x: any) => x) : []; nft.name = dataSourceNft.name; nft.timestamp = dataSourceNft.timestamp; - if (dataSourceNft.hash) { - const decodedHex = BinaryUtils.base64Decode(dataSourceNft.hash); - if (decodedHex.startsWith('proof:')) { - nft.hash = decodedHex; - } else { - nft.hash = dataSourceNft.hash; - } - } + nft.hash = TokenHelpers.getNftProof(dataSourceNft.hash) || ''; if (nft.uris && nft.uris.length > 0) { try { diff --git a/src/endpoints/nfts/nft.service.ts b/src/endpoints/nfts/nft.service.ts index 5d4ec1a6a..accd4adfa 100644 --- a/src/endpoints/nfts/nft.service.ts +++ b/src/endpoints/nfts/nft.service.ts @@ -348,14 +348,7 @@ export class NftService { const elasticNftData = elasticNft.data; if (elasticNftData) { nft.name = elasticNftData.name; - if (elasticNftData.hash) { - const decodedHex = BinaryUtils.base64Decode(elasticNftData.hash); - if (decodedHex.startsWith('proof:')) { - nft.hash = decodedHex; - } else { - nft.hash = elasticNftData.hash; - } - } + nft.hash = nft.hash = TokenHelpers.getNftProof(elasticNftData.hash) || ''; nft.creator = elasticNftData.creator; nft.royalties = elasticNftData.royalties ? elasticNftData.royalties / 100 : undefined; // 10.000 => 100% nft.attributes = elasticNftData.attributes; diff --git a/src/utils/token.helpers.ts b/src/utils/token.helpers.ts index 9918a2b02..7ed8d6091 100644 --- a/src/utils/token.helpers.ts +++ b/src/utils/token.helpers.ts @@ -5,6 +5,7 @@ import { CollectionRoles } from "src/endpoints/tokens/entities/collection.roles" import { TokenRoles } from "src/endpoints/tokens/entities/token.roles"; import { ApiUtils } from '@multiversx/sdk-nestjs-http'; import '@multiversx/sdk-nestjs-common/lib/utils/extensions/string.extensions'; +import { BinaryUtils } from "@multiversx/sdk-nestjs-common"; export class TokenHelpers { static canBool(string: string) { @@ -96,4 +97,17 @@ export class TokenHelpers { static getCollectionIdentifier(nftIdentifier: string): string { return nftIdentifier.split('-').slice(0, 2).join('-'); } + + static getNftProof(hash: string): string | undefined { + if (!hash) { + return undefined; + } + + const decodedHex = BinaryUtils.base64Decode(hash); + if (decodedHex.startsWith('proof:')) { + return decodedHex; + } else { + return hash; + } + } } From a022555f7e250bd0f6217446e5121c6779d233d8 Mon Sep 17 00:00:00 2001 From: bogdan-rosianu Date: Tue, 4 Mar 2025 16:04:39 +0200 Subject: [PATCH 7/8] fix after review --- src/endpoints/nfts/nft.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/endpoints/nfts/nft.service.ts b/src/endpoints/nfts/nft.service.ts index accd4adfa..f063a648d 100644 --- a/src/endpoints/nfts/nft.service.ts +++ b/src/endpoints/nfts/nft.service.ts @@ -348,7 +348,7 @@ export class NftService { const elasticNftData = elasticNft.data; if (elasticNftData) { nft.name = elasticNftData.name; - nft.hash = nft.hash = TokenHelpers.getNftProof(elasticNftData.hash) || ''; + nft.hash = TokenHelpers.getNftProof(elasticNftData.hash) ?? ''; nft.creator = elasticNftData.creator; nft.royalties = elasticNftData.royalties ? elasticNftData.royalties / 100 : undefined; // 10.000 => 100% nft.attributes = elasticNftData.attributes; From a471a95e4cdf588e62e22e35db3a574b9b341e6d Mon Sep 17 00:00:00 2001 From: bogdan-rosianu Date: Tue, 4 Mar 2025 16:06:53 +0200 Subject: [PATCH 8/8] fix --- src/endpoints/esdt/esdt.address.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/endpoints/esdt/esdt.address.service.ts b/src/endpoints/esdt/esdt.address.service.ts index be4a63318..566759eb7 100644 --- a/src/endpoints/esdt/esdt.address.service.ts +++ b/src/endpoints/esdt/esdt.address.service.ts @@ -262,7 +262,7 @@ export class EsdtAddressService { nft.uris = dataSourceNft.uris ? dataSourceNft.uris.filter((x: any) => x) : []; nft.name = dataSourceNft.name; nft.timestamp = dataSourceNft.timestamp; - nft.hash = TokenHelpers.getNftProof(dataSourceNft.hash) || ''; + nft.hash = TokenHelpers.getNftProof(dataSourceNft.hash) ?? ''; if (nft.uris && nft.uris.length > 0) { try {