aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--routes/invoices.js2
-rw-r--r--routes/lightning/invoice.js11
-rw-r--r--routes/lightning/receive.js23
3 files changed, 17 insertions, 19 deletions
diff --git a/routes/invoices.js b/routes/invoices.js
index f36b497c..c6bf4b6e 100644
--- a/routes/invoices.js
+++ b/routes/invoices.js
@@ -4,7 +4,7 @@ app.post("/invoice", auth, async (req, res) => {
const { invoice } = req.body;
invoice.user_id = req.user.id;
- l.info("creating invoice", req.user.username, invoice.network, invoice.amount, invoice.tip, invoice.currency, invoice.rate.toFixed(2));
+ l.info("creating invoice", invoice.text, req.user.username, invoice.network, invoice.amount, invoice.tip, invoice.currency, invoice.rate.toFixed(2));
const exists = await db.Invoice.findOne({
where: {
diff --git a/routes/lightning/invoice.js b/routes/lightning/invoice.js
index 3f4ab1db..3b453a73 100644
--- a/routes/lightning/invoice.js
+++ b/routes/lightning/invoice.js
@@ -3,17 +3,6 @@ module.exports = async (req, res) => {
l.info("adding lightning invoice", req.user.username, amount, tip);
- /*
- const exists = await db.Invoice.findOne({
- where: {
- [Op.or]: {
- address: invoice.address || "undefined",
- text: invoice.text
- }
- }
- });
- */
-
try {
if (config.lna.clightning) {
const invoice = await lnb.invoice(`${amount + tip}sat` || "any", new Date(), "", 360);
diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js
index 3082c205..0e8d7e22 100644
--- a/routes/lightning/receive.js
+++ b/routes/lightning/receive.js
@@ -1,6 +1,8 @@
const asset = "LNBTC";
const handlePayment = async msg => {
+ try {
+ await db.transaction(async transaction => {
if (!msg.settled) return;
const invoice = await db.Invoice.findOne({
@@ -9,7 +11,7 @@ const handlePayment = async msg => {
}
});
- if (!invoice) return;
+ if (!invoice) return l.warn("received lightning with no invoice", msg.payment_request);
const { text: hash, currency, rate, tip, user_id } = invoice;
const amount = parseInt(msg.amt_paid_sat) - tip;
@@ -18,7 +20,9 @@ const handlePayment = async msg => {
where: {
user_id,
asset: config.liquid.btcasset
- }
+ },
+ lock: transaction.LOCK.UPDATE,
+ transaction
});
let preimage = msg.r_preimage.toString("hex");
@@ -35,17 +39,18 @@ const handlePayment = async msg => {
confirmed: true,
network: "LNBTC",
tip
- });
+ },
+ { transaction });
invoice.received += amount + tip;
account.balance += amount + tip;
- await account.save();
- await invoice.save();
- await payment.save();
+ await account.save({ transaction });
+ await invoice.save({ transaction });
+ await payment.save({ transaction });
payments.push(msg.payment_request);
- let user = await getUserById(user_id);
+ let user = await getUserById(user_id, transaction);
payment = payment.get({ plain: true });
payment.account = account.get({ plain: true });
@@ -58,6 +63,10 @@ const handlePayment = async msg => {
payment.amount,
payment.tip
);
+ });
+ } catch(e) {
+ l.error("problem receiving lightning payment", e.message);
+ }
};
if (config.lna.clightning) {