diff options
| author | Adam Soltys <[email protected]> | 2024-11-21 16:31:51 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-11-21 16:31:51 -0800 |
| commit | ff4d63f395a556543e9a642676f92dea5d1c1645 (patch) | |
| tree | dbee8887d40bf535f587c1f10bc0fa7f36db31f8 /routes/ecash.ts | |
| parent | 3b15d16339c9209f307f8453af91fba15f3d340c (diff) | |
| download | coinos-server-ff4d63f395a556543e9a642676f92dea5d1c1645.tar.gz coinos-server-ff4d63f395a556543e9a642676f92dea5d1c1645.zip | |
ecash requests
Diffstat (limited to 'routes/ecash.ts')
| -rw-r--r-- | routes/ecash.ts | 42 |
1 files changed, 6 insertions, 36 deletions
diff --git a/routes/ecash.ts b/routes/ecash.ts index ff092374..101d1aca 100644 --- a/routes/ecash.ts +++ b/routes/ecash.ts @@ -1,26 +1,21 @@ import { db, g, s } from "$lib/db"; -import { check, claim, get, mint, request } from "$lib/ecash"; +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 { - PaymentRequest, - PaymentRequestPayload, - PaymentRequestTransport, - PaymentRequestTransportType, - decodePaymentRequest, - getDecodedToken, -} from "@cashu/cashu-ts"; import { v4 } from "uuid"; const { ecash: type } = types; const sendCash = async ({ amount, user }) => { + console.log("HELLO", amount); const id = v4(); const hash = v4(); const p = await debit({ hash, amount, user, type }); + console.log("P", p); const token = await mint(amount); + console.log("TOKEN", token); p.memo = id; await s(`payment:${p.id}`, p); s(`cash:${id}`, token); @@ -93,8 +88,10 @@ export default { user, } = req; try { + console.log("OY"); res.send(await sendCash({ amount, user })); } catch (e) { + console.log(e); err(e.message); bail(res, e.message); } @@ -152,31 +149,4 @@ export default { bail(res, e.message); } }, - - async pay(req, res) { - const { user } = req; - const { request } = req.body; - const { amount } = decodePaymentRequest(request); - const { id, token } = await sendCash({ amount, user }); - - - const decodedToken = getDecodedToken(token); - if (!decodedToken) { - console.error("could not decode token"); - return; - } - const proofs = token.getProofs(decodedToken); - const mint = token.getMint(decodedToken); - const paymentPayload: PaymentRequestPayload = { - id: request.id, - mint: mint, - unit: request.unit || "", - proofs: proofs, - }; - const paymentPayloadString = JSON.stringify(paymentPayload); - try { - await nostrStore.sendNip17DirectMessageToNprofile(transport.target, paymentPayloadString); - - res.send({ id, token }); - }, }; |
