aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
Diffstat (limited to 'routes')
-rw-r--r--routes/ecash.ts23
1 files changed, 23 insertions, 0 deletions
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);
+ }
+ },
};