aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2021-05-13 02:24:05 -0400
committerAdam Soltys <[email protected]>2021-05-13 02:24:05 -0400
commit4d2379b801ed0a95e8538a64873a0be503e74672 (patch)
tree8114688e98443e0ab536e7367eecb2f5d40aafe0 /routes
parent7d6d6ca74f1f271427c271382fff49446aaa1895 (diff)
downloadcoinos-server-4d2379b801ed0a95e8538a64873a0be503e74672.tar.gz
coinos-server-4d2379b801ed0a95e8538a64873a0be503e74672.zip
confidential to non-confidential liquid conversion
Diffstat (limited to 'routes')
-rw-r--r--routes/invoices.js1
-rw-r--r--routes/lightning/receive.js1
-rw-r--r--routes/liquid/receive.js18
-rw-r--r--routes/liquid/send.js2
-rw-r--r--routes/users.js2
5 files changed, 21 insertions, 3 deletions
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);