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 /lib/ecash.ts | |
| parent | ff4d63f395a556543e9a642676f92dea5d1c1645 (diff) | |
| download | coinos-server-f0ef70adc613c85f58ccc679f3a4d2d3b2d09e71.tar.gz coinos-server-f0ef70adc613c85f58ccc679f3a4d2d3b2d09e71.zip | |
migrate to new cashu-ts
Diffstat (limited to 'lib/ecash.ts')
| -rw-r--r-- | lib/ecash.ts | 18 |
1 files changed, 8 insertions, 10 deletions
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(); |
