aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-08-20 16:13:50 -0700
committerAdam Soltys <[email protected]>2024-08-20 16:13:50 -0700
commit6588913c949d5440c33e657b0a86ed62ba94164e (patch)
treeebfcb6c1c703a729492fdcb904c27a6d8dff99a1
parent0dd1feac21158c13cf99a96a306f3c8bf92e31cd (diff)
downloadcoinos-server-6588913c949d5440c33e657b0a86ed62ba94164e.tar.gz
coinos-server-6588913c949d5440c33e657b0a86ed62ba94164e.zip
show spent ecash
-rwxr-xr-xbun.lockbbin213547 -> 213547 bytes
-rw-r--r--lib/ecash.js10
-rw-r--r--routes/ecash.js6
3 files changed, 14 insertions, 2 deletions
diff --git a/bun.lockb b/bun.lockb
index 7668cf5a..15a724cd 100755
--- a/bun.lockb
+++ b/bun.lockb
Binary files differ
diff --git a/lib/ecash.js b/lib/ecash.js
index 0e4a3c1a..df7759bf 100644
--- a/lib/ecash.js
+++ b/lib/ecash.js
@@ -32,3 +32,13 @@ export async function mint(amount) {
await s(`cash`, enc(returnChange));
return enc(rcvd);
}
+
+export async function check(token) {
+ let { proofs } = dec(token);
+ let total = proofs.reduce((a, b) => a + b.amount, 0);
+
+ let r = await wallet.checkProofsSpent(proofs);
+ let spent = r.reduce((a, b) => a + b.amount, 0);
+
+ return { total, spent };
+}
diff --git a/routes/ecash.js b/routes/ecash.js
index 1b8bcae1..8ce841dd 100644
--- a/routes/ecash.js
+++ b/routes/ecash.js
@@ -1,5 +1,5 @@
import { g, s, db } from "$lib/db";
-import { claim, mint } from "$lib/ecash";
+import { claim, mint, check } from "$lib/ecash";
import { bail } from "$lib/utils";
import { debit, credit, types } from "$lib/payments";
import { v4 } from "uuid";
@@ -12,7 +12,9 @@ let { ecash: type } = types;
export default {
async get({ params: { id } }, res) {
try {
- res.send(await g(`cash:${id}`));
+ let token = await g(`cash:${id}`);
+ let status = await check(token);
+ res.send({ token, status });
} catch (e) {
bail(res, e.message);
}