diff options
| author | Adam Soltys <[email protected]> | 2022-09-02 14:47:08 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-09-02 14:47:14 -0700 |
| commit | 3161dd7ee95b6c7d70f8341298dd4fab84cda8b0 (patch) | |
| tree | 16cd6c55d5dc481331b1e8b640d179f193e7ea13 /lib/sync.js | |
| parent | 7a8d64833de8873afb92982b3f5bfff59b30c542 (diff) | |
| download | coinos-server-3161dd7ee95b6c7d70f8341298dd4fab84cda8b0.tar.gz coinos-server-3161dd7ee95b6c7d70f8341298dd4fab84cda8b0.zip | |
es6 migration
Diffstat (limited to 'lib/sync.js')
| -rw-r--r-- | lib/sync.js | 72 |
1 files changed, 38 insertions, 34 deletions
diff --git a/lib/sync.js b/lib/sync.js index ab1e81f0..1a98c121 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -1,7 +1,9 @@ -import { differenceInDays } from 'date-fns'; -import fs from 'fs'; -import read from '../lib/read.js'; -import { Op } from 'sequelize'; +import db from "../db/index.js"; +import app from "../app.js"; +import { differenceInDays } from "date-fns"; +import fs from "fs"; +import read from "../lib/read.js"; +import { Op } from "@sequelize/core"; const init = async () => { try { @@ -134,7 +136,12 @@ const sync = async () => { } } } catch (e) { - l.error("problem syncing lightning payment", JSON.stringify(missed[i]), e.message, e.stack); + l.error( + "problem syncing lightning payment", + JSON.stringify(missed[i]), + e.message, + e.stack + ); } } @@ -311,34 +318,31 @@ const sync = async () => { setTimeout(sync, 5000); -app.get( - "/conversions", - ah(async (req, res) => { - const transactions = [ - ...(await bc.listTransactions("*", 500)), - ...(await lq.listTransactions("*", 500)) - ].filter(tx => ["receive"].includes(tx.category)); +app.get("/conversions", 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"] + 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) + ); }) - ).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)) - ); - }) -); + .filter(c => !payments.includes(c)) + ); +}); |
