diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/lightning.ts | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/lightning.ts b/lib/lightning.ts index 764ce627..0de5aa6b 100644 --- a/lib/lightning.ts +++ b/lib/lightning.ts @@ -10,6 +10,7 @@ const LISTENER_RETRY_DELAY = 5000; // 5 seconds const MAX_LISTENER_RETRIES = 10; let listenerRetries = 0; let listenerActive = false; +let lastPayTime = Date.now(); export async function listenForLightning() { if (listenerActive) { @@ -36,6 +37,7 @@ export async function listenForLightning() { } = inv; await s("pay_index", pay_index); + lastPayTime = Date.now(); // Reset retry counter on successful receive if (listenerRetries > 0) { @@ -119,6 +121,13 @@ export async function listenForLightning() { } } +export function ensureListenerAlive() { + if (!listenerActive) { + warn("lightning listener: not active, restarting"); + listenForLightning(); + } +} + export async function replay(index) { const inv = await lnListen.waitanyinvoice(index - 1); const { |
