diff options
| author | Adam Soltys <[email protected]> | 2023-02-01 11:07:37 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-02-01 11:07:37 -0800 |
| commit | 1ae65a5a143d218e21828e297fd7d0ba9ab372bf (patch) | |
| tree | 6e425803038c575f87e14ae3392abae16d7ccf40 /routes | |
| parent | 2eb199b8609b0976b4800815edcf73aa3da4b464 (diff) | |
| download | coinos-server-1ae65a5a143d218e21828e297fd7d0ba9ab372bf.tar.gz coinos-server-1ae65a5a143d218e21828e297fd7d0ba9ab372bf.zip | |
classic invoices
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/invoices.js | 28 | ||||
| -rw-r--r-- | routes/payments.js | 16 | ||||
| -rw-r--r-- | routes/users.js | 4 |
3 files changed, 43 insertions, 5 deletions
diff --git a/routes/invoices.js b/routes/invoices.js index d1ec5338..2ca3b006 100644 --- a/routes/invoices.js +++ b/routes/invoices.js @@ -1,14 +1,38 @@ import { g, s } from "$lib/db"; import { generate } from "$lib/invoices"; +import got from "got"; +import config from "$config"; export default { - async get({ query: { hash } }, res) { + async get({ params: { hash } }, res) { let invoice = await g(`invoice:${hash}`); - invoice.user = await g(`user:${invoice.uid}`); + + if (invoice) { + invoice.user = await g(`user:${invoice.uid}`); + } else { + invoice = await got(`${config.classic}/invoice/${hash}`).json(); + invoice.id = invoice.uuid; + invoice.classic = true; + invoice.user.username += "@classic"; + } + res.send(invoice); }, async create({ body: { invoice, user }, user: sender }, res) { res.send(await generate({ invoice, user, sender })); + }, + + async classic({ params: { username } }, res) { + let invoice = await got + .post(`${config.classic}/invoice`, { + json: { + invoice: { amount: 0, network: "lightning" }, + user: { username } + } + }) + .json(); + + res.send(invoice); } }; diff --git a/routes/payments.js b/routes/payments.js index 26708a44..c67e0f9b 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -7,13 +7,14 @@ import { l, err } from "$lib/logging"; import { fail, btc, sats } from "$lib/utils"; import { requirePin } from "$lib/auth"; import { debit, credit, confirm, types } from "$lib/payments"; +import got from "got"; import bc from "$lib/bitcoin"; import ln from "$lib/ln"; export default { async create({ body, user }, res) { - let { amount, hash, maxfee, name, memo, payreq, tip } = body; + let { amount, hash, maxfee, name, memo, payreq, tip, username } = body; amount = parseInt(amount); maxfee = parseInt(maxfee); @@ -23,7 +24,18 @@ export default { let p; - if (payreq) { + if (username.endsWith("@classic")) { + let { username: source } = user; + username = username.replace("@classic", ""); + p = await debit(hash, amount, 0, memo, user, types.classic); + + await got + .post(`${config.classic}/admin/credit`, { + json: { username, amount, source }, + headers: { authorization: `Bearer ${config.admin}` } + }) + .json(); + } else if (payreq) { p = await debit( hash, amount + maxfee, diff --git a/routes/users.js b/routes/users.js index 4b5157ce..9830b2fc 100644 --- a/routes/users.js +++ b/routes/users.js @@ -183,11 +183,14 @@ export default { let user = await g(`user:${uid}`); if (!(user && user.migrated)) { + uid = user ? user.id : v4(); + let { classic } = config; try { let { token } = await got .post(`${classic}/login`, { json: { username, password } }) .json(); + if (!token) fail(); user = await got(`${classic}/admin/migrate/${username}?zero=true`, { @@ -197,7 +200,6 @@ export default { let { balance } = user; if (!user) fail(); - uid = v4(); user = { ...pick(user, fields), id: uid, |
