From b82f045fe567f25c7d0a9fbb5163853373cd616c Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 22 Nov 2024 22:42:35 -0800 Subject: ecash receive --- routes/ecash.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'routes') diff --git a/routes/ecash.ts b/routes/ecash.ts index 6aac01a8..a807cdb5 100644 --- a/routes/ecash.ts +++ b/routes/ecash.ts @@ -4,6 +4,7 @@ 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 { getEncodedToken } from "@cashu/cashu-ts"; import { v4 } from "uuid"; const { ecash: type } = types; @@ -140,4 +141,26 @@ export default { bail(res, e.message); } }, + + async receive(req, res) { + try { + const { payload } = req.body; + const { id, proofs, mint, memo } = payload; + const { uid: ref } = await g(`invoice:${id}`); + + const amount = await claim( + getEncodedToken({ + mint, + proofs, + }), + ); + + await credit({ hash: id, amount, memo, ref, type }); + + res.send({ id }); + } catch (e) { + err(e.message); + bail(res, e.message); + } + }, }; -- cgit v1.2.3