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 | |
| parent | 13352f9b30eed52d2e7d0970d3cbd76f401d6de0 (diff) | |
| download | coinos-server-981321e3722af3aba217aeddfba3843615085ec7.tar.gz coinos-server-981321e3722af3aba217aeddfba3843615085ec7.zip | |
es6 migration
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/buildliquidtx.js | 3 | ||||
| -rw-r--r-- | lib/buildtx.js | 3 | ||||
| -rw-r--r-- | lib/ln.js | 17 | ||||
| -rw-r--r-- | lib/lnd.js | 2 | ||||
| -rw-r--r-- | lib/rates.js | 2 | ||||
| -rw-r--r-- | lib/rpc.js | 6 | ||||
| -rw-r--r-- | lib/sync.js | 42 |
7 files changed, 32 insertions, 43 deletions
diff --git a/lib/buildliquidtx.js b/lib/buildliquidtx.js index 783e4036..81e3d971 100644 --- a/lib/buildliquidtx.js +++ b/lib/buildliquidtx.js @@ -1,3 +1,4 @@ +import store from "./store.js"; import { prod } from "./utils.js"; import axios from 'axios'; // import liquid from 'liquidjs-lib'; @@ -105,7 +106,7 @@ export default async ({ total += value; if (!address) { address = changeAddress; - change.push(address); + store.change.push(address); } psbt = psbt.addOutput({ diff --git a/lib/buildtx.js b/lib/buildtx.js index e6dde1d2..e65bea7d 100644 --- a/lib/buildtx.js +++ b/lib/buildtx.js @@ -1,3 +1,4 @@ +import store from "./store.js"; import { prod } from "./utils.js"; import axios from 'axios'; import bitcoin from 'bitcoinjs-lib'; @@ -53,7 +54,7 @@ export default async ({ address, amount, feeRate, replaceable, user }) => { total += value; if (!address) { address = payments[payments.length - 1].address; - change.push(address); + store.change.push(address); } psbt = psbt.addOutput({ @@ -4,22 +4,7 @@ let ln; if (config.lna.clightning) { ln = (await import("clightning-client"))(config.lna.dir); } else { - let lnd = await import("../lib/lnd"); - ln = [ - "addInvoice", - "channelBalance", - "connectPeer", - "decodePayReq", - "getInfo", - "listInvoices", - "listPayments", - "sendPaymentSync", - "walletBalance" - ].reduce( - (a, b) => - (a[b] = args => new Promise(r => lnd[b](args, (e, v) => r(v)))) && a, - {} - ); + ln = (await import("./lnd.js")); } export default ln; @@ -1,4 +1,4 @@ -import { promisify } from 'util'; +import config from "../config/index.js"; import { authenticatedLndGrpc } from 'lightning'; const { cert, macaroon, socket } = config.lna; diff --git a/lib/rates.js b/lib/rates.js index 5e24cff0..d22bf2f5 100644 --- a/lib/rates.js +++ b/lib/rates.js @@ -46,7 +46,7 @@ let fetchRates; } } - store.fx = fx; + store.fx = fx; setTimeout(fetchRates, 7200000); })(); @@ -1,6 +1,6 @@ import wretch from "./wretch.js"; -export default ({ host, port, wallet, user, password }) => +export default ({ host, port, wallet, username, password }) => new Proxy( {}, { @@ -9,7 +9,9 @@ export default ({ host, port, wallet, user, password }) => wretch() .url(`http://${host}:${port}/wallet/${wallet}`) .auth( - `Basic ${Buffer.from(`${user}:${password}`).toString("base64")}` + `Basic ${Buffer.from(`${username}:${password}`).toString( + "base64" + )}` ) .post({ method, 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); } |
