Skip to content

Commit

Permalink
Fix: Search by TokenId (#829)
Browse files Browse the repository at this point in the history
* Token Id search doesn't work

Signed-off-by: Eugene Panteleymonchuk <[email protected]>

* Token Id search works.

Signed-off-by: Eugene Panteleymonchuk <[email protected]>

* Remove unused import.

Signed-off-by: Eugene Panteleymonchuk <[email protected]>

* rename foundryOutputs to foundryOutput

Signed-off-by: Eugene Panteleymonchuk <[email protected]>

* Rename missed methods.

Signed-off-by: Eugene Panteleymonchuk <[email protected]>

* Add typescript to client methods.

Signed-off-by: Eugene Panteleymonchuk <[email protected]>

* 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 <[email protected]>
Co-authored-by: Mario Sarcevic <[email protected]>
  • Loading branch information
panteleymonchuk and msarcev authored Nov 15, 2023
1 parent e6d6b94 commit fe3a2ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
22 changes: 11 additions & 11 deletions api/src/utils/stardust/searchExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class SearchExecutor {
new Promise((resolve, reject) => {
StardustTangleHelper.tryFetchNodeThenPermanode<string, OutputResponse>(
searchQuery.output,
"output",
"getOutput",
network
).then(
output => {
Expand All @@ -148,13 +148,13 @@ export class SearchExecutor {
if (searchQuery.aliasId) {
promises.push(
new Promise((resolve, reject) => {
StardustTangleHelper.tryFetchNodeThenPermanode<string, IOutputsResponse>(
StardustTangleHelper.tryFetchNodeThenPermanode<string, string>(
searchQuery.aliasId,
"alias",
"aliasOutputId",
network
).then(
aliasOutputs => {
if (aliasOutputs.items.length > 0) {
if (aliasOutputs) {
promisesResult = {
aliasId: searchQuery.aliasId
};
Expand All @@ -173,13 +173,13 @@ export class SearchExecutor {
if (searchQuery.nftId) {
promises.push(
new Promise((resolve, reject) => {
StardustTangleHelper.tryFetchNodeThenPermanode<string, IOutputsResponse>(
StardustTangleHelper.tryFetchNodeThenPermanode<string, string>(
searchQuery.nftId,
"nft",
"nftOutputId",
network
).then(
nftOutputs => {
if (nftOutputs.items.length > 0) {
if (nftOutputs) {
promisesResult = {
nftId: searchQuery.nftId
};
Expand All @@ -198,13 +198,13 @@ export class SearchExecutor {
if (searchQuery.foundryId) {
promises.push(
new Promise((resolve, reject) => {
StardustTangleHelper.tryFetchNodeThenPermanode<string, IOutputsResponse>(
StardustTangleHelper.tryFetchNodeThenPermanode<string, string>(
searchQuery.foundryId,
"foundry",
"foundryOutputId",
network
).then(
foundryOutputs => {
if (foundryOutputs.items.length > 0) {
foundryOutput => {
if (foundryOutput) {
promisesResult = {
foundryId: searchQuery.foundryId
};
Expand Down
10 changes: 8 additions & 2 deletions api/src/utils/stardust/stardustTangleHelper.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -30,6 +31,9 @@ import { INetwork } from "../../models/db/INetwork";
import { NodeInfoService } from "../../services/stardust/nodeInfoService";
import { HexHelper } from "../hexHelper";

type NameType<T> = T extends { name: infer U } ? U : never;
type ExtractedMethodNames = NameType<__ClientMethods__>;

/**
* Helper functions for use with tangle.
*/
Expand Down Expand Up @@ -598,7 +602,7 @@ export class StardustTangleHelper {
*/
public static async tryFetchNodeThenPermanode<A, R>(
args: A,
methodName: string,
methodName: ExtractedMethodNames,
network: INetwork
): Promise<R> | null {
const {
Expand All @@ -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)
Expand Down

0 comments on commit fe3a2ea

Please sign in to comment.