Skip to content

Commit

Permalink
fix: use both node and permanode for client data fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
VmMad committed Jan 18, 2024
1 parent a3ed15c commit 9d75cc5
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions api/src/initServices.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9d75cc5

Please sign in to comment.