From dffa9c53e93006bfe30b42f5d27db51b8f5486e6 Mon Sep 17 00:00:00 2001 From: wphan Date: Wed, 10 Jan 2024 16:33:00 -0800 Subject: [PATCH] ts-sdk: filter out erroneous logs in EventSubscriber (#815) --- sdk/src/events/webSocketLogProvider.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sdk/src/events/webSocketLogProvider.ts b/sdk/src/events/webSocketLogProvider.ts index 4d82f89bd..9fb896f65 100644 --- a/sdk/src/events/webSocketLogProvider.ts +++ b/sdk/src/events/webSocketLogProvider.ts @@ -1,5 +1,11 @@ import { LogProvider, logProviderCallback } from './types'; -import { Commitment, Connection, PublicKey } from '@solana/web3.js'; +import { + Commitment, + Connection, + Context, + Logs, + PublicKey, +} from '@solana/web3.js'; import { EventEmitter } from 'events'; export class WebSocketLogProvider implements LogProvider { @@ -45,7 +51,7 @@ export class WebSocketLogProvider implements LogProvider { public setSubscription(callback: logProviderCallback): void { this.subscriptionId = this.connection.onLogs( this.address, - (logs, ctx) => { + (logs: Logs, ctx: Context) => { if (this.resubTimeoutMs && !this.isUnsubscribing) { this.receivingData = true; clearTimeout(this.timeoutId); @@ -55,6 +61,9 @@ export class WebSocketLogProvider implements LogProvider { } this.reconnectAttempts = 0; } + if (logs.err !== null) { + return; + } callback(logs.signature, ctx.slot, logs.logs, undefined); }, this.commitment