diff options
| author | Adam Soltys <[email protected]> | 2024-08-23 23:39:05 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-08-23 23:39:05 -0700 |
| commit | 193457c5bd6c7c892c3be50674579dabd07fd2f2 (patch) | |
| tree | 82792280db6ea9945643a76112a210d904d49239 /lib/ecash.js | |
| parent | 7be5db4d1dae7226a48623f42aca864adfa54e02 (diff) | |
| download | coinos-server-193457c5bd6c7c892c3be50674579dabd07fd2f2.tar.gz coinos-server-193457c5bd6c7c892c3be50674579dabd07fd2f2.zip | |
use redis to store rates
Diffstat (limited to 'lib/ecash.js')
| -rw-r--r-- | lib/ecash.js | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/lib/ecash.js b/lib/ecash.js index df7759bf..8741cff1 100644 --- a/lib/ecash.js +++ b/lib/ecash.js @@ -7,8 +7,11 @@ import { MintQuoteState, } from "@cashu/cashu-ts"; import { g, s } from "$lib/db"; +import ln from "$lib/ln"; +import { fail } from "$lib/utils"; -let wallet = new CashuWallet(new CashuMint(config.mintUrl)); +let m = new CashuMint(config.mintUrl); +let w = new CashuWallet(m); let enc = (proofs) => getEncodedToken({ @@ -17,9 +20,21 @@ let enc = (proofs) => let dec = (token) => getDecodedToken(token).token[0]; +let ext = async (mint) => { + let issuer = new CashuMint(mint); + let { pubkey: issuerPk } = await issuer.getInfo(); + let { pubkey: ourPk } = await m.getInfo(); + console.log(issuerPk, ourPk); + return issuerPk !== ourPk; +}; + export async function claim(token) { let { proofs: current } = dec(await g(`cash`)); - let rcvd = await wallet.receive(token); + let { mint } = dec(token); + + if (await ext(mint)) fail("Unable to receive from other mints"); + + let rcvd = await w.receive(token); await s(`cash`, enc([...current, ...rcvd])); return rcvd.reduce((a, b) => a + b.amount, 0); @@ -27,18 +42,20 @@ export async function claim(token) { export async function mint(amount) { let { proofs } = dec(await g(`cash`)); - let { send, returnChange } = await wallet.send(amount, proofs); - let rcvd = await wallet.receive(enc(send)); + let { send, returnChange } = await w.send(amount, proofs); + let rcvd = await w.receive(enc(send)); await s(`cash`, enc(returnChange)); return enc(rcvd); } export async function check(token) { - let { proofs } = dec(token); + let { mint, proofs } = dec(token); let total = proofs.reduce((a, b) => a + b.amount, 0); - let r = await wallet.checkProofsSpent(proofs); + let external = await ext(mint); + + let r = await w.checkProofsSpent(proofs); let spent = r.reduce((a, b) => a + b.amount, 0); - return { total, spent }; + return { total, spent, mint, external }; } |
