aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ecash.js24
1 files changed, 8 insertions, 16 deletions
diff --git a/lib/ecash.js b/lib/ecash.js
index d47513a4..0e4a3c1a 100644
--- a/lib/ecash.js
+++ b/lib/ecash.js
@@ -4,6 +4,7 @@ import {
CashuWallet,
getDecodedToken,
getEncodedToken,
+ MintQuoteState,
} from "@cashu/cashu-ts";
import { g, s } from "$lib/db";
@@ -16,27 +17,18 @@ let enc = (proofs) =>
let dec = (token) => getDecodedToken(token).token[0];
-export async function melt(user, amount) {
- let { proofs } = dec(await g(`cash:${user.id}`));
+export async function claim(token) {
let { proofs: current } = dec(await g(`cash`));
+ let rcvd = await wallet.receive(token);
- let { send, returnChange } = await wallet.send(amount, proofs);
-
- await s(`cash`, enc([...current, ...send]));
- await s(`cash:${user.id}`, enc(returnChange));
+ await s(`cash`, enc([...current, ...rcvd]));
+ return rcvd.reduce((a, b) => a + b.amount, 0);
}
-export async function mint(user, amount) {
+export async function mint(amount) {
let { proofs } = dec(await g(`cash`));
- let { proofs: current } = dec(await g(`cash:${user.id}`));
-
let { send, returnChange } = await wallet.send(amount, proofs);
-
- await s(`cash:${user.id}`, enc([...current, ...send]));
+ let rcvd = await wallet.receive(enc(send));
await s(`cash`, enc(returnChange));
-}
-
-export async function balance(user) {
- let { proofs } = dec(await g(`cash:${user.id}`));
- return proofs.reduce((a, b) => a + b.amount, 0);
+ return enc(rcvd);
}