diff options
| author | Adam Soltys <[email protected]> | 2024-09-25 09:44:26 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-09-25 09:44:29 -0700 |
| commit | 61d246e1bca5566c93486312818e02b8a8aa70b3 (patch) | |
| tree | 3382a5db19e0dff6280232e77f3fd9f7cb1b0587 | |
| parent | 9ef8f0eea743929207009d0f42b9ba44eec00641 (diff) | |
| download | coinos-server-61d246e1bca5566c93486312818e02b8a8aa70b3.tar.gz coinos-server-61d246e1bca5566c93486312818e02b8a8aa70b3.zip | |
push to account invoices
| -rw-r--r-- | lib/invoices.ts | 2 | ||||
| -rw-r--r-- | mint.ts | 35 | ||||
| -rw-r--r-- | routes/invoices.ts | 2 |
3 files changed, 37 insertions, 2 deletions
diff --git a/lib/invoices.ts b/lib/invoices.ts index d7f09de5..a17288ca 100644 --- a/lib/invoices.ts +++ b/lib/invoices.ts @@ -126,7 +126,7 @@ export let generate = async ({ invoice, user }) => { await s(`invoice:${hash}`, id); await s(`invoice:${id}`, invoice); - await db.lPush(`${user.id}:invoices`, id); + await db.lPush(`${aid}:invoices`, id); if (request_id) { let request = await g(`request:${request_id}`); diff --git a/mint.ts b/mint.ts new file mode 100644 index 00000000..8cf3e744 --- /dev/null +++ b/mint.ts @@ -0,0 +1,35 @@ +import config from "$config"; +import { createClient } from "redis"; +import { + CashuMint, + CashuWallet, + getEncodedTokenV4, + MintQuoteState, +} from "@cashu/cashu-ts"; + +const mintUrl = "http://mint:3338"; // the mint URL +const mint = new CashuMint(mintUrl); +const wallet = new CashuWallet(mint); +let amt = 100000; +const mintQuote = await wallet.createMintQuote(amt); +console.log(mintQuote.request); + +let interval = setInterval(async () => { + const mintQuoteChecked = await wallet.checkMintQuote(mintQuote.quote); + if (mintQuoteChecked.state == MintQuoteState.PAID) { + const { proofs } = await wallet.mintTokens(amt, mintQuote.quote); + + const token = getEncodedTokenV4({ + token: [{ mint: mintUrl, proofs }], + }); + + let db = createClient({ + url: config.db, + }); + + await db.connect(); + await db.set("cash", token); + + clearInterval(interval); + } +}, 1000); diff --git a/routes/invoices.ts b/routes/invoices.ts index 98a851ed..acad5ce7 100644 --- a/routes/invoices.ts +++ b/routes/invoices.ts @@ -36,7 +36,7 @@ export default { try { res.send(await generate({ invoice, user })); } catch (e) { - console.log(e) + console.log(e); err("problem generating invoice", e.message); bail(res, e.message); } |
