diff options
| author | Adam Soltys <[email protected]> | 2024-12-03 14:48:31 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-12-03 14:48:31 -0800 |
| commit | ad4f2d37de749748de44523714790a215c846086 (patch) | |
| tree | a21a8b5bb7b29888bbdd8a5aa2d298316162ebd7 | |
| parent | 0a318bf04d7691b47f65e1aa431a618d9bd935c0 (diff) | |
| download | coinos-server-ad4f2d37de749748de44523714790a215c846086.tar.gz coinos-server-ad4f2d37de749748de44523714790a215c846086.zip | |
handle keysend failure
| -rw-r--r-- | lib/nwc.ts | 34 |
1 files changed, 19 insertions, 15 deletions
@@ -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() { |
