aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2021-08-03 04:47:20 -0400
committerAdam Soltys <[email protected]>2021-08-03 04:47:20 -0400
commit1fbae57bb9540b1c116efc367809ac01ae2e9df2 (patch)
treee32613e98db8d813864623ab4c31dfb17280be0e
parent05f4be452167da0ee719b6d27b16299c189a748c (diff)
downloadcoinos-server-1fbae57bb9540b1c116efc367809ac01ae2e9df2.tar.gz
coinos-server-1fbae57bb9540b1c116efc367809ac01ae2e9df2.zip
move lightning invoice fetch out of db transaction
-rw-r--r--routes/lightning/receive.js31
1 files changed, 17 insertions, 14 deletions
diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js
index 55193d2d..492320d3 100644
--- a/routes/lightning/receive.js
+++ b/routes/lightning/receive.js
@@ -1,20 +1,18 @@
const handlePayment = async msg => {
+ if (!msg.settled) return;
let account, total, user;
- try {
- await db.transaction(async transaction => {
- if (!msg.settled) return;
- const invoice = await db.Invoice.findOne({
- where: {
- text: msg.payment_request
- }
- });
+ const invoice = await db.Invoice.findOne({
+ where: {
+ text: msg.payment_request
+ }
+ });
- if (!invoice)
- return l.warn(
- "received lightning with no invoice",
- msg.payment_request
- );
+ if (!invoice)
+ return l.warn("received lightning with no invoice", msg.payment_request);
+
+ try {
+ await db.transaction(async transaction => {
const { text: hash, currency, memo, rate, tip, user_id } = invoice;
const amount = parseInt(msg.amt_paid_sat) - tip;
@@ -83,7 +81,12 @@ const handlePayment = async msg => {
let c = convert[msg.payment_request];
if (msg.payment_request && c) {
- l.info("lightning detected for conversion request", msg.payment_request, c.address, user.username);
+ l.info(
+ "lightning detected for conversion request",
+ msg.payment_request,
+ c.address,
+ user.username
+ );
user.account = account;