diff options
| author | Adam Soltys <[email protected]> | 2024-11-21 21:17:20 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-11-21 21:17:20 -0800 |
| commit | f0ef70adc613c85f58ccc679f3a4d2d3b2d09e71 (patch) | |
| tree | 164b05a6cc64fbff87ade03684bf3b369623bb18 | |
| parent | ff4d63f395a556543e9a642676f92dea5d1c1645 (diff) | |
| download | coinos-server-f0ef70adc613c85f58ccc679f3a4d2d3b2d09e71.tar.gz coinos-server-f0ef70adc613c85f58ccc679f3a4d2d3b2d09e71.zip | |
migrate to new cashu-ts
| -rw-r--r-- | index.ts | 2 | ||||
| -rw-r--r-- | lib/ecash.ts | 18 | ||||
| -rw-r--r-- | routes/ecash.ts | 22 |
3 files changed, 16 insertions, 26 deletions
@@ -1,3 +1,5 @@ +Error.stackTraceLimit = Infinity; + import app from "$lib/app"; import { admin, auth, optional } from "$lib/auth"; diff --git a/lib/ecash.ts b/lib/ecash.ts index 4bcbb6d7..9de5cdc2 100644 --- a/lib/ecash.ts +++ b/lib/ecash.ts @@ -20,8 +20,6 @@ const enc = (proofs) => proofs, }); -const dec = (token) => getDecodedToken(token).token[0]; - const ext = async (mint) => { const issuer = new CashuMint(mint); const { pubkey: issuerPk } = await issuer.getInfo(); @@ -35,8 +33,8 @@ export async function get(id) { } export async function claim(token) { - const { proofs: current } = dec(await g("cash")); - const { mint } = dec(token); + const { proofs: current } = getDecodedToken(await g("cash")); + const { mint } = getDecodedToken(token); if (await ext(mint)) fail("Unable to receive from other mints"); @@ -51,7 +49,6 @@ export async function mint(amount) { const w = new CashuWallet(m, { keysets }); const { proofs } = getDecodedToken(await g("cash")); const { send, keep } = await w.send(amount, proofs); - console.log("SEND", send); const rcvd = await w.receive(enc(send)); const change = enc(keep); await s("cash", change); @@ -59,19 +56,21 @@ export async function mint(amount) { } export async function check(token) { - const o = dec(token); + const o = getDecodedToken(token); const { mint, proofs } = o; const total = proofs.reduce((a, b) => a + b.amount, 0); const external = await ext(mint); - const r = await w.checkProofsSpent(proofs); - const spent = r.reduce((a, b) => a + b.amount, 0); + let spent = 0; + for (const [i, p] of (await w.checkProofsStates(proofs)).entries()) { + if (p.state === "SPENT") spent += proofs[i].amount; + } return { total, spent, mint, external }; } -export async function init(amount = 10000) { +export async function init(amount = 100000) { try { await new Promise((r) => setTimeout(r, 2000)); const { quote, request } = await w.createMintQuote(amount); @@ -94,4 +93,3 @@ export async function init(amount = 10000) { console.log(e); } } -init(); diff --git a/routes/ecash.ts b/routes/ecash.ts index 101d1aca..35d9f950 100644 --- a/routes/ecash.ts +++ b/routes/ecash.ts @@ -7,15 +7,14 @@ import { bail, fail } from "$lib/utils"; import { v4 } from "uuid"; const { ecash: type } = types; +Error.stackTraceLimit = 100; // Set this to the desired limit + const sendCash = async ({ amount, user }) => { - console.log("HELLO", amount); const id = v4(); const hash = v4(); const p = await debit({ hash, amount, user, type }); - console.log("P", p); - const token = await mint(amount); - console.log("TOKEN", token); + const token = await mint(parseInt(amount)); p.memo = id; await s(`payment:${p.id}`, p); s(`cash:${id}`, token); @@ -83,18 +82,9 @@ export default { }, async mint(req, res) { - const { - body: { amount }, - user, - } = req; - try { - console.log("OY"); - res.send(await sendCash({ amount, user })); - } catch (e) { - console.log(e); - err(e.message); - bail(res, e.message); - } + const { body, user } = req; + const amount = parseInt(body.amount); + res.send(await sendCash({ amount, user })); }, async melt(req, res) { |
