From fe3a2ea9f8743f6a31bc76025dee3cf9882932b3 Mon Sep 17 00:00:00 2001 From: Eugene Panteleymonchuk Date: Wed, 15 Nov 2023 16:34:35 +0200 Subject: [PATCH] Fix: Search by TokenId (#829) * Token Id search doesn't work Signed-off-by: Eugene Panteleymonchuk * Token Id search works. Signed-off-by: Eugene Panteleymonchuk * Remove unused import. Signed-off-by: Eugene Panteleymonchuk * rename foundryOutputs to foundryOutput Signed-off-by: Eugene Panteleymonchuk * Rename missed methods. Signed-off-by: Eugene Panteleymonchuk * Add typescript to client methods. Signed-off-by: Eugene Panteleymonchuk * feat: Use correct method for single outputId search in searchExecutor * fix: Fix aliasOutputId and nftOutputId queries in searchExecutor to be "single". Fix permanode queries (it needs the ignoreNodeHealth flag when used with iota-sdk). --------- Signed-off-by: Eugene Panteleymonchuk Co-authored-by: Mario Sarcevic --- api/src/utils/stardust/searchExecutor.ts | 22 +++++++++---------- .../utils/stardust/stardustTangleHelper.ts | 10 +++++++-- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/api/src/utils/stardust/searchExecutor.ts b/api/src/utils/stardust/searchExecutor.ts index 1d5862764..efaf28d9b 100644 --- a/api/src/utils/stardust/searchExecutor.ts +++ b/api/src/utils/stardust/searchExecutor.ts @@ -127,7 +127,7 @@ export class SearchExecutor { new Promise((resolve, reject) => { StardustTangleHelper.tryFetchNodeThenPermanode( searchQuery.output, - "output", + "getOutput", network ).then( output => { @@ -148,13 +148,13 @@ export class SearchExecutor { if (searchQuery.aliasId) { promises.push( new Promise((resolve, reject) => { - StardustTangleHelper.tryFetchNodeThenPermanode( + StardustTangleHelper.tryFetchNodeThenPermanode( searchQuery.aliasId, - "alias", + "aliasOutputId", network ).then( aliasOutputs => { - if (aliasOutputs.items.length > 0) { + if (aliasOutputs) { promisesResult = { aliasId: searchQuery.aliasId }; @@ -173,13 +173,13 @@ export class SearchExecutor { if (searchQuery.nftId) { promises.push( new Promise((resolve, reject) => { - StardustTangleHelper.tryFetchNodeThenPermanode( + StardustTangleHelper.tryFetchNodeThenPermanode( searchQuery.nftId, - "nft", + "nftOutputId", network ).then( nftOutputs => { - if (nftOutputs.items.length > 0) { + if (nftOutputs) { promisesResult = { nftId: searchQuery.nftId }; @@ -198,13 +198,13 @@ export class SearchExecutor { if (searchQuery.foundryId) { promises.push( new Promise((resolve, reject) => { - StardustTangleHelper.tryFetchNodeThenPermanode( + StardustTangleHelper.tryFetchNodeThenPermanode( searchQuery.foundryId, - "foundry", + "foundryOutputId", network ).then( - foundryOutputs => { - if (foundryOutputs.items.length > 0) { + foundryOutput => { + if (foundryOutput) { promisesResult = { foundryId: searchQuery.foundryId }; diff --git a/api/src/utils/stardust/stardustTangleHelper.ts b/api/src/utils/stardust/stardustTangleHelper.ts index 641085b50..ac25cd7dc 100644 --- a/api/src/utils/stardust/stardustTangleHelper.ts +++ b/api/src/utils/stardust/stardustTangleHelper.ts @@ -1,5 +1,6 @@ /* eslint-disable no-warning-comments */ import { + __ClientMethods__, OutputResponse, Client, IBlockMetadata, MilestonePayload, IOutputsResponse, HexEncodedString, Block, Utils, QueryParameter, NftQueryParameter, AliasQueryParameter, FoundryQueryParameter } from "@iota/sdk"; @@ -30,6 +31,9 @@ import { INetwork } from "../../models/db/INetwork"; import { NodeInfoService } from "../../services/stardust/nodeInfoService"; import { HexHelper } from "../hexHelper"; +type NameType = T extends { name: infer U } ? U : never; +type ExtractedMethodNames = NameType<__ClientMethods__>; + /** * Helper functions for use with tangle. */ @@ -598,7 +602,7 @@ export class StardustTangleHelper { */ public static async tryFetchNodeThenPermanode( args: A, - methodName: string, + methodName: ExtractedMethodNames, network: INetwork ): Promise | null { const { @@ -614,7 +618,9 @@ export class StardustTangleHelper { } catch { } if (permaNodeEndpoint && isFallbackEnabled) { - const permanode = new Client({ nodes: [permaNodeEndpoint] }); + // Client with permanode needs the ignoreNodeHealth as chronicle is considered "not healthy" by the sdk + // Related: https://github.com/iotaledger/inx-chronicle/issues/1302 + const permanode = new Client({ nodes: [permaNodeEndpoint], ignoreNodeHealth: true }); try { // try fetch from permanode (chronicle)