diff options
| author | Adam Soltys <[email protected]> | 2020-04-27 11:14:43 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2020-04-28 22:33:02 -0700 |
| commit | e166ab2c743e4c66eacb51c6484711c5965dd090 (patch) | |
| tree | a3b309cb38ceceb6e581963f0001a6869452b531 /routes | |
| parent | fae6e8b55ea12989d688eb777c002222199c169b (diff) | |
| download | coinos-server-e166ab2c743e4c66eacb51c6484711c5965dd090.tar.gz coinos-server-e166ab2c743e4c66eacb51c6484711c5965dd090.zip | |
select payments from current account
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/invoices.js | 2 | ||||
| -rw-r--r-- | routes/lightning/receive.js | 1 | ||||
| -rw-r--r-- | routes/liquid/receive.js | 39 | ||||
| -rw-r--r-- | routes/users.js | 22 |
4 files changed, 47 insertions, 17 deletions
diff --git a/routes/invoices.js b/routes/invoices.js index 50f578ac..651863d6 100644 --- a/routes/invoices.js +++ b/routes/invoices.js @@ -3,7 +3,7 @@ const { Op } = require("sequelize"); app.post("/invoice", auth, async (req, res) => { const { invoice } = req.body; invoice.user_id = req.user.id; - l.info("creating invoice", req.user.username, invoice.asset, invoice.amount, invoice.tip, invoice.currency, invoice.rate.toFixed(2)); + l.info("creating invoice", req.user.username, invoice.network, invoice.amount, invoice.tip, invoice.currency, invoice.rate.toFixed(2)); const exists = await db.Invoice.findOne({ where: { diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js index c300d8ea..3083eca7 100644 --- a/routes/lightning/receive.js +++ b/routes/lightning/receive.js @@ -9,7 +9,6 @@ const handlePayment = async msg => { } }); - if (!invoice) return; const { text: hash, currency, rate, tip, user_id } = invoice; diff --git a/routes/liquid/receive.js b/routes/liquid/receive.js index 5d7eb237..858cc0ed 100644 --- a/routes/liquid/receive.js +++ b/routes/liquid/receive.js @@ -34,17 +34,6 @@ zmqRawTx.on("message", async (topic, message, sequence) => { } }); - const invoice = await db.Invoice.findOne({ - where: { - user_id: user.id, - asset - }, - order: [["id", "DESC"]] - }); - - const currency = invoice ? invoice.currency : user.currency; - const rate = invoice ? invoice.rate : app.get("rates")[user.currency]; - const tip = invoice ? invoice.tip : null; let confirmed = 0; @@ -61,13 +50,17 @@ zmqRawTx.on("message", async (topic, message, sequence) => { account.pending += value; await account.save(); } else { - let assets = await axios.get("https://assets.blockstream.info/"); + let name = asset.substr(0, 6); + let ticker = asset.substr(0, 3); + let precision = 8; + + const assets = await axios.get("https://assets.blockstream.info/"); if (assets[asset]) { - let { ticker, precision, name } = assets[asset]; - params = { ...params, ...{ ticker, precision, name } }; + ({ticker, precision, name } = assets[asset]); } + params = { ...params, ...{ ticker, precision, name } }; params.balance = 0; params.pending = value; account = await db.Account.create(params); @@ -84,6 +77,23 @@ zmqRawTx.on("message", async (topic, message, sequence) => { addresses[user.liquid] = user.username; + l.info("account", account.id); + + let invoice; + if (asset === config.liquid.btcasset) { + invoice = await db.Invoice.findOne({ + where: { + user_id: user.id, + network: 'LBTC', + }, + order: [["id", "DESC"]] + }); + } + + const currency = invoice ? invoice.currency : user.currency; + const rate = invoice ? invoice.rate : app.get("rates")[user.currency]; + const tip = invoice ? invoice.tip : null; + const payment = await db.Payment.create({ account_id: account.id, user_id: user.id, @@ -97,6 +107,7 @@ zmqRawTx.on("message", async (topic, message, sequence) => { address, network: "LBTC" }); + payments.push(blinded.txid); l.info("liquid detected", user.username, asset, value); diff --git a/routes/users.js b/routes/users.js index cc7b62cc..d77cd8a0 100644 --- a/routes/users.js +++ b/routes/users.js @@ -46,7 +46,10 @@ app.get("/liquidate", async (req, res) => { user_id: user.id, asset: config.liquid.btcasset, balance: user.balance, - pending: 0 + pending: 0, + ticker: 'BTC', + name: 'Bitcoin', + precision: 8, }); } } @@ -212,6 +215,7 @@ app.post("/user", auth, async (req, res) => { } await user.save(); + user = await getUser(user.username); emit(user.username, "user", user); res.send({ user, token }); } catch (e) { @@ -360,4 +364,20 @@ app.post("/address", auth, async (req, res) => { res.send(user.address); }); +app.post("/shiftAccount", auth, async (req, res) => { + let { user } = req; + let { asset } = req.body; + + const account = await db.Account.findOne({ + where: { user_id: user.id, asset } + }); + + user.account_id = account.id; + await user.save(); + + user = await getUser(user.username); + emit(user.username, "user", user); + res.send(account); +}); + setInterval(() => (faucet = 2000), DAY); |
