From 2cc2510c078ed0acae1f3de1e9f1ec8f38776263 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 11 Mar 2022 01:19:34 -0500 Subject: upgrade pm2 --- lib/sync.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/sync.js b/lib/sync.js index d7bdb4c5..dda83eab 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -288,8 +288,8 @@ const sync = async () => { } }; -//setTimeout(sync, 5000); -//setInterval(sync, 300000); +setTimeout(sync, 5000); +setInterval(sync, 300000); app.get( "/conversions", -- cgit v1.2.3 From 5576f07a5a29bc8f2cb0695f5e12b4603b2771f9 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 25 Mar 2022 23:47:57 -0400 Subject: wait for 2 confs before reporting unconfirmed txns --- lib/sync.js | 9 ++++++--- routes/users.js | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/sync.js b/lib/sync.js index dda83eab..10e857b3 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -173,12 +173,13 @@ const sync = async () => { missed = transactions.filter( tx => tx.category === "receive" && - tx.confirmations > 0 && + tx.confirmations > 2 && hashes.includes(tx.txid) ); for (let i = 0; i < missed.length; i++) { let p = unconfirmed.find(p => p.hash === missed[i].txid); + /* p.confirmed = 1; await db.transaction(async transaction => { @@ -190,8 +191,9 @@ const sync = async () => { emit(p.user.username, "account", p.account); emit(p.user.username, "payment", p); + */ - l.info("confirmed tx", p.user_id, p.hash, p.address); + l.info("unconfirmed tx", p.user_id, p.hash, p.address); } unaccounted = []; @@ -286,10 +288,11 @@ const sync = async () => { } catch (e) { l.error("sync check failed", e.message, e.stack); } + + setTimeout(sync, 300000); }; setTimeout(sync, 5000); -setInterval(sync, 300000); app.get( "/conversions", diff --git a/routes/users.js b/routes/users.js index 403c4646..549de828 100644 --- a/routes/users.js +++ b/routes/users.js @@ -358,7 +358,7 @@ app.post( user = pick(user, ...whitelist); res.send({ user, token }); } catch (e) { - l.error("login error", e.message); + l.error("login error", e.message, req.connection.remoteAddress); res.status(401).end(); } }) @@ -420,7 +420,7 @@ app.post( user = pick(user, ...whitelist); res.send({ user, token }); } catch (e) { - l.error("login error", e.message); + l.error("login error", e.message, req.connection.remoteAddress); res.status(401).end(); } }) -- cgit v1.2.3 From 2e585488fd58e90264da5a5e5c25e1e397b56145 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 2 Apr 2022 02:30:19 -0400 Subject: check invoices up to 30 days ago --- lib/send.js | 3 +++ lib/sync.js | 20 ++------------------ 2 files changed, 5 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/lib/send.js b/lib/send.js index 4d3201fa..1f7e6369 100644 --- a/lib/send.js +++ b/lib/send.js @@ -24,6 +24,7 @@ send = async (amount, memo, hash, user) => { let error, fee, total, preimage, payment; await db.transaction(async transaction => { + l.info("starting lightning send transaction"); let account; if (user.account.asset === config.liquid.btcasset) account = await db.Account.findOne({ @@ -94,6 +95,8 @@ send = async (amount, memo, hash, user) => { }); await db.transaction(async transaction => { + l.info("starting lightning fee transaction"); + let account; if (user.account.asset === config.liquid.btcasset) account = await db.Account.findOne({ diff --git a/lib/sync.js b/lib/sync.js index 10e857b3..6c048388 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -11,13 +11,13 @@ const init = async () => { } try { - const twoDays = new Date(new Date().setDate(new Date().getDate() - 2)); + const thirtyDays = new Date(new Date().setDate(new Date().getDate() - 30)); ( await db.Invoice.findAll({ where: { createdAt: { - [Op.gt]: twoDays + [Op.gt]: thirtyDays } }, include: { @@ -33,22 +33,6 @@ const init = async () => { console.log(e); } - try { - const accounts = await db.Account.findAll({ - where: { pubkey: { [Op.ne]: null } }, - include: { - model: db.User, - as: "user" - } - }); - - accounts.map(({ address, user: { username } }) => { - addresses[address] = username; - }); - } catch (e) { - console.log(e); - } - payments = ( await db.Payment.findAll({ attributes: ["hash"] -- cgit v1.2.3 From d72de475b6621fb6ef31c03c2cf4d3ca1e82f5f2 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 2 Apr 2022 03:19:06 -0400 Subject: find missed payments --- lib/sync.js | 68 +++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 29 deletions(-) (limited to 'lib') diff --git a/lib/sync.js b/lib/sync.js index 6c048388..d6adba2e 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -17,7 +17,7 @@ const init = async () => { await db.Invoice.findAll({ where: { createdAt: { - [Op.gt]: thirtyDays + [Op.gt]: thirtyDays } }, include: { @@ -150,8 +150,8 @@ const sync = async () => { let hashes = unconfirmed.map(p => p.hash); const transactions = [ - ...(await bc.listTransactions("*", 50)), - ...(await lq.listTransactions("*", 50)) + ...(await bc.listTransactions("*", 500)), + ...(await lq.listTransactions("*", 500)) ].filter(tx => ["send", "receive"].includes(tx.category)); missed = transactions.filter( @@ -199,7 +199,9 @@ const sync = async () => { let receipts = unaccounted .filter( - tx => tx.category === "receive" && tx.asset === config.liquid.btcasset + tx => + tx.category === "receive" && + (!tx.asset || tx.asset === config.liquid.btcasset) ) .map(tx => tx.address); @@ -237,37 +239,45 @@ const sync = async () => { user_id } = invoices[i]; - let { amount, txid: hash } = unaccounted.find( + l.info("unaccounted", address); + + let pending = unaccounted.filter( tx => tx.address === address || tx.address === unconfidential ); - amount = toSats(amount); + for (let i = 0; i < pending.length; i++) { + let { amount, txid: hash } = pending[i]; + + amount = toSats(amount); + + await db.transaction(async transaction => { + payments.push(hash); + let p = await db.Payment.create( + { + account_id, + address: address || unconfidential, + amount, + confirmed: false, + currency, + hash, + invoice_id, + network, + rate, + received: true, + tip, + user_id + }, + { transaction } + ); - await db.transaction(async transaction => { - payments.push(hash); - let p = await db.Payment.create( - { - account_id, - address: address || unconfidential, - amount, - confirmed: false, - currency, - hash, - invoice_id, - network, - rate, - received: true, - tip, - user_id - }, - { transaction } - ); + await account.increment({ pending: amount }, { transaction }); - await account.increment({ pending: amount }, { transaction }); + l.info("found pending balance", user.username, amount); - emit(user.username, "account", account); - emit(user.username, "payment", p); - }); + emit(user.username, "account", account); + emit(user.username, "payment", p); + }); + } } } catch (e) { l.error("sync check failed", e.message, e.stack); -- cgit v1.2.3