diff options
| author | Adam Soltys <[email protected]> | 2022-09-02 23:32:30 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-09-02 23:32:30 -0700 |
| commit | 981321e3722af3aba217aeddfba3843615085ec7 (patch) | |
| tree | d46dab617a6e8f33980275db362aa000e0447939 /lib/sync.js | |
| parent | 13352f9b30eed52d2e7d0970d3cbd76f401d6de0 (diff) | |
| download | coinos-server-981321e3722af3aba217aeddfba3843615085ec7.tar.gz coinos-server-981321e3722af3aba217aeddfba3843615085ec7.zip | |
es6 migration
Diffstat (limited to 'lib/sync.js')
| -rw-r--r-- | lib/sync.js | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/lib/sync.js b/lib/sync.js index f1d28421..30d5b007 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -2,14 +2,20 @@ 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 read from "./read.js"; import { Op } from "@sequelize/core"; import store from "./store.js"; -import { err } from "./logging.js"; +import { l, err, warn } from "./logging.js"; +import lnd from "./lnd.js"; +import { getInvoices } from "lightning"; +import bc from "./bitcoin.js"; +import lq from "./liquid.js"; const init = async () => { try { - read(fs.createReadStream("exceptions"), data => store.exceptions.push(data)); + read(fs.createReadStream("exceptions"), data => + store.exceptions.push(data) + ); } catch (e) { warn("couldn't read exceptions file", e.message); } @@ -31,7 +37,8 @@ const init = async () => { }) ).map(({ address, user, unconfidential }) => { if (address && user) store.addresses[address] = user.username; - if (unconfidential && user) store.addresses[unconfidential] = user.username; + if (unconfidential && user) + store.addresses[unconfidential] = user.username; }); } catch (e) { console.log(e); @@ -65,10 +72,7 @@ const sync = async () => { ] }); - let { invoices } = await lnp.listInvoices({ - reversed: true, - num_max_invoices: 1000 - }); + let { invoices } = await getInvoices({ lnd, limit: 200 }); let recent = invoices .filter( @@ -202,26 +206,26 @@ const sync = async () => { } } - unaccounted = []; + store.unaccounted = []; transactions.map(tx => { if ( !payments.find(p => p.hash === tx.txid) && !store.exceptions.includes(tx.txid) && - !unaccounted.find(a => a.txid === tx.txid) && + !store.unaccounted.find(a => a.txid === tx.txid) && new Date(tx.blocktime * 1000) >= twoWeeksAgo ) { - unaccounted.push(tx); + store.unaccounted.push(tx); } }); - if (unaccounted.length) + if (store.unaccounted.length) warn( "wallet transactions missing from database", - unaccounted.map(tx => tx.txid) + store.unaccounted.map(tx => tx.txid) ); - let receipts = unaccounted + let receipts = store.unaccounted .filter( tx => tx.category === "receive" && @@ -265,7 +269,7 @@ const sync = async () => { l("unaccounted", address); - let pending = unaccounted.filter( + let pending = store.unaccounted.filter( tx => tx.address === address || tx.address === unconfidential ); @@ -302,16 +306,12 @@ const sync = async () => { emit(user.username, "payment", p); }); } catch (e) { - err( - "problem updating pending transaction", - hash, - e.message, - e.stack - ); + err("problem updating pending transaction", hash, e.message, e.stack); } } } } catch (e) { + console.log(e); err("sync check failed", e.message, e.stack); } |
