diff options
| -rw-r--r-- | package.json | 2 | ||||
| -rw-r--r-- | routes/bitcoin/receive.js | 6 | ||||
| -rw-r--r-- | routes/lightning/receive.js | 1 | ||||
| -rw-r--r-- | routes/lnurl.js | 13 | ||||
| -rw-r--r-- | routes/send.js | 4 |
5 files changed, 16 insertions, 10 deletions
diff --git a/package.json b/package.json index 870ceada..06c8a26f 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.0.1", "private": true, "scripts": { - "start": "DEBUG=lnurl* NODE_OPTIONS=\"--es-module-specifier-resolution=node --experimental-modules --loader ./loader.js --openssl-legacy-provider\" nodemon index.js", + "start": "NODE_OPTIONS=\"--es-module-specifier-resolution=node --experimental-modules --loader ./loader.js --openssl-legacy-provider\" nodemon index.js", "generate": "sequelize-automate -c config/index.js", "min": "DEBUG=debug SCOPE=MIN nodemon index.js", "debug": "DEBUG=debug nodemon index.js" diff --git a/routes/bitcoin/receive.js b/routes/bitcoin/receive.js index 7fc685c5..544021b0 100644 --- a/routes/bitcoin/receive.js +++ b/routes/bitcoin/receive.js @@ -32,6 +32,7 @@ const seen = []; zmqRawTx.on("message", async (topic, message, sequence) => { + try { const hex = message.toString("hex"); let tx = bitcoin.Transaction.fromHex(message); @@ -152,10 +153,13 @@ zmqRawTx.on("message", async (topic, message, sequence) => { }); } } catch (e) { - console.log(e); + console.log("problem parsing bitcoin tx", e); } }) ); + } catch(e) { + console.log("problem receiving bitcoin tx", e); + } }); zmqRawBlock.on("message", async (topic, message, sequence) => { diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js index 0e241dbd..56714da7 100644 --- a/routes/lightning/receive.js +++ b/routes/lightning/receive.js @@ -12,6 +12,7 @@ import { l, err, warn } from "$lib/logging"; const handlePayment = async msg => { try { + console.log(msg) l("incoming lightning payment", msg.received); if (!msg.secret) return; diff --git a/routes/lnurl.js b/routes/lnurl.js index 6eab008a..d7d6b172 100644 --- a/routes/lnurl.js +++ b/routes/lnurl.js @@ -15,7 +15,8 @@ import jwt from "jsonwebtoken"; import qs from "query-string"; import bolt11 from "bolt11"; -import { createInvoice, getPayments } from "lightning"; + +import { createInvoice, decodePaymentRequest, getPayments } from "lightning"; import { computeConversionFee, @@ -197,8 +198,7 @@ app.post("/pay", auth, async (req, res, next) => { lnurlPayments[secret] = user.id; if (recipients[secret]) { - url = `${req.protocol}://${req.get("host")}/api/send`; - console.log(url); + url = `https://coinos.io/api/send`; const { data } = await axios.post( url, { @@ -208,7 +208,7 @@ app.post("/pay", auth, async (req, res, next) => { }, { headers: { - Authorization: req.get("Authorization") + authorization: req.headers.authorization } } ); @@ -219,7 +219,6 @@ app.post("/pay", auth, async (req, res, next) => { res.send(await send(amount, "", data.pr, user)); } } catch (e) { - console.log(e); err("failed to send payment", e.message); res.code(500).send(e.message); } @@ -305,7 +304,7 @@ lnurlServer.bindToHook( const { amount: msats, key, tag, pr, k1 } = req.query; if (msats) { - amount = Math.round(msats / 1000); + let amount = Math.round(msats / 1000); const parts = req.originalUrl.split("/"); const secret = parts[parts.length - 1].split("?")[0]; let user_id = lnurlPayments[secret]; @@ -505,7 +504,7 @@ lnurlServer.bindToHook( } } - if (next) next(req, res); + if (next) next(); } catch (e) { err("unhandled lnurerr", e.message); } diff --git a/routes/send.js b/routes/send.js index 002ce8d8..5d46f4de 100644 --- a/routes/send.js +++ b/routes/send.js @@ -30,7 +30,7 @@ export default async (req, res, next) => { try { await db.transaction(async transaction => { let account; - if (user.account.asset === asset) { + if (user.account.asset === asset && !user.account.pubkey) { account = await db.Account.findOne({ where: { id: user.account.id, @@ -51,6 +51,8 @@ export default async (req, res, next) => { }); } + if (!account) throw new Error("Account not found"); + if (account.balance < amount) { throw new Error("Insufficient funds"); } |
