diff options
| author | Adam Soltys <[email protected]> | 2021-08-30 14:48:26 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2021-08-30 16:03:09 -0700 |
| commit | c6dc858ee5491e6c584d94d702438e9b24adbfc7 (patch) | |
| tree | 412344ab540dc81f209a965eaf82e5621a85b4d3 /routes | |
| parent | 7d3cc287e862e590c7cc85a8ce99eb2782ff84af (diff) | |
| download | coinos-server-c6dc858ee5491e6c584d94d702438e9b24adbfc7.tar.gz coinos-server-c6dc858ee5491e6c584d94d702438e9b24adbfc7.zip | |
handle conversions for internal payments
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/assets.js | 5 | ||||
| -rw-r--r-- | routes/liquid/send.js | 1 | ||||
| -rw-r--r-- | routes/send.js | 23 |
3 files changed, 25 insertions, 4 deletions
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 }); |
