From 9d75cc562e60dba18d719bdba5913f63c0660e94 Mon Sep 17 00:00:00 2001 From: JCNoguera Date: Thu, 18 Jan 2024 16:55:48 +0100 Subject: [PATCH] fix: use both node and permanode for client data fetch --- api/src/initServices.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/api/src/initServices.ts b/api/src/initServices.ts index 4c643f32e..47764d29b 100644 --- a/api/src/initServices.ts +++ b/api/src/initServices.ts @@ -1,5 +1,5 @@ import { MqttClient as ChrysalisMqttClient } from "@iota/mqtt.js"; -import { Client as StardustClient } from "@iota/sdk"; +import { IClientOptions, Client as StardustClient } from "@iota/sdk"; import { ServiceFactory } from "./factories/serviceFactory"; import logger from "./logger"; import { IConfiguration } from "./models/configuration/IConfiguration"; @@ -141,10 +141,19 @@ function initChrysalisServices(networkConfig: INetwork): void { */ function initStardustServices(networkConfig: INetwork): void { logger.verbose(`Initializing Stardust services for ${networkConfig.network}`); - const stardustClient = new StardustClient({ + const stardustClientParams: IClientOptions = { nodes: [networkConfig.provider], brokerOptions: { useWs: true }, - }); + }; + + if (networkConfig.permaNodeEndpoint) { + // Use both the node and permaNode to fetch data correctly + // Reference: https://github.com/iotaledger/iota-sdk/issues/1808#issuecomment-1893331116 + stardustClientParams.permanodes = [networkConfig.permaNodeEndpoint]; + stardustClientParams.ignoreNodeHealth = true; + } + + const stardustClient = new StardustClient(stardustClientParams); ServiceFactory.register(`client-${networkConfig.network}`, () => stardustClient); if (networkConfig.permaNodeEndpoint) {