diff options
| author | Adam Soltys <[email protected]> | 2023-04-04 00:05:39 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-04-04 00:05:39 -0700 |
| commit | 8b67a32b6ffc87b14ef1fa26b6596695419b8e3e (patch) | |
| tree | 86f7acca86021d5a1cc02aae0f6d4edefe60376c | |
| parent | 0aea60330afff02ad8bb525c5fddd7c367abf03a (diff) | |
| download | coinos-server-8b67a32b6ffc87b14ef1fa26b6596695419b8e3e.tar.gz coinos-server-8b67a32b6ffc87b14ef1fa26b6596695419b8e3e.zip | |
prettier
| -rw-r--r-- | lib/invoices.js | 2 | ||||
| -rw-r--r-- | lib/lightning.js | 2 | ||||
| -rw-r--r-- | lib/payments.js | 6 | ||||
| -rw-r--r-- | lib/rates.js | 6 | ||||
| -rw-r--r-- | lib/utils.js | 18 | ||||
| -rw-r--r-- | routes/lnurl.js | 2 | ||||
| -rw-r--r-- | routes/nostr.js | 41 | ||||
| -rw-r--r-- | routes/payments.js | 26 | ||||
| -rw-r--r-- | routes/users.js | 30 |
9 files changed, 66 insertions, 67 deletions
diff --git a/lib/invoices.js b/lib/invoices.js index 74870f82..9aade609 100644 --- a/lib/invoices.js +++ b/lib/invoices.js @@ -63,7 +63,7 @@ export let generate = async ({ invoice, user, sender, memo }) => { text, tip, type, - uid: user.id + uid: user.id, }; l("creating invoice", user.username, amount, tip, currency, invoice.hash); diff --git a/lib/lightning.js b/lib/lightning.js index 7ef62cc9..e4a2bbd9 100644 --- a/lib/lightning.js +++ b/lib/lightning.js @@ -15,7 +15,7 @@ export async function listenForLightning() { pay_index, status, msatoshi_received, - payment_preimage: preimage + payment_preimage: preimage, } = event; await s("pay_index", pay_index); diff --git a/lib/payments.js b/lib/payments.js index 5dc24c9b..7eab01b0 100644 --- a/lib/payments.js +++ b/lib/payments.js @@ -13,7 +13,7 @@ export const types = { bitcoin: "bitcoin", lightning: "lightning", pot: "pot", - classic: "classic" + classic: "classic", }; export let debit = async ( @@ -89,7 +89,7 @@ export let debit = async ( type, ref, tip, - created: Date.now() + created: Date.now(), }; await s(`payment:${id}`, p); @@ -136,7 +136,7 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { tip, type, confirmed: true, - created: Date.now() + created: Date.now(), }; invoice.received += amount; diff --git a/lib/rates.js b/lib/rates.js index 362aaa98..0b2daab2 100644 --- a/lib/rates.js +++ b/lib/rates.js @@ -15,11 +15,11 @@ let connect = async () => { ws = new WebSocket("wss://stream.binance.com:9443/ws/btcusdt@ticker"); - ws.onmessage = async function(event) { + ws.onmessage = async function (event) { try { let msg = JSON.parse(event.data); - Object.keys(store.fx).map(symbol => { + Object.keys(store.fx).map((symbol) => { store.rates[symbol] = msg.c * store.fx[symbol]; }); @@ -31,7 +31,7 @@ let connect = async () => { } }; - ws.onerror = async function(error) { + ws.onerror = async function (error) { err("binance socket error", error.message); }; diff --git a/lib/utils.js b/lib/utils.js index 05819ecb..1e12214b 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -4,7 +4,7 @@ import config from "$config"; export const nada = () => {}; -export const sleep = n => new Promise(r => setTimeout(r, n)); +export const sleep = (n) => new Promise((r) => setTimeout(r, n)); export const wait = async (f, s = 300, n = 50) => { let i = 0; while (!(await f()) && i < s) (await sleep(n)) && i++; @@ -13,17 +13,17 @@ export const wait = async (f, s = 300, n = 50) => { }; export const prod = process.env.NODE_ENV === "production"; -export const fail = msg => { +export const fail = (msg) => { throw new Error(msg); }; export const bail = (res, msg) => res.code(500).send(msg); export const SATS = 100000000; -export const sats = n => Math.round(n * SATS); -export const btc = n => parseFloat((n / SATS).toFixed(8)); +export const sats = (n) => Math.round(n * SATS); +export const btc = (n) => parseFloat((n / SATS).toFixed(8)); -export const uniq = (a, k) => [...new Map(a.map(x => [k(x), x])).values()]; +export const uniq = (a, k) => [...new Map(a.map((x) => [k(x), x])).values()]; export const pick = (O, K) => K.reduce((o, k) => (typeof O[k] !== "undefined" && (o[k] = O[k]), o), {}); @@ -53,11 +53,11 @@ export const fields = [ "haspin", "profile", "prompt", - "banner" + "banner", ]; -export const getUser = async username => { - username = username.replace(/\s/g, "").toLowerCase() - let uid = await g(`user:${username}`); +export const getUser = async (username) => { + username = username.replace(/\s/g, "").toLowerCase(); + let uid = await g(`user:${username}`); return g(`user:${uid}`); }; diff --git a/routes/lnurl.js b/routes/lnurl.js index 97e4e8f8..4540a11a 100644 --- a/routes/lnurl.js +++ b/routes/lnurl.js @@ -56,7 +56,7 @@ export default { u = { id: uid, about: u.address, ...pick(u, fields) }; delete u.address; - await s(`user:${username.replace(/\s/g, '').toLowerCase()}`, uid); + await s(`user:${username.replace(/\s/g, "").toLowerCase()}`, uid); await s(`user:${uid}`, u); await s(`balance:${uid}`, balance); diff --git a/routes/nostr.js b/routes/nostr.js index 33233a7a..e45c0cbd 100644 --- a/routes/nostr.js +++ b/routes/nostr.js @@ -15,7 +15,7 @@ export default { pubkey, anon: true, follows: [], - followers: [] + followers: [], }; res.send(event); @@ -31,12 +31,12 @@ export default { pubkey, anon: true, follows: [], - followers: [] + followers: [], }; let params = { kinds: [1], - authors: [pubkey] + authors: [pubkey], }, opts = { since: 0 }; @@ -45,16 +45,16 @@ export default { let ids = await db.sMembers(pubkey); let events = ids.length - ? (await db.mGet(ids.map(k => "ev:" + k))).map(JSON.parse) + ? (await db.mGet(ids.map((k) => "ev:" + k))).map(JSON.parse) : []; - res.send(events.map(e => ({ ...e, user }))); + res.send(events.map((e) => ({ ...e, user }))); }, async messages({ params: { pubkey, since = 0 } }, res) { let params = { kinds: [4], - authors: [pubkey] + authors: [pubkey], }; let opts = { since }; @@ -63,7 +63,7 @@ export default { params = { kinds: [4], - "#p": [pubkey] + "#p": [pubkey], }; await q(`${pubkey}:messages`, params, opts).catch(nada); @@ -71,7 +71,7 @@ export default { let messages = await db.sMembers(`${pubkey}:messages`); messages = await Promise.all( - messages.map(async id => { + messages.map(async (id) => { let m = await g(`ev:${id}`); let aid = await g(`user:${m.pubkey}`); @@ -98,7 +98,7 @@ export default { params = { limit: 1, kinds: [3], - authors: [pubkey] + authors: [pubkey], }, opts = { timeout: 60000, eager: 60000 }; @@ -114,7 +114,7 @@ export default { q(`${pubkey}:profile:f1`, { limit: 1, kinds: [0], - authors: [pubkey] + authors: [pubkey], }).catch(nada); let uid = await g(`user:${pubkey}`); @@ -124,13 +124,13 @@ export default { user = { username: pubkey.substr(0, 6), pubkey, - anon: true + anon: true, }; follows.push(user); } - follows = uniq(follows, e => e.pubkey); + follows = uniq(follows, (e) => e.pubkey); follows.sort((a, b) => a.username.localeCompare(b.username)); res.send(follows); @@ -139,7 +139,7 @@ export default { async followers({ params: { pubkey } }, res) { try { let pubkeys = [ - ...new Set([...(await db.sMembers(`${pubkey}:followers`))]) + ...new Set([...(await db.sMembers(`${pubkey}:followers`))]), ]; let followers = []; @@ -157,7 +157,7 @@ export default { await q(`${pubkey}:profile:f2`, { limit: 1, kinds: [0], - authors: [pubkey] + authors: [pubkey], }).catch(nada); uid = await g(`user:${pubkey}`); @@ -168,13 +168,13 @@ export default { user = { username: pubkey.substr(0, 6), pubkey, - anon: true + anon: true, }; followers.push(user); } - followers = uniq(followers, e => e.pubkey); + followers = uniq(followers, (e) => e.pubkey); followers.sort((a, b) => a.username.localeCompare(b.username)); res.send(followers); @@ -187,11 +187,10 @@ export default { async identities(req, res) { res.send({ names: { - adam: - "566c166f3adab0c8fba5da015b0b3bcc8eb3696b455f2a1d43bfbd97059646a8", + adam: "566c166f3adab0c8fba5da015b0b3bcc8eb3696b455f2a1d43bfbd97059646a8", asoltys: - "566c166f3adab0c8fba5da015b0b3bcc8eb3696b455f2a1d43bfbd97059646a8" - } + "566c166f3adab0c8fba5da015b0b3bcc8eb3696b455f2a1d43bfbd97059646a8", + }, }); - } + }, }; diff --git a/routes/payments.js b/routes/payments.js index ead233d6..a8cffa50 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -151,23 +151,23 @@ export default { async parse({ body: { payreq } }, res) { try { - let hour = 1000 * 60 * 60; - let { last } = store.nodes; - let { nodes } = store; + let hour = 1000 * 60 * 60; + let { last } = store.nodes; + let { nodes } = store; - if (!last || last > Date.now() - hour) ({ nodes } = await ln.listnodes()); - store.nodes = nodes; + if (!last || last > Date.now() - hour) ({ nodes } = await ln.listnodes()); + store.nodes = nodes; - let twoWeeksAgo = new Date(new Date().setDate(new Date().getDate() - 14)); - let decoded = await ln.decodepay(payreq); - let { msatoshi, payee } = decoded; - let node = nodes.find((n) => n.nodeid === payee); - let alias = node ? node.alias : payee.substr(0, 12); + let twoWeeksAgo = new Date(new Date().setDate(new Date().getDate() - 14)); + let decoded = await ln.decodepay(payreq); + let { msatoshi, payee } = decoded; + let node = nodes.find((n) => n.nodeid === payee); + let alias = node ? node.alias : payee.substr(0, 12); - res.send({ alias, amount: Math.round(msatoshi / 1000) }); - } catch(e) { + res.send({ alias, amount: Math.round(msatoshi / 1000) }); + } catch (e) { bail(res, e.message); - } + } }, async pot({ params: { name } }, res) { diff --git a/routes/users.js b/routes/users.js index 780d4003..f4e68d1e 100644 --- a/routes/users.js +++ b/routes/users.js @@ -1,7 +1,7 @@ import { g, s, db } from "$lib/db"; import config from "$config"; import store from "$lib/store"; - import { +import { fields, nada, pick, @@ -9,7 +9,7 @@ import store from "$lib/store"; wait, bail, fail, - getUser + getUser, } from "$lib/utils"; import bcrypt from "bcrypt"; import jwt from "jsonwebtoken"; @@ -92,7 +92,7 @@ export default { username: key, display: key.substr(0, 6), pubkey: key, - anon: true + anon: true, }; } @@ -109,7 +109,7 @@ export default { "pubkey", "display", "prompt", - "id" + "id", ]; if (user.pubkey) @@ -133,7 +133,7 @@ export default { pubkey, password, username, - salt + salt, }; user = await register(user, ip, false); @@ -210,7 +210,7 @@ export default { "salt", "seed", "tokens", - "twofa" + "twofa", ]; for (let a of attributes) { @@ -254,7 +254,7 @@ export default { if (!token) fail(); user = await got(`${classic}/admin/migrate/${username}?zero=true`, { - headers: { authorization: `Bearer ${config.admin}` } + headers: { authorization: `Bearer ${config.admin}` }, }).json(); let { balance } = user; @@ -266,7 +266,7 @@ export default { ...pick(user, fields), id: uid, about: user.address, - migrated: true + migrated: true, }; await s(`user:${username}`, uid); @@ -274,7 +274,7 @@ export default { await s(`balance:${uid}`, balance); let payments = await got(`${classic}/payments`, { - headers: { authorization: `Bearer ${token}` } + headers: { authorization: `Bearer ${token}` }, }).json(); for (let p of payments) { @@ -284,7 +284,7 @@ export default { "confirmed", "rate", "currency", - "preimage" + "preimage", ]); n.id = v4(); n.created = parseISO(p.createdAt).getTime(); @@ -302,7 +302,7 @@ export default { u = await got( `${classic}/admin/migrate/${p.with.username.toLowerCase()}`, { - headers: { authorization: `Bearer ${config.admin}` } + headers: { authorization: `Bearer ${config.admin}` }, } ).json(); @@ -374,7 +374,7 @@ export default { if (!subscriptions) subscriptions = []; if ( !subscriptions.find( - s => JSON.stringify(s) === JSON.stringify(subscription) + (s) => JSON.stringify(s) === JSON.stringify(subscription) ) ) subscriptions.push(subscription); @@ -411,8 +411,8 @@ export default { let contacts = (await g(`${id}:contacts`)) || []; for (let { ref } of ( - await Promise.all(payments.map(async id => await g(`payment:${id}`))) - ).filter(p => p.type === types.internal && p.ref)) { + await Promise.all(payments.map(async (id) => await g(`payment:${id}`))) + ).filter((p) => p.type === types.internal && p.ref)) { !~contacts.findIndex(({ id }) => id === ref) && contacts.push(await g(`user:${ref}`)); } @@ -470,5 +470,5 @@ export default { } catch (e) { bail(res, e.message); } - } + }, }; |
