Skip to content

Commit

Permalink
show spent ecash
Browse files Browse the repository at this point in the history
  • Loading branch information
asoltys committed Aug 20, 2024
1 parent 0dd1fea commit 6588913
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Binary file modified bun.lockb
Binary file not shown.
10 changes: 10 additions & 0 deletions lib/ecash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
6 changes: 4 additions & 2 deletions routes/ecash.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);
}
Expand Down

0 comments on commit 6588913

Please sign in to comment.