aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sync.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-02-12 08:18:07 -0500
committerAdam Soltys <[email protected]>2022-02-12 08:18:17 -0500
commit98eceb8d3ad40a9952d143c89fa3cbc5a40db668 (patch)
treea63534adb1ce2489d8509739e854838876c59d5d /lib/sync.js
parent9d40e5686c12141b743e5e7acaab5117a6ce746d (diff)
downloadcoinos-server-98eceb8d3ad40a9952d143c89fa3cbc5a40db668.tar.gz
coinos-server-98eceb8d3ad40a9952d143c89fa3cbc5a40db668.zip
log payreq
Diffstat (limited to 'lib/sync.js')
-rw-r--r--lib/sync.js40
1 files changed, 31 insertions, 9 deletions
diff --git a/lib/sync.js b/lib/sync.js
index dd1ff9aa..dda83eab 100644
--- a/lib/sync.js
+++ b/lib/sync.js
@@ -48,16 +48,32 @@ const init = async () => {
} catch (e) {
console.log(e);
}
-};
-
-init();
-const sync = async () => {
- const payments = (
+ payments = (
await db.Payment.findAll({
attributes: ["hash"]
})
).map(p => p.hash);
+};
+
+init();
+
+const sync = async () => {
+ const twoWeeksAgo = new Date(new Date().setDate(new Date().getDate() - 14));
+ const payments = await db.Payment.findAll({
+ attributes: ["hash", "confirmed", "preimage"],
+ where: { createdAt: { [Op.gt]: twoWeeksAgo } },
+ include: [
+ {
+ model: db.Account,
+ as: "account"
+ },
+ {
+ model: db.User,
+ as: "user"
+ }
+ ]
+ });
try {
let { invoices } = await lnp.listInvoices({
@@ -181,7 +197,10 @@ const sync = async () => {
unaccounted = [];
transactions.map(tx => {
- if (!payments.includes(tx.txid) && !exceptions.includes(tx.txid)) {
+ if (
+ !payments.find(p => p.hash === tx.txid) &&
+ !exceptions.includes(tx.txid)
+ ) {
unaccounted.push(tx);
}
});
@@ -270,12 +289,11 @@ const sync = async () => {
};
setTimeout(sync, 5000);
-setInterval(sync, 720000);
+setInterval(sync, 300000);
app.get(
"/conversions",
ah(async (req, res) => {
-
const transactions = [
...(await bc.listTransactions("*", 500)),
...(await lq.listTransactions("*", 500))
@@ -294,7 +312,11 @@ app.get(
Object.keys(conversions)
.filter(c => conversions[c].address === addr)
.filter(c => {
- return invoices.find(i => i.payment_request === c && i.state === 'SETTLED') || transactions.find(tx => tx.txid === c)
+ return (
+ invoices.find(
+ i => i.payment_request === c && i.state === "SETTLED"
+ ) || transactions.find(tx => tx.txid === c)
+ );
})
.filter(c => !payments.includes(c))
);