diff options
| -rw-r--r-- | lib/countries.js | 4 | ||||
| -rw-r--r-- | lib/invoices.js | 20 | ||||
| -rw-r--r-- | lib/lightning.js | 9 | ||||
| -rw-r--r-- | lib/payments.js | 23 | ||||
| -rw-r--r-- | routes/invoices.js | 4 | ||||
| -rw-r--r-- | routes/payments.js | 9 |
6 files changed, 39 insertions, 30 deletions
diff --git a/lib/countries.js b/lib/countries.js index ad049fba..5fc19683 100644 --- a/lib/countries.js +++ b/lib/countries.js @@ -151,7 +151,7 @@ export default { NA: "NAM", NR: "NRU", NP: "NPL", - NL: "NLD", + NL: "EUR", AN: "ANG", NC: "XPF", NZ: "NZD", @@ -213,7 +213,7 @@ export default { SR: "SUR", SJ: "NOK", SZ: "SWZ", - SE: "SWE", + SE: "SEK", CH: "CHE", SY: "SYR", TW: "TWN", diff --git a/lib/invoices.js b/lib/invoices.js index b4583ea1..2e5a8e64 100644 --- a/lib/invoices.js +++ b/lib/invoices.js @@ -38,19 +38,15 @@ export let generate = async ({ invoice, user, sender, memo }) => { let hash, text; if (type === types.lightning) { - let r = await ln.invoice( - amount ? `${amount + tip}sat` : "any", - new Date(), - memo || "", - expiry || 3600, - undefined, - undefined, - undefined, - undefined, - true - ); + let r = await ln.invoice({ + amount_msat: amount ? `${amount + tip}sat` : "any", + label: new Date(), + description: memo || "", + expiry: expiry || 3600, + deschashonly: true + }); - hash = r.payment_hash; + hash = r.bolt11; text = r.bolt11; } else if (type === types.bitcoin) { hash = await bc.getNewAddress(); diff --git a/lib/lightning.js b/lib/lightning.js index 1ccdbaa4..0c5fd75e 100644 --- a/lib/lightning.js +++ b/lib/lightning.js @@ -10,7 +10,6 @@ import { credit, types } from "$lib/payments"; export async function listenForLightning() { let event = await ln.waitanyinvoice(await g("pay_index")); let { - payment_hash: hash, bolt11, pay_index, status, @@ -28,13 +27,13 @@ export async function listenForLightning() { if (!preimage) return; - let invoice = await g(`invoice:${hash}`); + let invoice = await g(`invoice:${bolt11}`); if (!invoice) return warn("received lightning with no invoice", bolt11); - let payment = await g(`payment:${hash}`); - if (payment) return warn("already processed", hash); + let payment = await g(`payment:${bolt11}`); + if (payment) return warn("already processed", bolt11); - await credit(hash, received, invoice.memo, preimage, types.lightning); + await credit(bolt11, received, invoice.memo, preimage, types.lightning); } catch (e) { console.log(e); err("problem receiving lightning payment", e.message); diff --git a/lib/payments.js b/lib/payments.js index c8e74201..48fc36a8 100644 --- a/lib/payments.js +++ b/lib/payments.js @@ -181,9 +181,26 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { callWebhook(invoice, p); if (user.hasprinter) { - let words = dollarsToWords( - parseFloat(((amount * p.rate) / 100000000).toFixed(2)) - ); + let fiat = parseFloat(((amount * p.rate) / 100000000).toFixed(2)); + let words = dollarsToWords(fiat); + + let client = mqtt.connect("mqtt://ln.coinos.io", config.mqtt); + client.subscribe(username); + + if (fiat === 0.02) { + words = "there is no second best"; + client.publish(username, "easter"); + } + + if (fiat === 0.21) { + words = "tick tock, next block"; + client.publish(username, "easter"); + } + + if (fiat === 0.69) { + words = "have fun staying poor"; + client.publish(username, "easter"); + } let client = mqtt.connect("mqtt://ln.coinos.io", config.mqtt); client.subscribe(username); diff --git a/routes/invoices.js b/routes/invoices.js index a1ead582..9f2e4c99 100644 --- a/routes/invoices.js +++ b/routes/invoices.js @@ -9,10 +9,6 @@ import ln from "$lib/ln"; export default { async get({ params: { hash } }, res) { let pr; - if (hash.startsWith("ln")) { - ({ payment_hash: hash } = await ln.decode(hash)); - } - let invoice = await g(`invoice:${hash}`); if (invoice) { diff --git a/routes/payments.js b/routes/payments.js index c13f7bec..383b89fc 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -61,11 +61,11 @@ export default { let total = amount; let { amount_msat, payment_hash } = await ln.decode(payreq); if (amount_msat) total = Math.round(amount_msat / 1000); - let invoice = await g(`invoice:${payment_hash}`); + let invoice = await g(`invoice:${payreq}`); if (invoice) { if (invoice.uid === user.id) fail("Cannot send to self"); - hash = payment_hash; + hash = payreq; } else { p = await debit(hash, total, maxfee, memo, user, types.lightning); @@ -79,7 +79,8 @@ export default { maxfee: maxfee * 1000, retry_for: 5 }); - if (r.status !== "complete") fail("payment did not complete"); + + if (r.status !== "complete" || !r.payment_preimage) fail("payment did not complete"); p.amount = -amount; p.tip = total - amount; @@ -93,7 +94,7 @@ export default { await db.incrBy(`balance:${p.uid}`, maxfee - p.fee); } catch (e) { warn("something went wrong", e.message); - if (!(r && r.status === "complete")) { + if (!(r && r.status === "complete" && r.payment_preimage)) { let credit = Math.round(total * config.fee) - p.ourfee; warn("crediting balance", total + maxfee + p.ourfee); await db.incrBy(`balance:${p.uid}`, total + maxfee + p.ourfee); |
