aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-03-11 10:20:46 -0800
committerAdam Soltys <[email protected]>2023-03-11 10:20:46 -0800
commit5955ff6969a5301c4413631b76cf2300d193f8ed (patch)
tree92d1269a098cb7c764ca92f7a40af9ee236ae5b1 /routes
parent7fec7cc3e7c51a9892869732b5bfe65922ee7818 (diff)
downloadcoinos-server-5955ff6969a5301c4413631b76cf2300d193f8ed.tar.gz
coinos-server-5955ff6969a5301c4413631b76cf2300d193f8ed.zip
separate tips from amounts
Diffstat (limited to 'routes')
-rw-r--r--routes/email.js26
-rw-r--r--routes/info.js4
-rw-r--r--routes/invoices.js6
-rw-r--r--routes/lnurl.js14
-rw-r--r--routes/locations.js2
-rw-r--r--routes/nostr.js41
-rw-r--r--routes/payments.js8
-rw-r--r--routes/rates.js2
-rw-r--r--routes/requests.js16
-rw-r--r--routes/users.js32
10 files changed, 75 insertions, 76 deletions
diff --git a/routes/email.js b/routes/email.js
index 9213cdd3..1b551864 100644
--- a/routes/email.js
+++ b/routes/email.js
@@ -6,16 +6,16 @@ import sendgrid from "@sendgrid/mail";
export default {
async send({ body }, res) {
let { token: response } = body;
- let { recaptcha: secret } = config;
- let { success } = await got
+ let { recaptcha: secret } = config;
+ let { success } = await got
.post("https://www.google.com/recaptcha/api/siteverify", {
form: {
secret,
- response
- }
+ response,
+ },
})
.json();
-
+
if (success) {
delete body.token;
sendgrid.setApiKey(config.sendgrid);
@@ -24,15 +24,13 @@ export default {
subject: body.subject || "Email Signup",
text: JSON.stringify(body),
- html: JSON.stringify(body)
+ html: JSON.stringify(body),
};
- await sendgrid.send(msg);
- res.send({ ok: true });
-
- }
- else {
- bail(res, "failed captcha");
- }
- }
+ await sendgrid.send(msg);
+ res.send({ ok: true });
+ } else {
+ bail(res, "failed captcha");
+ }
+ },
};
diff --git a/routes/info.js b/routes/info.js
index ae347b56..13b1de57 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 8e23e5f1..5d36edf0 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 dcd1657c..cad209c5 100644
--- a/routes/lnurl.js
+++ b/routes/lnurl.js
@@ -45,7 +45,7 @@ export default {
let uid = await g(`user:${username.toLowerCase()}`);
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");
@@ -65,7 +65,7 @@ export default {
let metadata = JSON.stringify([
["text/plain", `Paying ${username}@${host}`],
- ["text/identifier", `${username}@${host}`]
+ ["text/identifier", `${username}@${host}`],
]);
let id = v4();
@@ -76,7 +76,7 @@ export default {
maxSendable: 100000000000,
metadata,
callback: `${URL}/api/lnurl/${id}`,
- tag: "payRequest"
+ tag: "payRequest",
});
},
@@ -90,21 +90,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 fb4487f7..04a94175 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 d9a5e841..e274f61e 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,14 +63,14 @@ export default {
params = {
kinds: [4],
- "#p": [pubkey]
+ "#p": [pubkey],
};
await q(`${pubkey}:messages`, params, opts).catch(nada);
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}`);
@@ -97,7 +97,7 @@ export default {
params = {
limit: 1,
kinds: [3],
- authors: [pubkey]
+ authors: [pubkey],
},
opts = { timeout: 60000, eager: 60000 };
@@ -113,7 +113,7 @@ export default {
q(`${pubkey}:profile:f1`, {
limit: 1,
kinds: [0],
- authors: [pubkey]
+ authors: [pubkey],
}).catch(nada);
let uid = await g(`user:${pubkey}`);
@@ -123,13 +123,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);
@@ -138,7 +138,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 = [];
@@ -156,7 +156,7 @@ export default {
await q(`${pubkey}:profile:f2`, {
limit: 1,
kinds: [0],
- authors: [pubkey]
+ authors: [pubkey],
}).catch(nada);
uid = await g(`user:${pubkey}`);
@@ -167,13 +167,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);
@@ -186,11 +186,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 f62eaa6e..a180d0a3 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -36,21 +36,23 @@ export default {
})
.json();
} else if (payreq) {
+ let total = amount;
let { msatoshi, payment_hash } = await ln.decode(payreq);
- if (msatoshi) amount = Math.round(msatoshi / 1000);
+ if (msatoshi) total = Math.round(msatoshi / 1000);
let invoice = await g(`invoice:${payment_hash}`);
if (invoice) {
if (invoice.uid === user.id) fail("Cannot send to self");
hash = payment_hash;
} else {
- p = await debit(hash, amount, maxfee, memo, user, types.lightning);
+ p = await debit(hash, total, maxfee, memo, user, types.lightning);
let r;
try {
r = await ln.pay(payreq, msatoshi ? undefined : `${amount}sats`);
p.amount = -amount;
+ p.tip = total - amount;
p.hash = r.payment_hash;
p.fee = Math.round((r.msatoshi_sent - r.msatoshi) / 1000);
p.ref = r.payment_preimage;
@@ -280,8 +282,6 @@ export default {
total = total - change + fee;
let amount = total - fee;
- console.log("AMOUNT", amount);
-
if (change && !amount) fail("Cannot send to unregistered coinos address");
await debit(txid, amount, fee, null, user, types.bitcoin, txid);
diff --git a/routes/rates.js b/routes/rates.js
index c36c7ae8..08b604bb 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 11bf9a36..02560733 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 c5ff938a..68e59b24 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -28,7 +28,8 @@ export default {
try {
user.balance = await g(`balance:${user.id}`);
user.prompt = !!user.prompt;
- if (user.pubkey) user.npub = encode("npub", toWords(Buffer.from(user.pubkey, "hex")));
+ if (user.pubkey)
+ user.npub = encode("npub", toWords(Buffer.from(user.pubkey, "hex")));
res.send(pick(user, whitelist));
} catch (e) {
console.log("problem fetching user", e);
@@ -56,7 +57,7 @@ export default {
username: key,
display: key.substr(0, 6),
pubkey: key,
- anon: true
+ anon: true,
};
}
@@ -73,10 +74,11 @@ export default {
"pubkey",
"display",
"prompt",
- "id"
+ "id",
];
- if (user.pubkey) user.npub = encode("npub", toWords(Buffer.from(user.pubkey, "hex")));
+ if (user.pubkey)
+ user.npub = encode("npub", toWords(Buffer.from(user.pubkey, "hex")));
user.prompt = !!user.prompt;
res.send(pick(user, whitelist));
@@ -96,7 +98,7 @@ export default {
pubkey,
password,
username,
- salt
+ salt,
};
user = await register(user, ip, false);
@@ -172,7 +174,7 @@ export default {
"salt",
"seed",
"tokens",
- "twofa"
+ "twofa",
];
for (let a of attributes) {
@@ -212,7 +214,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;
@@ -224,7 +226,7 @@ export default {
...pick(user, fields),
id: uid,
about: user.address,
- migrated: true
+ migrated: true,
};
await s(`user:${username}`, uid);
@@ -232,7 +234,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) {
@@ -242,7 +244,7 @@ export default {
"confirmed",
"rate",
"currency",
- "preimage"
+ "preimage",
]);
n.id = v4();
n.created = parseISO(p.createdAt).getTime();
@@ -260,7 +262,7 @@ export default {
u = await got(
`${classic}/admin/migrate/${p.with.username.toLowerCase()}`,
{
- headers: { authorization: `Bearer ${config.admin}` }
+ headers: { authorization: `Bearer ${config.admin}` },
}
).json();
@@ -332,7 +334,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);
@@ -369,8 +371,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}`));
}
@@ -407,5 +409,5 @@ export default {
}
res.send("ok");
- }
+ },
};