aboutsummaryrefslogtreecommitdiffstats
path: root/routes/lightning
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-06-08 13:04:02 -0700
committerAdam Soltys <[email protected]>2020-06-08 13:04:02 -0700
commit7a3a07bc711ea57fd8a84e809e7ecd0d6e64b5c2 (patch)
treeb31a06affa4b932990744997c271f6d65502d60c /routes/lightning
parent298672d3f50938ba06a16f8e04d607b7033703b8 (diff)
downloadcoinos-server-7a3a07bc711ea57fd8a84e809e7ecd0d6e64b5c2.tar.gz
coinos-server-7a3a07bc711ea57fd8a84e809e7ecd0d6e64b5c2.zip
reduce network traffic
Diffstat (limited to 'routes/lightning')
-rw-r--r--routes/lightning/receive.js10
-rw-r--r--routes/lightning/send.js14
2 files changed, 12 insertions, 12 deletions
diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js
index 0e8d7e22..6a9c95c8 100644
--- a/routes/lightning/receive.js
+++ b/routes/lightning/receive.js
@@ -21,10 +21,16 @@ const handlePayment = async msg => {
user_id,
asset: config.liquid.btcasset
},
+ include: {
+ model: db.User,
+ as: 'user',
+ },
lock: transaction.LOCK.UPDATE,
transaction
});
+ const { user } = account;
+
let preimage = msg.r_preimage.toString("hex");
let payment = await db.Payment.create({
@@ -50,12 +56,10 @@ const handlePayment = async msg => {
await payment.save({ transaction });
payments.push(msg.payment_request);
- let user = await getUserById(user_id, transaction);
-
payment = payment.get({ plain: true });
payment.account = account.get({ plain: true });
emit(user.username, "payment", payment);
- emit(user.username, "user", user);
+ emit(user.username, "account", payment.account);
l.info(
"lightning payment received",
diff --git a/routes/lightning/send.js b/routes/lightning/send.js
index e3b5c75a..9c4f2259 100644
--- a/routes/lightning/send.js
+++ b/routes/lightning/send.js
@@ -50,8 +50,9 @@ module.exports = async (req, res) => {
max_parts: 10
});
+ if (m.payment_error) throw new Error(m.payment_error);
+
({
- payment_error: error,
payment_route: { total_fees: fee, total_amt: total },
payment_preimage: preimage
} = m);
@@ -73,11 +74,6 @@ module.exports = async (req, res) => {
l.info("lnb sent back", amount);
}
- if (error) {
- l.error("error sending lightning", error);
- return res.status(500).send(error);
- }
-
if (seen.includes(preimage)) {
l.warn("duplicate payment detected", preimage);
throw new Error("Duplicate payment detected");
@@ -108,12 +104,12 @@ module.exports = async (req, res) => {
payment = payment.get({ plain: true });
payment.account = account.get({ plain: true });
+ emit(user.username, "account", payment.account);
+ emit(user.username, "payment", payment);
+
seen.push(preimage);
l.info("sent lightning", user.username, total);
- user = await getUser(user.username, transaction);
- emit(user.username, "user", user);
-
seen.push(hash);
res.send(payment);
});