From ad4f2d37de749748de44523714790a215c846086 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 3 Dec 2024 14:48:31 -0800 Subject: handle keysend failure --- lib/nwc.ts | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/nwc.ts b/lib/nwc.ts index 6313e05d..8961e8b0 100644 --- a/lib/nwc.ts +++ b/lib/nwc.ts @@ -144,24 +144,28 @@ const handle = (method, params, user, ev) => async pay_keysend() { const { amount, pubkey } = params; - const { payment_hash } = await sendKeysend({ - hash: ev.id, - amount, - pubkey, - user, - }); + try { + const { payment_hash } = await sendKeysend({ + hash: ev.id, + amount, + pubkey, + user, + }); - for (let i = 0; i < 10; i++) { - const { pays } = await ln.listpays({ payment_hash }); - const p = pays.find((p) => p.status === "complete"); - if (p) { - const { preimage } = p; - return result({ preimage }); + for (let i = 0; i < 10; i++) { + const { pays } = await ln.listpays({ payment_hash }); + const p = pays.find((p) => p.status === "complete"); + if (p) { + const { preimage } = p; + return result({ preimage }); + } + await sleep(2000); } - await sleep(2000); - } - return error({ code: "INTERNAL", message: "Payment timed out" }); + return error({ code: "INTERNAL", message: "Payment timed out" }); + } catch (e) { + return error({ code: "INTERNAL", message: "Keysend payment failed" }); + } }, async get_info() { -- cgit v1.2.3