diff options
| author | Adam Soltys <[email protected]> | 2026-02-06 16:55:45 +0000 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-02-06 16:55:45 +0000 |
| commit | 9089698e8df9d0c09c165c45eb6b05335a818699 (patch) | |
| tree | 592be0e8964857d7be5ca9baacb6143b29903b27 /routes | |
| parent | 0ad6c9ec8a4f91e1d45af4a76330cc3ddcf177a2 (diff) | |
| download | coinos-server-9089698e8df9d0c09c165c45eb6b05335a818699.tar.gz coinos-server-9089698e8df9d0c09c165c45eb6b05335a818699.zip | |
health check
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/info.ts | 7 | ||||
| -rw-r--r-- | routes/users.ts | 51 |
2 files changed, 13 insertions, 45 deletions
diff --git a/routes/info.ts b/routes/info.ts index c6d03e4d..a0ac7693 100644 --- a/routes/info.ts +++ b/routes/info.ts @@ -1,9 +1,16 @@ import { archive } from "$lib/db"; import { db, g } from "$lib/db"; +import { getHealthStatus } from "$lib/health"; import ln from "$lib/ln"; import { getDecodedToken } from "@cashu/cashu-ts"; export default { + async health(_, res) { + const status = getHealthStatus(); + const httpStatus = status.healthy ? 200 : 503; + res.status(httpStatus).send(status); + }, + async balances(_, res) { let total = 0; diff --git a/routes/users.ts b/routes/users.ts index 4f1cb487..64659a01 100644 --- a/routes/users.ts +++ b/routes/users.ts @@ -1,18 +1,17 @@ import { createReadStream } from "node:fs"; -import { appendFile, unlink, writeFile } from "node:fs/promises"; +import { unlink, writeFile } from "node:fs/promises"; import config from "$config"; import { requirePin } from "$lib/auth"; import { db, g, ga, gf, s } from "$lib/db"; import { err, l, warn } from "$lib/logging"; import { mail, templates } from "$lib/mail"; import { getNostrUser, getProfile, serverPubkey2 } from "$lib/nostr"; -import { reconcile } from "$lib/payments"; import register from "$lib/register"; import { emit } from "$lib/sockets"; import upload from "$lib/upload"; import { bail, fail, fields, getUser, pick } from "$lib/utils"; import whitelist from "$lib/whitelist"; -import rpc from "@coinos/rpc"; + import { $ } from "bun"; import got from "got"; import jwt from "jsonwebtoken"; @@ -844,38 +843,11 @@ export default { async createAccount(req, res) { try { - const { fingerprint, pubkey, name, seed, type } = req.body; + const { name, type } = req.body; const { user } = req; - const { id: uid } = user; const id = v4(); - const account = { id, name, seed, type, uid, descriptors: [] }; - - let node = rpc(config[type]); - - await node.createWallet({ - wallet_name: id, - descriptors: true, - disable_private_keys: true, - load_on_startup: true, - }); - - node = rpc({ ...config[type], wallet: id }); - - for (const i of [0, 1]) { - const desc = `wpkh([${fingerprint}]${pubkey}/${i}/*)`; - const { checksum } = await node.getDescriptorInfo(desc); - account.descriptors.push({ - desc: `${desc}#${checksum}`, - range: [0, 100], - next_index: 0, - timestamp: "now", - internal: i === 1, - active: true, - }); - } - - await node.importDescriptors(account.descriptors); + const account = { id, name, type, uid: user.id }; await db .multi() @@ -885,10 +857,6 @@ export default { .lPush(`${user.id}:accounts`, id) .exec(); - reconcile(account, true); - - await appendFile("/bitcoin.conf", `wallet=${id}\n`); - res.send(account); } catch (e) { bail(res, e.message); @@ -914,17 +882,10 @@ export default { try { const { id } = req.body; const { id: uid } = req.user; - const { type } = await g(`account:${id}`); + const account = await g(`account:${id}`); const pos = await db.lPos(`${uid}:accounts`, id); - if (!(type && pos != null)) fail("account not found"); - - try { - const node = rpc({ ...config[type], wallet: id }); - await node.unloadWallet(id); - } catch (e) { - warn("failed to unload wallet", id); - } + if (!(account && pos != null)) fail("account not found"); await db .multi() |
