From c5799e3bed9e3c2fa8c6af4beb3a2d4ee9acf32a Mon Sep 17 00:00:00 2001 From: dayvvo Date: Mon, 20 Jan 2025 03:03:40 +0100 Subject: [PATCH 1/3] feat: add custom-timeout-values-for-requester-method --- src/NWCClient.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/NWCClient.ts b/src/NWCClient.ts index 68cfb29..bcf2566 100644 --- a/src/NWCClient.ts +++ b/src/NWCClient.ts @@ -67,6 +67,11 @@ export type Nip47PayResponse = { preimage: string; }; +type Nip47TimeoutValues = { + replyTimeout?: number; + publishTimeout?: number; +}; + export type Nip47MultiPayInvoiceRequest = { invoices: (Nip47PayInvoiceRequest & WithOptionalId)[]; }; @@ -544,6 +549,7 @@ export class NWCClient { "get_info", {}, (result) => !!result.methods, + { replyTimeout: 10000 }, ); return result; } catch (error) { @@ -819,6 +825,7 @@ export class NWCClient { nip47Method: Nip47SingleMethod, params: unknown, resultValidator: (result: T) => boolean, + timeoutValues?: Nip47TimeoutValues, ): Promise { await this._checkConnected(); await this._checkCompatibility(); @@ -867,7 +874,10 @@ export class NWCClient { ); } - const replyTimeoutCheck = setTimeout(replyTimeout, 60000); + const replyTimeoutCheck = setTimeout( + replyTimeout, + timeoutValues?.replyTimeout || 60000, + ); sub.onevent = async (event) => { // console.log(`Received reply event: `, event); @@ -930,7 +940,10 @@ export class NWCClient { ), ); } - const publishTimeoutCheck = setTimeout(publishTimeout, 5000); + const publishTimeoutCheck = setTimeout( + publishTimeout, + timeoutValues?.publishTimeout || 5000, + ); try { await this.relay.publish(event); From 7c1e8cb741b46bca41bfdfe8b6bec7ca9067ed78 Mon Sep 17 00:00:00 2001 From: dayvvo Date: Tue, 21 Jan 2025 23:43:19 +0100 Subject: [PATCH 2/3] fix: include shorter reply timeout for non payment requests --- src/NWCClient.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/NWCClient.ts b/src/NWCClient.ts index bcf2566..b3a7fa2 100644 --- a/src/NWCClient.ts +++ b/src/NWCClient.ts @@ -564,6 +564,7 @@ export class NWCClient { "get_budget", {}, (result) => result !== undefined, + { replyTimeout: 10000 }, ); return result; } catch (error) { @@ -578,6 +579,7 @@ export class NWCClient { "get_balance", {}, (result) => result.balance !== undefined, + { replyTimeout: 10000 }, ); return result; } catch (error) { @@ -727,6 +729,7 @@ export class NWCClient { "list_transactions", request, (response) => !!response.transactions, + { replyTimeout: 10000 }, ); return result; From 299fae4f888f81d6da1efc85e21b33305d63f496 Mon Sep 17 00:00:00 2001 From: dayvvo Date: Fri, 24 Jan 2025 10:35:16 +0100 Subject: [PATCH 3/3] feat: include custom timeout values for multirequest method --- src/NWCClient.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/NWCClient.ts b/src/NWCClient.ts index b3a7fa2..953d903 100644 --- a/src/NWCClient.ts +++ b/src/NWCClient.ts @@ -971,6 +971,7 @@ export class NWCClient { params: unknown, numPayments: number, resultValidator: (result: T) => boolean, + timeoutValues?: Nip47TimeoutValues, ): Promise<(T & { dTag: string })[]> { await this._checkConnected(); await this._checkCompatibility(); @@ -1020,7 +1021,10 @@ export class NWCClient { ); } - const replyTimeoutCheck = setTimeout(replyTimeout, 60000); + const replyTimeoutCheck = setTimeout( + replyTimeout, + timeoutValues?.replyTimeout || 60000, + ); sub.onevent = async (event) => { // console.log(`Received reply event: `, event); @@ -1102,7 +1106,10 @@ export class NWCClient { ), ); } - const publishTimeoutCheck = setTimeout(publishTimeout, 5000); + const publishTimeoutCheck = setTimeout( + publishTimeout, + timeoutValues?.publishTimeout || 5000, + ); try { await this.relay.publish(event);