aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-11-22 22:42:35 -0800
committerAdam Soltys <[email protected]>2024-11-22 22:42:35 -0800
commitb82f045fe567f25c7d0a9fbb5163853373cd616c (patch)
tree0630fc14b88c740992bf04be5bfcd4fb4334f129 /routes
parent41ff5eb1261ad0878b080b5a85f6553223108429 (diff)
downloadcoinos-server-b82f045fe567f25c7d0a9fbb5163853373cd616c.tar.gz
coinos-server-b82f045fe567f25c7d0a9fbb5163853373cd616c.zip
ecash receive
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);
+ }
+ },
};