aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-11-06 11:23:32 -0800
committerAdam Soltys <[email protected]>2022-11-06 11:23:32 -0800
commit07a709c80da8a303b5cea23b5c193dd36302d6b4 (patch)
tree80568a48e4e4668eeb46c4310e420106a2df0e36 /routes
parent0290034a9ecd7fe3b5b93d8395e8a86cd0e3635e (diff)
downloadcoinos-server-07a709c80da8a303b5cea23b5c193dd36302d6b4.tar.gz
coinos-server-07a709c80da8a303b5cea23b5c193dd36302d6b4.zip
invoice requests
Diffstat (limited to 'routes')
-rw-r--r--routes/invoices.js35
1 files changed, 19 insertions, 16 deletions
diff --git a/routes/invoices.js b/routes/invoices.js
index c492b475..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, recipient } = 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,9 +151,12 @@ app.post("/invoice", optionalAuth, async (req, res, next) => {
if (blindkey) await lq.importBlindingKey(invoice.address, blindkey);
}
- if (recipient) {
- emit(recipient, "invoice", invoice.get({ plain: true {));
- }
+ if (requester) {
+ emit(requester, "invoice", {
+ uuid: invoice.uuid,
+ user: { username: user.username, profile: user.profile }
+ });
+ }
res.send(invoice);
} catch (e) {