From 4c596cfdcd04ee81ffc9be2e1ce2e5ee68154036 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 10 Oct 2022 18:47:11 +0000 Subject: fix liquid send --- routes/invoices.js | 32 ++++++++++++++++++++------------ routes/liquid/send.js | 8 ++++---- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/routes/invoices.js b/routes/invoices.js index 512679db..3a7f16b5 100644 --- a/routes/invoices.js +++ b/routes/invoices.js @@ -13,13 +13,13 @@ app.get("/invoice", async (req, res, next) => { try { const invoice = await db.Invoice.findOne({ where: { - uuid: req.query.uuid + uuid: req.query.uuid, }, include: { model: db.User, as: "user", - attributes: ["username", "currency"] - } + attributes: ["username", "currency"], + }, }); res.send(invoice); @@ -38,7 +38,7 @@ app.get("/invoice/:text", async (req, res, next) => { : text.startsWith("ln") ? { text } : { - [Op.or]: [{ unconfidential: text }, { address: text }] + [Op.or]: [{ unconfidential: text }, { address: text }], }; const invoice = await db.Invoice.findOne({ @@ -46,8 +46,8 @@ app.get("/invoice/:text", async (req, res, next) => { include: { model: db.User, as: "user", - attributes: ["username", "currency"] - } + attributes: ["username", "currency"], + }, }); res.send(invoice); @@ -71,12 +71,12 @@ app.post("/invoice", optionalAuth, async (req, res, next) => { else { user = await db.User.findOne({ where: { - username: user.username + username: user.username, }, include: { model: db.Account, - as: "account" - } + as: "account", + }, }); } if (!user) throw new Error("user not provided"); @@ -111,7 +111,7 @@ app.post("/invoice", optionalAuth, async (req, res, next) => { rate, tip, unconfidential, - user_id: user.id + user_id: user.id, }; if (network === "lightning") { @@ -121,8 +121,16 @@ app.post("/invoice", optionalAuth, async (req, res, next) => { } if (liquidAddress) { - l("conversion request for", liquidAddress, invoice.text); - store.convert[invoice.text] = { address: liquidAddress, tx }; + if (network === "lightning") { + l("conversion request for", liquidAddress, invoice.text); + store.convert[invoice.text] = { address: liquidAddress, tx }; + } else if (network === "liquid") { + l("conversion request for", liquidAddress, invoice.unconfidential); + store.convert[invoice.unconfidential] = { address: liquidAddress, tx }; + } else { + l("conversion request for", liquidAddress, invoice.address); + store.convert[invoice.address] = { address: liquidAddress, tx }; + } } l( diff --git a/routes/liquid/send.js b/routes/liquid/send.js index 2fa7a22a..d7a7c7b4 100644 --- a/routes/liquid/send.js +++ b/routes/liquid/send.js @@ -44,16 +44,16 @@ export const sendLiquid = async ({ asset, amount, user, address, memo, tx, limit let { asset, value, - scriptPubKey: { type, addresses } + scriptPubKey } = vout[i]; - if (type === "fee") fee = toSats(value); + if (scriptPubKey.type === "fee") fee = toSats(value); else { if (!totals[asset]) totals[asset] = change[asset] = 0; totals[asset] += toSats(value); - if (addresses) { - if (await isChange(addresses[0])) { + if (scriptPubKey.address) { + if (await isChange(scriptPubKey.address)) { change[asset] += toSats(value); } } -- cgit v1.2.3