diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/send.js | 3 | ||||
| -rw-r--r-- | lib/sockets.js | 39 |
2 files changed, 31 insertions, 11 deletions
diff --git a/lib/send.js b/lib/send.js index 71209456..7850da08 100644 --- a/lib/send.js +++ b/lib/send.js @@ -1,6 +1,6 @@ const bolt11 = require("bolt11"); -send = async (amount, hash, user) => { +send = async (amount, memo, hash, user) => { let payreq = bolt11.decode(hash); if (!amount) amount = payreq.satoshis; @@ -93,6 +93,7 @@ send = async (amount, hash, user) => { account_id: account.id, user_id: user.id, hash, + memo, preimage, rate: app.get("rates")[user.currency], currency: user.currency, diff --git a/lib/sockets.js b/lib/sockets.js index d0f00771..2dae9e93 100644 --- a/lib/sockets.js +++ b/lib/sockets.js @@ -26,19 +26,19 @@ broadcast = (type, data) => { } }; -server.on("upgrade", function(req, socket, head) { - wss.handleUpgrade(req, socket, head, function(ws) { +server.on("upgrade", function (req, socket, head) { + wss.handleUpgrade(req, socket, head, function (ws) { wss.emit("connection", ws, req); }); }); const names = {}; -wss.on("connection", function(ws, req) { +wss.on("connection", function (ws, req) { const id = uuidv4(); ws.send(JSON.stringify({ type: "connected" })); - ws.on("message", async message => { + ws.on("message", async (message) => { let type, data; try { ({ type, data } = JSON.parse(message)); @@ -57,22 +57,24 @@ wss.on("connection", function(ws, req) { const existing = Object.keys(sockets[username]); if (existing.length > 5) { l.warn("too many sockets, logging out", existing[0]); - sockets[username][existing[0]].send(JSON.stringify({ type: "login", data: false })); - } + sockets[username][existing[0]].send( + JSON.stringify({ type: "login", data: false }) + ); + } sockets[username][id] = ws; names[id] = username; let user = await getUser(username); let payments = await user.getPayments({ where: { - account_id: user.account_id + account_id: user.account_id, }, order: [["id", "DESC"]], limit: 12, include: { model: db.Account, - as: "account" - } + as: "account", + }, }); let accounts = await user.getAccounts(); let keys = await user.getKeys(); @@ -106,12 +108,29 @@ wss.on("connection", function(ws, req) { case "lnurl": sessions[data] = ws; break; + case "updateMemo": + const payment = await db.Payment.findOne({ + where: { + user_id: ws.user.id, + id: data.id, + }, + include: { + model: db.Account, + as: "account", + }, + }); + if (payment) { + payment.memo = data.memo; + await payment.save(); + emit(ws.user.username, "payment", payment); + } + break; default: l.warn("received socket message of unknown type", type, data); } }); - ws.on("close", function() { + ws.on("close", function () { try { const username = names[id]; if (sockets[username] && sockets[username][id]) |
