From c6dc858ee5491e6c584d94d702438e9b24adbfc7 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 30 Aug 2021 14:48:26 -0700 Subject: handle conversions for internal payments --- routes/assets.js | 5 +++-- routes/liquid/send.js | 1 - routes/send.js | 23 ++++++++++++++++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) (limited to 'routes') diff --git a/routes/assets.js b/routes/assets.js index d163e8e6..72d4c329 100644 --- a/routes/assets.js +++ b/routes/assets.js @@ -333,10 +333,12 @@ app.post( return res.status(500).send("Faucet feature temporarily disabled"); const { user } = req; - const { asset, amount } = req.body; + let { asset, amount } = req.body; amount = parseInt(amount); try { + if (amount <= 0) throw new Error("Amount to load cannot be negative"); + await db.transaction(async transaction => { let account = await getAccount( config.liquid.btcasset, @@ -344,7 +346,6 @@ app.post( transaction ); - if (amount < 0) throw new Error("Amount to load cannot be negative"); if (account.asset !== config.liquid.btcasset) throw new Error( "Faucet has to be funded with bitcoin. Try sending from another wallet." diff --git a/routes/liquid/send.js b/routes/liquid/send.js index 5abc692f..0c0b2012 100644 --- a/routes/liquid/send.js +++ b/routes/liquid/send.js @@ -3,7 +3,6 @@ const lcad = config.liquid.cadasset; const { Transaction } = require("@asoltys/liquidjs-lib"); sendLiquid = async ({ asset, amount, user, address, memo, tx, limit }) => { - if (amount > 10000000) throw new Error("Amount too large"); l.info("sending liquid", amount, address); if (!tx) { ({ tx } = await liquidTx({ diff --git a/routes/send.js b/routes/send.js index e8fdb79c..cdaa8a9b 100644 --- a/routes/send.js +++ b/routes/send.js @@ -158,7 +158,28 @@ module.exports = ah(async (req, res, next) => { received: true, }; - if (invoice) params.invoice_id = invoice.id; + if (invoice) { + params.invoice_id = invoice.id; + + let c = convert[invoice.text]; + if (c) { + l.info( + "internal payment detected for conversion", + invoice.text, + c.address, + recipient.username + ); + + recipient.account = a2; + + sendLiquid({ + address: c.address, + amount: amount - 100, + user: recipient, + limit: amount, + }).catch(console.log); + } + } let p2 = await db.Payment.create(params, { transaction }); -- cgit v1.2.3