aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--routes/invoices.js33
-rw-r--r--routes/requests.js8
2 files changed, 27 insertions, 14 deletions
diff --git a/routes/invoices.js b/routes/invoices.js
index 6e0fe358..074aed61 100644
--- a/routes/invoices.js
+++ b/routes/invoices.js
@@ -8,18 +8,19 @@ import { err, l } from "$lib/logging";
import bc from "$lib/bitcoin";
import lq from "$lib/liquid";
import { SATS, bip21, deriveAddress, derivePayRequest } from "$lib/utils";
+import { emit } from "$lib/sockets";
app.get("/invoice", async (req, res, next) => {
try {
const invoice = await db.Invoice.findOne({
where: {
- uuid: req.query.uuid,
+ uuid: req.query.uuid
},
include: {
model: db.User,
as: "user",
- attributes: ["username", "currency"],
- },
+ attributes: ["username", "currency"]
+ }
});
res.send(invoice);
@@ -38,7 +39,7 @@ app.get("/invoice/:text", async (req, res, next) => {
: text.startsWith("ln")
? { text }
: {
- [Op.or]: [{ unconfidential: text }, { address: text }],
+ [Op.or]: [{ unconfidential: text }, { address: text }]
};
const invoice = await db.Invoice.findOne({
@@ -46,8 +47,8 @@ app.get("/invoice/:text", async (req, res, next) => {
include: {
model: db.User,
as: "user",
- attributes: ["username", "currency"],
- },
+ attributes: ["username", "currency"]
+ }
});
res.send(invoice);
@@ -60,23 +61,22 @@ app.get("/invoice/:text", async (req, res, next) => {
app.post("/invoice", optionalAuth, async (req, res, next) => {
try {
let { type = "bech32", liquidAddress, id, invoice, user, tx } = req.body;
- let { blindkey, currency, tip, amount, rate, network } = invoice;
+ let { blindkey, currency, tip, amount, rate, network, requester } = invoice;
let address, unconfidential, text;
if (amount < 0) throw new Error("amount out of range");
- if (tip > 5 * amount || tip < 0)
- throw new Error("tip amount out of range");
+ if (tip > 5 * amount || tip < 0) throw new Error("tip amount out of range");
if (!user) ({ user } = req);
else {
user = await db.User.findOne({
where: {
- username: user.username,
+ username: user.username
},
include: {
model: db.Account,
- as: "account",
- },
+ as: "account"
+ }
});
}
if (!user) throw new Error("user not provided");
@@ -110,7 +110,7 @@ app.post("/invoice", optionalAuth, async (req, res, next) => {
rate,
tip,
unconfidential,
- user_id: user.id,
+ user_id: user.id
};
if (network === "lightning") {
@@ -151,6 +151,13 @@ app.post("/invoice", optionalAuth, async (req, res, next) => {
if (blindkey) await lq.importBlindingKey(invoice.address, blindkey);
}
+ if (requester) {
+ emit(requester, "invoice", {
+ uuid: invoice.uuid,
+ user: { username: user.username, profile: user.profile }
+ });
+ }
+
res.send(invoice);
} catch (e) {
err(e.message, e.stack);
diff --git a/routes/requests.js b/routes/requests.js
index 823e92c1..a4aad29f 100644
--- a/routes/requests.js
+++ b/routes/requests.js
@@ -1,15 +1,21 @@
import app from "$app";
import db from "$db";
import { auth } from "$lib/passport";
+import { emit } from "$lib/sockets";
app.post("/requests", auth, async (req, res) => {
try {
let { recipient: username, ...params } = req.body;
- let { id: recipient_id } = await db.User.findOne({ where: { username }});
+ let { id: recipient_id } = await db.User.findOne({ where: { username } });
let request = await db.Request.create({ recipient_id, ...params });
+ request = request.get({ plain: true });
+ request.requester = { username: req.user.username, profile: req.user.profile };
+ emit(username, "request", request);
+
res.send(request);
} catch (e) {
+ console.log(e)
res.code(500).send(e.message);
}
});