diff options
| author | Adam Soltys <[email protected]> | 2023-04-06 15:25:07 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-04-06 15:25:07 -0700 |
| commit | 99b72e143866d5cc62ba04847885070dc9a5c645 (patch) | |
| tree | abda08ae881b6e9bfff2ebbcf58d1409d7395fcf | |
| parent | 5083648dc113547c1c604e0c93ed0ee961f01ea3 (diff) | |
| download | coinos-server-99b72e143866d5cc62ba04847885070dc9a5c645.tar.gz coinos-server-99b72e143866d5cc62ba04847885070dc9a5c645.zip | |
prettier
| -rw-r--r-- | lib/app.js | 11 | ||||
| -rw-r--r-- | lib/auth.js | 12 | ||||
| -rw-r--r-- | lib/countries.js | 2 | ||||
| -rw-r--r-- | lib/db.js | 2 | ||||
| -rw-r--r-- | lib/invoices.js | 2 | ||||
| -rw-r--r-- | lib/lightning.js | 2 | ||||
| -rw-r--r-- | lib/locations.js | 3 | ||||
| -rw-r--r-- | lib/nostr.js | 12 | ||||
| -rw-r--r-- | lib/payments.js | 6 | ||||
| -rw-r--r-- | lib/rates.js | 6 | ||||
| -rw-r--r-- | lib/register.js | 4 | ||||
| -rw-r--r-- | lib/rpc.js | 38 | ||||
| -rw-r--r-- | lib/sockets.js | 8 | ||||
| -rw-r--r-- | lib/store.js | 2 | ||||
| -rw-r--r-- | lib/upload.js | 9 | ||||
| -rw-r--r-- | lib/utils.js | 14 | ||||
| -rw-r--r-- | lib/webhooks.js | 4 | ||||
| -rw-r--r-- | lib/whitelist.js | 2 | ||||
| -rw-r--r-- | routes/email.js | 20 | ||||
| -rw-r--r-- | routes/info.js | 4 | ||||
| -rw-r--r-- | routes/invoices.js | 6 | ||||
| -rw-r--r-- | routes/lnurl.js | 14 | ||||
| -rw-r--r-- | routes/locations.js | 2 | ||||
| -rw-r--r-- | routes/nostr.js | 41 | ||||
| -rw-r--r-- | routes/payments.js | 45 | ||||
| -rw-r--r-- | routes/rates.js | 2 | ||||
| -rw-r--r-- | routes/requests.js | 16 | ||||
| -rw-r--r-- | routes/users.js | 28 | ||||
| -rw-r--r-- | sampledata/index.js | 4 |
29 files changed, 164 insertions, 157 deletions
@@ -15,11 +15,11 @@ import { socketServer } from "$lib/sockets"; const app = fastify({ logger: pino(), disableRequestLogging: true, - maxParamLength: 500, + maxParamLength: 500 }); app.register(fastifySecureSession, { - key: Buffer.from(config.jwt, "hex"), + key: Buffer.from(config.jwt, "hex") }); app.register(fastifyPassport.initialize()); @@ -31,7 +31,7 @@ app.register(fastifyMultipart); app.register(fastifyStatic, { root: path.join("/app/data/uploads"), - prefix: "/public/", + prefix: "/public/" }); app.register(fastifyWs); @@ -46,7 +46,10 @@ app.setErrorHandler((error, request, reply) => { }); app.setNotFoundHandler((request, reply) => { - reply.code(404).type("text/html").send("Not Found"); + reply + .code(404) + .type("text/html") + .send("Not Found"); }); export default app; diff --git a/lib/auth.js b/lib/auth.js index d9d2a8e5..0533de31 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -7,17 +7,17 @@ export const optional = { preValidation: fastifyPassport.authenticate( "jwt", { session: false }, - function (req, res, err, user, info) { + function(req, res, err, user, info) { req.user = user; } - ), + ) }; export const auth = { preValidation: fastifyPassport.authenticate("jwt", { authInfo: false, - session: false, - }), + session: false + }) }; export const requirePin = async ({ body, user }) => { @@ -29,9 +29,9 @@ export const jwtStrategy = new jwt.Strategy( { jwtFromRequest: jwt.ExtractJwt.fromExtractors([ jwt.ExtractJwt.fromAuthHeaderAsBearerToken(), - (req) => (req.cookies ? req.cookies.token : null), + req => (req.cookies ? req.cookies.token : null) ]), - secretOrKey: config.jwt, + secretOrKey: config.jwt }, async (payload, next) => { let user; diff --git a/lib/countries.js b/lib/countries.js index 71bc2344..4d5a48dc 100644 --- a/lib/countries.js +++ b/lib/countries.js @@ -245,5 +245,5 @@ export default { VN: "VNM", YE: "YEM", ZM: "ZMB", - ZW: "ZWE", + ZW: "ZWE" }; @@ -7,7 +7,7 @@ export const db = createClient({ url: config.db }); await db.connect(); export default db; -export let g = async (k) => { +export let g = async k => { let v = await db.get(k); try { return JSON.parse(v); diff --git a/lib/invoices.js b/lib/invoices.js index ff372bf4..9e75abcb 100644 --- a/lib/invoices.js +++ b/lib/invoices.js @@ -64,7 +64,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 e4a2bbd9..7ef62cc9 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/locations.js b/lib/locations.js index 6df50e0c..39883555 100644 --- a/lib/locations.js +++ b/lib/locations.js @@ -8,8 +8,7 @@ export let getLocations = async () => { ).json(); locations = locations.filter( - (l) => - l["osm_json"].tags && l["osm_json"].tags["payment:coinos"] === "yes" + l => l["osm_json"].tags && l["osm_json"].tags["payment:coinos"] === "yes" ); await s("locations", locations); diff --git a/lib/nostr.js b/lib/nostr.js index 2ecd1c5c..604d207d 100644 --- a/lib/nostr.js +++ b/lib/nostr.js @@ -10,7 +10,7 @@ export let pool; export let fillPool = () => { pool = RelayPool(config.relays); - pool.on("open", (relay) => { + pool.on("open", relay => { if (relay.url.includes(config.nostr)) coinos = relay; relay.subscribe("live", { limit: 1 }); }); @@ -62,7 +62,7 @@ export let fillPool = () => { user = { ...user, ...content, - updated: ev.created_at, + updated: ev.created_at }; await s(`user:${pubkey}`, JSON.stringify(user)); @@ -112,7 +112,7 @@ export let q = async ( let done = { [sub]: [] }; - let check = (s) => { + let check = s => { let elapsed = Date.now() - start; if (rejected) return true; if ( @@ -147,7 +147,7 @@ export let q = async ( rejected = true; }, timeout); }, - timer: undefined, + timer: undefined }; timeouts[sub].extend(); @@ -167,14 +167,14 @@ export let q = async ( let seen = []; -let getUser = async (pubkey) => { +let getUser = async pubkey => { let id = await g(`user:${pubkey}`); let user = await g(`user:${id}`); return ( user || { username: pubkey.substr(0, 6), pubkey, - anon: true, + anon: true } ); }; diff --git a/lib/payments.js b/lib/payments.js index fe6a718c..7dbc1775 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); @@ -139,7 +139,7 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { tip, type, confirmed: true, - created: Date.now(), + created: Date.now() }; if (type === types.bitcoin) invoice.pending += amount; diff --git a/lib/rates.js b/lib/rates.js index 1d0eedb3..16ce37d5 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/register.js b/lib/register.js index 69b7f4e0..71b8e17d 100644 --- a/lib/register.js +++ b/lib/register.js @@ -29,8 +29,8 @@ export default async (user, ip, requireChallenge) => { try { let { location: { - country: { code }, - }, + country: { code } + } } = await got( `https://api.ipregistry.co/${ip}?key=${config.ipregistry}&fields=location.country.code` ).json(); @@ -4,25 +4,23 @@ export default ({ host, port, wallet, username, password }) => new Proxy( {}, { - get: - (target, prop) => - (...params) => - ((method, ...params) => { - let url = `http://${host}:${port}/wallet/${wallet}`; - return got - .post(url, { - json: { - method, - params, - }, - headers: { - authorization: `Basic ${Buffer.from( - `${username}:${password}` - ).toString("base64")}`, - }, - }) - .json() - .then(({ result }) => result); - })(prop.toLowerCase(), ...params), + get: (target, prop) => (...params) => + ((method, ...params) => { + let url = `http://${host}:${port}/wallet/${wallet}`; + return got + .post(url, { + json: { + method, + params + }, + headers: { + authorization: `Basic ${Buffer.from( + `${username}:${password}` + ).toString("base64")}` + } + }) + .json() + .then(({ result }) => result); + })(prop.toLowerCase(), ...params) } ); diff --git a/lib/sockets.js b/lib/sockets.js index 55cd642e..458c77a9 100644 --- a/lib/sockets.js +++ b/lib/sockets.js @@ -41,7 +41,7 @@ export const broadcast = (type, data) => { } } - Object.values(all).map((ws) => { + Object.values(all).map(ws => { if (!sent.includes(ws.id)) ws.send(JSON.stringify({ type, data })); }); }; @@ -56,7 +56,7 @@ export async function socketServer(app) { ws.send(JSON.stringify({ type: "connected", data: id })); all[id] = ws; - ws.on("message", async (message) => { + ws.on("message", async message => { let type, data; try { ({ type, data } = JSON.parse(message)); @@ -87,7 +87,7 @@ export async function socketServer(app) { if (!store.sockets[uid]) store.sockets[uid] = {}; const existing = Object.keys(store.sockets[uid]); if (existing.length > 4) { - const p = existing.find((sid) => sid !== uid); + const p = existing.find(sid => sid !== uid); store.sockets[uid][p].send(JSON.stringify({ type: "logout" })); setTimeout(() => { if (store.sockets[uid][p]) @@ -132,7 +132,7 @@ export async function socketServer(app) { ws.on("error", console.log); - ws.on("close", function (code, reason) { + ws.on("close", function(code, reason) { try { const uid = users[id]; if (store.sockets[uid] && store.sockets[uid][id]) { diff --git a/lib/store.js b/lib/store.js index 4c86761c..bf71219e 100644 --- a/lib/store.js +++ b/lib/store.js @@ -18,5 +18,5 @@ export default { last: {}, payments: [], fetching: {}, - timeouts: {}, + timeouts: {} }; diff --git a/lib/upload.js b/lib/upload.js index cb14f459..d46c116c 100644 --- a/lib/upload.js +++ b/lib/upload.js @@ -10,7 +10,7 @@ import { g, s, db } from "$lib/db"; export default async (req, res) => { let { params: { type }, - user, + user } = req; if (!["banner", "profile"].includes(type)) throw new Error("invalid upload"); @@ -28,9 +28,12 @@ export default async (req, res) => { let path = `/app/data/uploads/${name}`; let size = type === "banner" ? 1920 : 240; - let t = sharp().rotate().resize(size).webp(); + let t = sharp() + .rotate() + .resize(size) + .webp(); - await new Promise((r) => pipeline(s2, t, fs.createWriteStream(path), r)); + await new Promise(r => pipeline(s2, t, fs.createWriteStream(path), r)); user[type] = true; await s(`user:${user.id}`, user); diff --git a/lib/utils.js b/lib/utils.js index 1e12214b..2eac0054 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,10 +53,10 @@ export const fields = [ "haspin", "profile", "prompt", - "banner", + "banner" ]; -export const getUser = async (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/lib/webhooks.js b/lib/webhooks.js index 2ae5a890..1158fe9d 100644 --- a/lib/webhooks.js +++ b/lib/webhooks.js @@ -20,8 +20,8 @@ export const callWebhook = async (invoice, payment) => { hash, memo, received, - text, - }, + text + } }).res(); return res; } diff --git a/lib/whitelist.js b/lib/whitelist.js index 8f1f65ee..9b2225e2 100644 --- a/lib/whitelist.js +++ b/lib/whitelist.js @@ -27,5 +27,5 @@ export default [ "theme", "twofa", "username", - "verified", + "verified" ]; diff --git a/routes/email.js b/routes/email.js index ba590d4c..c043f0c8 100644 --- a/routes/email.js +++ b/routes/email.js @@ -13,8 +13,8 @@ export default { .post("https://www.google.com/recaptcha/api/siteverify", { form: { secret, - response, - }, + response + } }) .json(); @@ -26,25 +26,25 @@ export default { new SendEmailCommand({ Destination: { CcAddresses: [], - ToAddresses: ["[email protected]"], + ToAddresses: ["[email protected]"] }, Message: { Body: { Html: { Charset: "UTF-8", - Data: JSON.stringify(body), + Data: JSON.stringify(body) }, Text: { Charset: "UTF-8", - Data: JSON.stringify(body), - }, + Data: JSON.stringify(body) + } }, Subject: { Charset: "UTF-8", - Data: body.subject || "Support Request", - }, + Data: body.subject || "Support Request" + } }, - Source: "[email protected]", + Source: "[email protected]" }) ); @@ -52,5 +52,5 @@ export default { } else { bail(res, "failed captcha"); } - }, + } }; diff --git a/routes/info.js b/routes/info.js index 13b1de57..ae347b56 100644 --- a/routes/info.js +++ b/routes/info.js @@ -18,9 +18,9 @@ export default { const info = { lnchannel, lnwallet, - total, + total }; res.send(info); - }, + } }; diff --git a/routes/invoices.js b/routes/invoices.js index 5d36edf0..8e23e5f1 100644 --- a/routes/invoices.js +++ b/routes/invoices.js @@ -41,11 +41,11 @@ export default { .post(`${config.classic}/invoice`, { json: { invoice: { amount: 0, network: "lightning" }, - user: { username }, - }, + user: { username } + } }) .json(); res.send(invoice); - }, + } }; diff --git a/routes/lnurl.js b/routes/lnurl.js index 1f45627b..bcb3f234 100644 --- a/routes/lnurl.js +++ b/routes/lnurl.js @@ -46,7 +46,7 @@ export default { let { id: uid } = await getUser(username); if (!uid) { let u = await got(`${classic}/admin/migrate/${username}?zero=true`, { - headers: { authorization: `Bearer ${admin}` }, + headers: { authorization: `Bearer ${admin}` } }).json(); if (!u) fail("user not found"); @@ -66,7 +66,7 @@ export default { let metadata = JSON.stringify([ ["text/plain", `Paying ${username}@${host}`], - ["text/identifier", `${username}@${host}`], + ["text/identifier", `${username}@${host}`] ]); let id = v4(); @@ -77,7 +77,7 @@ export default { maxSendable: 100000000000, metadata, callback: `${URL}/api/lnurl/${id}`, - tag: "payRequest", + tag: "payRequest" }); } catch (e) { warn("problem generating lnurlp request", e.message); @@ -95,21 +95,21 @@ export default { let metadata = JSON.stringify([ ["text/plain", `Paying ${username}@${host}`], - ["text/identifier", `${username}@${host}`], + ["text/identifier", `${username}@${host}`] ]); ({ text: pr } = await generate({ invoice: { amount: Math.round(amount / 1000), - type: types.lightning, + type: types.lightning }, memo: metadata, - user, + user })); await s(`lnurlp:${id}`, pr); } res.send({ pr, routes: [] }); - }, + } }; diff --git a/routes/locations.js b/routes/locations.js index 04a94175..fb4487f7 100644 --- a/routes/locations.js +++ b/routes/locations.js @@ -3,5 +3,5 @@ import { g } from "$lib/db"; export default { async list(req, res) { res.send({ locations: await g("locations") }); - }, + } }; diff --git a/routes/nostr.js b/routes/nostr.js index e45c0cbd..33233a7a 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,10 +187,11 @@ export default { async identities(req, res) { res.send({ names: { - adam: "566c166f3adab0c8fba5da015b0b3bcc8eb3696b455f2a1d43bfbd97059646a8", - asoltys: + adam: "566c166f3adab0c8fba5da015b0b3bcc8eb3696b455f2a1d43bfbd97059646a8", - }, + asoltys: + "566c166f3adab0c8fba5da015b0b3bcc8eb3696b455f2a1d43bfbd97059646a8" + } }); - }, + } }; diff --git a/routes/payments.js b/routes/payments.js index 5985f2ed..571d84f4 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -15,12 +15,12 @@ import ln from "$lib/ln"; let seen = []; let catchUp = async () => { let txns = await bc.listTransactions("*", 50); - txns = txns.filter((tx) => tx.category === "receive" && tx.confirmations > 0); + txns = txns.filter(tx => tx.category === "receive" && tx.confirmations > 0); for (let { txid } of txns) { try { if (seen.includes(txid)) continue; await got.post(`http://localhost:${process.env.PORT || 3119}/bitcoin`, { - json: { txid, wallet: config.bitcoin.wallet }, + json: { txid, wallet: config.bitcoin.wallet } }); seen.push(txid); @@ -54,7 +54,7 @@ export default { await got .post(`${config.classic}/admin/credit`, { json: { username, amount, source }, - headers: { authorization: `Bearer ${config.admin}` }, + headers: { authorization: `Bearer ${config.admin}` } }) .json(); } else if (payreq) { @@ -74,7 +74,7 @@ export default { r = await ln.pay({ bolt11: payreq.replace(/\s/g, "").toLowerCase(), amount_msat: msatoshi ? undefined : `${amount}sats`, - maxfee, + maxfee }); if (r.status !== "complete") fail("payment did not complete"); @@ -129,7 +129,7 @@ export default { let payments = (await db.lRange(`${id}:payments`, 0, -1)) || []; payments = ( await Promise.all( - payments.map(async (id) => { + payments.map(async id => { let p = await g(`payment:${id}`); if (p.created < start || p.created > end) return; if (p.type === types.internal) p.with = await g(`user:${p.ref}`); @@ -137,7 +137,7 @@ export default { }) ) ) - .filter((p) => p) + .filter(p => p) .sort((a, b) => b.created - a.created); let total = payments.length; @@ -165,7 +165,7 @@ export default { 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 node = nodes.find(n => n.nodeid === payee); let alias = node ? node.alias : payee.substr(0, 12); res.send({ alias, amount: Math.round(msatoshi / 1000) }); @@ -178,13 +178,13 @@ export default { let amount = await g(`pot:${name}`); if (!amount) return bail(res, "pot not found"); let payments = (await db.lRange(`pot:${name}:payments`, 0, -1)) || []; - payments = await Promise.all(payments.map((hash) => g(`payment:${hash}`))); + payments = await Promise.all(payments.map(hash => g(`payment:${hash}`))); await Promise.all( - payments.map(async (p) => (p.user = await g(`user:${p.uid}`))) + payments.map(async p => (p.user = await g(`user:${p.uid}`))) ); - payments = payments.filter((p) => p); + payments = payments.filter(p => p); res.send({ amount, payments }); }, @@ -192,13 +192,16 @@ export default { amount = parseInt(amount); await t(`pot:${name}`, async (balance, db) => { if (balance < amount) fail("Insufficient funds"); - await db.multi().decrBy(`pot:${name}`, amount).exec(); + await db + .multi() + .decrBy(`pot:${name}`, amount) + .exec(); }); let hash = v4(); await s(`invoice:${hash}`, { uid: user.id, - received: 0, + received: 0 }); let payment = await credit(hash, amount, "", name, types.pot); @@ -258,7 +261,7 @@ export default { let tx = await bc.fundRawTransaction(raw, { feeRate, subtractFeeFromOutputs, - replaceable, + replaceable }); let fee = sats(tx.fee); @@ -301,7 +304,7 @@ export default { for (let { scriptPubKey: { address }, - value, + value } of tx.vout) { total += sats(value); if ( @@ -336,13 +339,13 @@ export default { "card[number]": number, "card[exp_month]": month, "card[exp_year]": year, - "card[cvc]": cvc, + "card[cvc]": cvc }; let { id: source } = await got .post(`${stripe}/tokens`, { form, - username, + username }) .json(); @@ -351,13 +354,13 @@ export default { amount, currency, source, - description: "starter coupon", + description: "starter coupon" }; let r = await got .post(`${stripe}/charges`, { form, - username, + username }) .json(); @@ -367,7 +370,7 @@ export default { let memo = "stripe"; await s(`invoice:${hash}`, { uid: user.id, - received: 0, + received: 0 }); amount = sats(amount / store.rates[currency]); let uid = await g("user:coinos"); @@ -387,7 +390,7 @@ export default { "estimatesmartfee", "echo", "getblockchaininfo", - "getnetworkinfo", + "getnetworkinfo" ]; if (!whitelist.includes(method)) fail("unsupported method"); @@ -431,5 +434,5 @@ export default { } catch (e) { bail(res, e.message); } - }, + } }; diff --git a/routes/rates.js b/routes/rates.js index 08b604bb..c36c7ae8 100644 --- a/routes/rates.js +++ b/routes/rates.js @@ -7,5 +7,5 @@ export default { async index(req, res) { res.send(store.rates); - }, + } }; diff --git a/routes/requests.js b/routes/requests.js index 02560733..11bf9a36 100644 --- a/routes/requests.js +++ b/routes/requests.js @@ -19,21 +19,21 @@ export default { let requests = await db.lRange(`${id}:requests`, 0, -1); - requests = await Promise.all(requests.map((id) => g(`request:${id}`))); + requests = await Promise.all(requests.map(id => g(`request:${id}`))); requests = await Promise.all( - requests.map(async (r) => { + requests.map(async r => { r.requester = await g(`user:${r.requester_id}`); r.recipient = await g(`user:${r.recipient_id}`); return r; }) ); - let sent = requests.filter((r) => r.requester_id === id); + let sent = requests.filter(r => r.requester_id === id); let received = requests - .filter((r) => r.recipient_id === id) - .filter((r) => !r.invoice_id); + .filter(r => r.recipient_id === id) + .filter(r => !r.invoice_id); let invoices = []; for (let r of sent) { @@ -56,7 +56,7 @@ export default { async create( { body: { recipient, ...params }, - user: { id: requester_id, username, profile }, + user: { id: requester_id, username, profile } }, res ) { @@ -67,7 +67,7 @@ export default { id, recipient_id, requester_id, - ...params, + ...params }; await s(`request:${id}`, request); @@ -81,5 +81,5 @@ export default { async destroy({ body: { request_id }, user: { id } }, res) { await db.lrem(`user:${id}:requests`, request_id); res.send(); - }, + } }; diff --git a/routes/users.js b/routes/users.js index 1e4d00cc..9130b249 100644 --- a/routes/users.js +++ b/routes/users.js @@ -9,7 +9,7 @@ import { 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}`)); } @@ -476,5 +476,5 @@ export default { } catch (e) { bail(res, e.message); } - }, + } }; diff --git a/sampledata/index.js b/sampledata/index.js index a2f2e259..8fcb0a6f 100644 --- a/sampledata/index.js +++ b/sampledata/index.js @@ -10,7 +10,7 @@ export default { username: "admin1", password: "123", network: "regtest", - port: 18443, + port: 18443 }, - lightning: "/app/config/lightning/regtest/lightning-rpc", + lightning: "/app/config/lightning/regtest/lightning-rpc" }; |
