diff options
| author | Adam Soltys <[email protected]> | 2021-08-04 07:00:20 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2021-08-04 08:16:43 -0700 |
| commit | ea2c9ed23c2b80f4a6200ee19fb4a6c77c3ccb95 (patch) | |
| tree | 1bb8ebcdf7b5bdbdc92ee536ef5517e711e9388c /routes | |
| parent | cfa93d65f113b4eed50cc88be76eeefa04a900eb (diff) | |
| download | coinos-server-ea2c9ed23c2b80f4a6200ee19fb4a6c77c3ccb95.tar.gz coinos-server-ea2c9ed23c2b80f4a6200ee19fb4a6c77c3ccb95.zip | |
config update, lnd support
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/assets.js | 1 | ||||
| -rw-r--r-- | routes/info.js | 6 | ||||
| -rw-r--r-- | routes/lightning/channel.js | 4 | ||||
| -rw-r--r-- | routes/lightning/invoice.js | 5 | ||||
| -rw-r--r-- | routes/lightning/send.js | 2 | ||||
| -rw-r--r-- | routes/lnurl.js | 8 | ||||
| -rw-r--r-- | routes/payments.js | 69 |
7 files changed, 55 insertions, 40 deletions
diff --git a/routes/assets.js b/routes/assets.js index 3f483a28..fe667dd9 100644 --- a/routes/assets.js +++ b/routes/assets.js @@ -148,7 +148,6 @@ app.post( const brt = await lq.blindRawTransaction(hex, true, [], false); const srt = await lq.signRawTransactionWithWallet(brt); const allowed = (await lq.testMempoolAccept([srt.hex]))[0].allowed; - fs.writeFileSync('tx', srt.hex); if (!allowed) throw new Error("issuance rejected by mempool"); const txid = await lq.sendRawTransaction(srt.hex); diff --git a/routes/info.js b/routes/info.js index f8a0fa72..6d9d5f32 100644 --- a/routes/info.js +++ b/routes/info.js @@ -34,9 +34,9 @@ app.get("/balances", ah(async (req, res, next) => { lnchannel = parseInt(funds.channels.reduce((a, b) => a + b.channel_sat, 0)); lnwallet = parseInt(funds.outputs.reduce((a, b) => a + b.value, 0)); } else { - lninfo = await lna.getInfo({}); - lnchannel = parseInt((await lna.channelBalance({})).balance); - lnwallet = parseInt((await lna.walletBalance({})).total_balance); + lninfo = await lnp.getInfo({}); + lnchannel = parseInt((await lnp.channelBalance({})).balance); + lnwallet = parseInt((await lnp.walletBalance({})).total_balance); } } diff --git a/routes/lightning/channel.js b/routes/lightning/channel.js index b6c4a25f..cb8ddf07 100644 --- a/routes/lightning/channel.js +++ b/routes/lightning/channel.js @@ -7,7 +7,7 @@ module.exports = ah(async (req, res) => { l.info("connecting to peer", req.user.username, pubkey, host); let result; try { - result = await lna.connectPeer({ + result = await lnp.connectPeer({ addr: { pubkey, host }, perm: true }); @@ -21,7 +21,7 @@ module.exports = ah(async (req, res) => { const { callback, k1 } = params; let remoteid; try { - remoteid = (await lna.getInfo({})).identity_pubkey; + remoteid = (await lnp.getInfo({})).identity_pubkey; } catch(e) { l.error("problem getting lightning node info", e.message); return res.status(500).send(e.message); diff --git a/routes/lightning/invoice.js b/routes/lightning/invoice.js index 1f3a0528..054a4a46 100644 --- a/routes/lightning/invoice.js +++ b/routes/lightning/invoice.js @@ -1,3 +1,4 @@ + module.exports = ah(async (req, res) => { let { amount, memo, tip } = req.body; if (!tip) tip = 0; @@ -14,11 +15,11 @@ module.exports = ah(async (req, res) => { ); res.send(invoice.bolt11); } else { - const invoice = await lna.addInvoice({ value, memo }); + const invoice = await lnp.addInvoice({ value, memo }); res.send(invoice.payment_request); } } catch (e) { - l.error("problem creating invoice", e.message); + l.error("problem creating invoice", e.message, e.stack); res.status(500).send(e.message); } }); diff --git a/routes/lightning/send.js b/routes/lightning/send.js index f6bd1b36..f3c0da46 100644 --- a/routes/lightning/send.js +++ b/routes/lightning/send.js @@ -5,7 +5,7 @@ module.exports = ah(async (req, res) => { try { res.send(await send(amount, memo, payreq, user)); } catch (e) { - l.error("problem sending lightning payment", user.username, e.message); + l.error("problem sending lightning payment", user.username, e.message, e.stack); res.status(500).send(e.message); } }); diff --git a/routes/lnurl.js b/routes/lnurl.js index f6b066ff..adf4df7c 100644 --- a/routes/lnurl.js +++ b/routes/lnurl.js @@ -90,7 +90,7 @@ app.post( amount: value, params: { callback, k1 } } = req.body; - const invoice = await lna.addInvoice({ value }); + const invoice = await lnp.addInvoice({ value }); const { payment_request: pr } = invoice; const url = `${callback}?k1=${k1}&pr=${pr}`; @@ -284,7 +284,7 @@ lnurlServer.bindToHook( if (recipient) { setTimeout(async () => { - let { invoices } = await lna.listInvoices({ + let { invoices } = await lnp.listInvoices({ pending_only: true }); @@ -352,7 +352,7 @@ lnurlServer.bindToHook( } try { - let decoded = await lna.decodePayReq({ pay_req: pr }); + let decoded = await lnp.decodePayReq({ pay_req: pr }); let amount = decoded.num_satoshis; await db.transaction(async transaction => { @@ -385,7 +385,7 @@ lnurlServer.bindToHook( setTimeout(async () => { try { - let { payments } = await lna.listPayments({ + let { payments } = await lnp.listPayments({ include_incomplete: false, max_payments: 5, reversed: true diff --git a/routes/payments.js b/routes/payments.js index a171b92f..70b711da 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -2,6 +2,7 @@ const BitcoinCore = require("@asoltys/bitcoin-core"); const { Op } = require("sequelize"); const { join } = require("path"); const fs = require("fs"); +const lnd = require("../lib/lnd"); const read = require("../lib/read"); ah(async () => { @@ -12,34 +13,34 @@ 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); } try { - ( - await db.Invoice.findAll({ - include: { - model: db.User, - as: "user", - }, - }) - ).map(({ address, user, unconfidential }) => { - if (address && user) addresses[address] = user.username; - if (unconfidential && user) addresses[unconfidential] = user.username; - }); - } catch(e) { + ( + await db.Invoice.findAll({ + include: { + model: db.User, + as: "user" + } + }) + ).map(({ address, user, unconfidential }) => { + if (address && user) addresses[address] = user.username; + if (unconfidential && user) addresses[unconfidential] = user.username; + }); + } catch (e) { console.log(e); - } + } try { const accounts = await db.Account.findAll({ where: { pubkey: { [Op.ne]: null } }, include: { model: db.User, - as: "user", - }, + as: "user" + } }); accounts.map(({ address, user: { username } }) => { @@ -51,36 +52,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); } @@ -96,7 +96,22 @@ ah(async () => { if (config.lna.clightning) { lna = require("clightning-client")(config.lna.dir); } else { - lna = lnd(config.lna); + lna = lnd.default; + lnp = [ + "addInvoice", + "channelBalance", + "connectPeer", + "decodePayReq", + "getInfo", + "listInvoices", + "listPayments", + "sendPaymentSync", + "walletBalance" + ].reduce( + (a, b) => + (a[b] = args => new Promise(r => lna[b](args, (e, v) => r(v)))) && a, + {} + ); } app.post("/lightning/channel", require("./lightning/channel")); @@ -152,7 +167,7 @@ ah(async () => { const parts = hdkeypath.split("/"); app.set("lqAddressIndex", parts[parts.length - 1].slice(0, -1)); } catch (e) { - console.error("Problem getting liquid address", e); + l.warn("Problem getting liquid address index", e.message); } }, 50); } |
