Skip to content

Commit

Permalink
extract common code
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan-rosianu committed Feb 26, 2025
1 parent 2d06a89 commit aace90e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
9 changes: 1 addition & 8 deletions src/endpoints/esdt/esdt.address.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 1 addition & 8 deletions src/endpoints/nfts/nft.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions src/utils/token.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit aace90e

Please sign in to comment.