diff options
| author | Adam Soltys <[email protected]> | 2021-05-30 06:38:58 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2021-06-09 16:06:45 -0700 |
| commit | c5374c599a9d96507bff6ff6d5b9e1f355e89eff (patch) | |
| tree | def064241e92be3f2f589dc67d161d25264dce59 /routes | |
| parent | 441cc95d60d198cc54a36a758d5fc8c4fe363938 (diff) | |
| download | coinos-server-c5374c599a9d96507bff6ff6d5b9e1f355e89eff.tar.gz coinos-server-c5374c599a9d96507bff6ff6d5b9e1f355e89eff.zip | |
changes to dev environment
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/lightning/invoice.js | 11 | ||||
| -rw-r--r-- | routes/payments.js | 54 |
2 files changed, 40 insertions, 25 deletions
diff --git a/routes/lightning/invoice.js b/routes/lightning/invoice.js index 140a3002..1f3a0528 100644 --- a/routes/lightning/invoice.js +++ b/routes/lightning/invoice.js @@ -1,13 +1,20 @@ module.exports = ah(async (req, res) => { let { amount, memo, tip } = req.body; if (!tip) tip = 0; + let value = amount + tip; try { if (config.lna.clightning) { - const invoice = await lna.invoice(`${amount + tip}sat` || "any", new Date(), memo, 360); + if (!memo) memo = "coinos"; + const invoice = await lna.invoice( + value ? `${value}sat` : "any", + new Date(), + memo, + 360 + ); res.send(invoice.bolt11); } else { - const invoice = await lna.addInvoice({ value: amount + tip, memo }); + const invoice = await lna.addInvoice({ value, memo }); res.send(invoice.payment_request); } } catch (e) { diff --git a/routes/payments.js b/routes/payments.js index 005223af..a52ad395 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -12,7 +12,7 @@ ah(async () => { const exceptions = []; try { - read(fs.createReadStream("exceptions"), data => exceptions.push(data)); + read(fs.createReadStream("exceptions"), (data) => exceptions.push(data)); } catch (e) { l.warn("couldn't read exceptions file", e.message); } @@ -21,8 +21,8 @@ ah(async () => { await db.Invoice.findAll({ include: { model: db.User, - as: "user" - } + as: "user", + }, }) ).map(({ address, user, unconfidential }) => { if (address && user) addresses[address] = user.username; @@ -34,8 +34,8 @@ ah(async () => { where: { pubkey: { [Op.ne]: null } }, include: { model: db.User, - as: "user" - } + as: "user", + }, }); accounts.map(({ address, user: { username } }) => { @@ -47,35 +47,35 @@ ah(async () => { payments = ( await db.Payment.findAll({ - attributes: ["hash"] + attributes: ["hash"], }) - ).map(p => p.hash); + ).map((p) => p.hash); setInterval(async () => { const unconfirmed = ( await db.Payment.findAll({ where: { - confirmed: 0 - } + confirmed: 0, + }, }) - ).map(p => p.hash); + ).map((p) => p.hash); const transactions = await bc.listTransactions("*", 1000); transactions .filter( - tx => + (tx) => tx.category === "receive" && tx.confirmations > 0 && unconfirmed.includes(tx.txid) ) - .map(tx => { + .map((tx) => { l.warn("tx unconfirmed in db", tx.txid, tx.address); }); const unaccounted = []; - transactions.map(tx => { + transactions.map((tx) => { if (!payments.includes(tx.txid) && !exceptions.includes(tx.txid)) { unaccounted.push(tx.txid); } @@ -89,8 +89,7 @@ ah(async () => { if (config.lna) { if (config.lna.clightning) { - const lnapath = join(require("os").homedir(), ".lightningreg/regtest"); - lna = require("clightning-client")(lnapath); + lna = require("clightning-client")(config.lna.dir); } else { throw new Error("lnd not supported"); } @@ -120,10 +119,14 @@ ah(async () => { require("./bitcoin/receive"); setTimeout(async () => { - const address = await bc.getNewAddress(); - const { hdkeypath } = await bc.getAddressInfo(address); - const parts = hdkeypath.split("/"); - app.set("bcAddressIndex", parts[parts.length - 1].slice(0, -1)); + try { + const address = await bc.getNewAddress(); + const { hdkeypath } = await bc.getAddressInfo(address); + const parts = hdkeypath.split("/"); + app.set("bcAddressIndex", parts[parts.length - 1].slice(0, -1)); + } catch (e) { + console.error(e); + } }, 50); } @@ -137,13 +140,18 @@ ah(async () => { require("./liquid/receive"); setTimeout(async () => { - const address = await lq.getNewAddress(); - const { hdkeypath } = await lq.getAddressInfo(address); - const parts = hdkeypath.split("/"); - app.set("lqAddressIndex", parts[parts.length - 1].slice(0, -1)); + try { + const address = await lq.getNewAddress(); + const { hdkeypath } = await lq.getAddressInfo(address); + const parts = hdkeypath.split("/"); + app.set("lqAddressIndex", parts[parts.length - 1].slice(0, -1)); + } catch (e) { + console.error(e); + } }, 50); } + app.get( "/payments", auth, |
