diff options
| author | Adam Soltys <[email protected]> | 2024-10-24 13:59:34 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-10-24 13:59:34 -0700 |
| commit | d09712ef8f8ea8218ce229b233fc0013e6c06f7a (patch) | |
| tree | ec0b548baef30c0b95b068ec8117672a49ccdd54 /routes | |
| parent | ac161f60e08e7e32c46d98aa3288f4f1b3d6e2d8 (diff) | |
| download | coinos-server-d09712ef8f8ea8218ce229b233fc0013e6c06f7a.tar.gz coinos-server-d09712ef8f8ea8218ce229b233fc0013e6c06f7a.zip | |
save ecash id
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/ecash.ts | 61 | ||||
| -rw-r--r-- | routes/invoices.ts | 6 |
2 files changed, 33 insertions, 34 deletions
diff --git a/routes/ecash.ts b/routes/ecash.ts index 48b03fd3..cc617138 100644 --- a/routes/ecash.ts +++ b/routes/ecash.ts @@ -1,20 +1,20 @@ -import { g, s, db } from "$lib/db"; -import { get, claim, mint, check } from "$lib/ecash"; +import { db, g, s } from "$lib/db"; +import { check, claim, get, mint } from "$lib/ecash"; +import { err, l } from "$lib/logging"; +import { credit, debit, types } from "$lib/payments"; +import { emit } from "$lib/sockets"; import { bail, fail } from "$lib/utils"; -import { debit, credit, types } from "$lib/payments"; import { v4 } from "uuid"; -import { l, err } from "$lib/logging"; -import { emit } from "$lib/sockets"; -let { ecash: type } = types; +const { ecash: type } = types; export default { async save(req, res) { - let { + const { body: { token }, } = req; try { - let id = v4(); + const id = v4(); await s(`cash:${id}`, token); res.send({ id }); } catch (e) { @@ -24,12 +24,12 @@ export default { }, async get(req, res) { - let { + const { params: { id, version }, } = req; try { - let token = await get(id, version); - let status = await check(token); + const token = await get(id, version); + const status = await check(token); res.send({ token, status }); } catch (e) { err(e.message); @@ -38,17 +38,17 @@ export default { }, async claim(req, res) { - let { + const { body: { token }, user, } = req; try { - let amount = await claim(token); + const amount = await claim(token); let memo; - let hash = v4(); - let { currency, id: uid } = user; - let rates = await g("rates"); + const hash = v4(); + const { currency, id: uid } = user; + const rates = await g("rates"); await s(`invoice:${hash}`, { currency, id: hash, @@ -68,18 +68,17 @@ export default { }, async mint(req, res) { - let { + const { body: { amount }, user, } = req; try { - let id = v4(); - let hash = v4(); + const id = v4(); + const hash = v4(); - let memo, rate; - let p = await debit({ hash, amount, user, type, memo, rate }); - let token = await mint(amount); - p.memo = token; + const p = await debit({ hash, amount, user, type }); + const token = await mint(amount); + p.memo = id; await s(`payment:${p.id}`, p); s(`cash:${id}`, token); @@ -97,11 +96,11 @@ export default { } = req; try { amount = Math.round(amount / 1000); - let ref = preimage; - let { lightning: type } = types; + const ref = preimage; + const { lightning: type } = types; if (user.username !== "mint") fail("unauthorized"); - let { id: uid, currency } = user; - let ourfee = await db.debit( + const { id: uid, currency } = user; + const ourfee = await db.debit( `balance:${uid}`, `credit:${type}:${uid}`, amount || 0, @@ -110,13 +109,13 @@ export default { 0, ); - let rates = await g("rates"); - let rate = rates[currency]; + const rates = await g("rates"); + const rate = rates[currency]; if (ourfee.err) fail(ourfee.err); - let id = v4(); - let p = { + const id = v4(); + const p = { id, amount: -amount, hash, diff --git a/routes/invoices.ts b/routes/invoices.ts index acad5ce7..c571f4de 100644 --- a/routes/invoices.ts +++ b/routes/invoices.ts @@ -1,11 +1,11 @@ import { g } from "$lib/db"; import { generate } from "$lib/invoices"; -import { bail, pick } from "$lib/utils"; import { err } from "$lib/logging"; +import { bail, pick } from "$lib/utils"; export default { async get(req, res) { - let { + const { params: { id }, } = req; let invoice = await g(`invoice:${id}`); @@ -31,7 +31,7 @@ export default { async create(req, res) { let { body, user } = req; if (body.user) user = body.user; - let { invoice } = body; + const { invoice } = body; try { res.send(await generate({ invoice, user })); |
