diff options
| author | Adam Soltys <[email protected]> | 2021-05-13 02:24:05 -0400 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2021-05-13 02:24:05 -0400 |
| commit | 4d2379b801ed0a95e8538a64873a0be503e74672 (patch) | |
| tree | 8114688e98443e0ab536e7367eecb2f5d40aafe0 | |
| parent | 7d6d6ca74f1f271427c271382fff49446aaa1895 (diff) | |
| download | coinos-server-4d2379b801ed0a95e8538a64873a0be503e74672.tar.gz coinos-server-4d2379b801ed0a95e8538a64873a0be503e74672.zip | |
confidential to non-confidential liquid conversion
| -rw-r--r-- | lib/rates.js | 10 | ||||
| -rw-r--r-- | lib/sockets.js | 3 | ||||
| -rw-r--r-- | routes/invoices.js | 1 | ||||
| -rw-r--r-- | routes/lightning/receive.js | 1 | ||||
| -rw-r--r-- | routes/liquid/receive.js | 18 | ||||
| -rw-r--r-- | routes/liquid/send.js | 2 | ||||
| -rw-r--r-- | routes/users.js | 2 |
7 files changed, 29 insertions, 8 deletions
diff --git a/lib/rates.js b/lib/rates.js index b9e889fb..80c22bf0 100644 --- a/lib/rates.js +++ b/lib/rates.js @@ -27,7 +27,9 @@ let fetchRates; try { let { data: { rates: fx } - } = await axios.get(`http://data.fixer.io/api/latest?access_key=${config.fixer}`); + } = await axios.get( + `http://data.fixer.io/api/latest?access_key=${config.fixer}` + ); let USD = fx["USD"]; Object.keys(fx).map(k => { fx[k] = parseFloat((fx[k] / fx["USD"]).toFixed(6)); @@ -44,10 +46,12 @@ let fetchRates; setTimeout(fetchRates, 7200000); })(); -app.get('/rates', +app.get( + "/rates", ah(async (req, res, next) => { res.send(app.get("rates")); - })); + }) +); setInterval(() => { broadcast("rate", app.get("last")); diff --git a/lib/sockets.js b/lib/sockets.js index b6a806ff..931a9d23 100644 --- a/lib/sockets.js +++ b/lib/sockets.js @@ -92,10 +92,9 @@ wss.on("connection", function(ws, req) { case "login": let token = data; - if (differenceInSeconds(new Date(), subSeconds(lastSeen[token], 5)) < 2) return; + if (differenceInSeconds(new Date(), lastSeen[token]) < 5) return; lastSeen[token] = new Date(); - try { if (!token || token === "null") return ws.close(); const username = jwt.decode(token).username; diff --git a/routes/invoices.js b/routes/invoices.js index cdf8ca91..a1928287 100644 --- a/routes/invoices.js +++ b/routes/invoices.js @@ -40,6 +40,7 @@ app.post( if (!user) throw new Error("user not provided"); if (!invoice.currency) invoice.currency = user.currency; if (!invoice.rate) invoice.rate = app.get("rates")[invoice.currency]; + if (invoice.tip > invoice.amount || invoice.tip > 1000000) throw new Error("tip is too large") invoice.user_id = user.id; invoice.account_id = user.account_id; diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js index 8778bb22..325f7092 100644 --- a/routes/lightning/receive.js +++ b/routes/lightning/receive.js @@ -18,6 +18,7 @@ const handlePayment = async msg => { const { text: hash, currency, memo, rate, tip, user_id } = invoice; const amount = parseInt(msg.amt_paid_sat) - tip; + if (amount > 10000000 || amount < 0) throw new Error("amount out of range"); account = await db.Account.findOne({ where: { diff --git a/routes/liquid/receive.js b/routes/liquid/receive.js index 3ce6ca9a..f6a78cfa 100644 --- a/routes/liquid/receive.js +++ b/routes/liquid/receive.js @@ -287,6 +287,7 @@ setInterval(async () => { for (let i = 0; i < arr.length; i++) { const hash = arr[i]; + let account, address, user, total; await db.transaction(async transaction => { let p = await db.Payment.findOne({ where: { hash, confirmed: 0, received: 1 }, @@ -304,7 +305,7 @@ setInterval(async () => { transaction }); - const { user } = p; + ({ account, address, user } = p); if (p && p.account) { let total = p.amount + p.tip; @@ -340,6 +341,21 @@ setInterval(async () => { delete queue[hash]; }); + + let c = convert[address]; + if (c) { + let { tx } = c; + user.account = account; + + delete queue[hash]; + + await sendLiquid({ + address, + user, + tx, + limit: total + }); + } } } catch (e) { l.error("problem processing queued liquid transaction", e.message); diff --git a/routes/liquid/send.js b/routes/liquid/send.js index 0729370c..b80471b0 100644 --- a/routes/liquid/send.js +++ b/routes/liquid/send.js @@ -158,6 +158,6 @@ module.exports = ah(async (req, res) => { res.send(await sendLiquid({ user, address, memo, tx })); } catch (e) { l.error("problem sending liquid", user.username, e.message); - return res.status(500).send(e.message); + return res.status(500).send(e); } }); diff --git a/routes/users.js b/routes/users.js index d2cf6f2a..44478c0a 100644 --- a/routes/users.js +++ b/routes/users.js @@ -161,7 +161,7 @@ app.post( return res.status(500).send("Username taken"); } else { sockets[username] = sockets[user.username]; - l.info("changing username", user.username, username); + if (user.username !== username) l.info("changing username", user.username, username); user.username = username; token = jwt.sign({ username }, config.jwt); |
