aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2021-12-20 20:03:41 -0500
committerAdam Soltys <[email protected]>2022-02-12 08:18:17 -0500
commit9d40e5686c12141b743e5e7acaab5117a6ce746d (patch)
treee4bd0f79db7d4aab7413836cc14cf77415171492 /lib
parent143fb28ba56c462665cd4a402390b3ac081e36df (diff)
downloadcoinos-server-9d40e5686c12141b743e5e7acaab5117a6ce746d.tar.gz
coinos-server-9d40e5686c12141b743e5e7acaab5117a6ce746d.zip
endpoint to get missed conversions
Diffstat (limited to 'lib')
-rw-r--r--lib/sync.js39
1 files changed, 34 insertions, 5 deletions
diff --git a/lib/sync.js b/lib/sync.js
index ba8d0a48..dd1ff9aa 100644
--- a/lib/sync.js
+++ b/lib/sync.js
@@ -48,17 +48,17 @@ const init = async () => {
} catch (e) {
console.log(e);
}
+};
+
+init();
- payments = (
+const sync = async () => {
+ const payments = (
await db.Payment.findAll({
attributes: ["hash"]
})
).map(p => p.hash);
-};
-
-init();
-const sync = async () => {
try {
let { invoices } = await lnp.listInvoices({
reversed: true,
@@ -271,3 +271,32 @@ const sync = async () => {
setTimeout(sync, 5000);
setInterval(sync, 720000);
+
+app.get(
+ "/conversions",
+ ah(async (req, res) => {
+
+ const transactions = [
+ ...(await bc.listTransactions("*", 500)),
+ ...(await lq.listTransactions("*", 500))
+ ].filter(tx => ["receive"].includes(tx.category));
+
+ const { addr } = req.query;
+ const { invoices } = require("./invoices");
+ const persist = require("./persist");
+ let conversions = persist("data/conversions.json");
+ const payments = (
+ await db.Payment.findAll({
+ attributes: ["hash"]
+ })
+ ).map(p => p.hash);
+ res.send(
+ 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)
+ })
+ .filter(c => !payments.includes(c))
+ );
+ })
+);