aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--index.js2
-rw-r--r--lib/db.js2
-rw-r--r--lib/payments.js6
-rw-r--r--routes/payments.js13
4 files changed, 15 insertions, 8 deletions
diff --git a/index.js b/index.js
index 5b8a3afb..5dbfd209 100644
--- a/index.js
+++ b/index.js
@@ -54,7 +54,7 @@ app.get("/invoice/classic/:username", invoices.classic);
app.post("/payments", auth, payments.create);
app.get("/payments", auth, payments.list);
app.get("/payments/:hash", auth, payments.get);
-app.post("/parse", payments.parse);
+app.post("/parse", auth, payments.parse);
app.get("/fund/:name", payments.fund);
app.get("/fund/:name/withdraw", payments.withdraw);
app.post("/take", auth, payments.take);
diff --git a/lib/db.js b/lib/db.js
index ab88925f..d14e4962 100644
--- a/lib/db.js
+++ b/lib/db.js
@@ -18,7 +18,7 @@ local covered = math.min(credit, ourfee)
ourfee = ourfee - covered
if balance < amount + tip + fee + ourfee then
- return {err = 'Insufficient funds'}
+ return {err = 'Insufficient funds ' .. balance .. ' vs ' .. amount + tip + fee + ourfee}
end
redis.call('decrby', creditKey, tostring(math.floor(covered)))
diff --git a/lib/payments.js b/lib/payments.js
index 9eeec99a..c76bea70 100644
--- a/lib/payments.js
+++ b/lib/payments.js
@@ -33,11 +33,11 @@ export let debit = async ({
user,
type = types.internal,
id = v4(),
- rate
+ rate,
}) => {
let ref;
let { id: uid, currency, username } = user;
- if (!rate) rate = store.rates[currency]
+ if (!rate) rate = store.rates[currency];
let iid = await g(`invoice:${hash}`);
if (iid && iid.hash) iid = iid.hash;
@@ -73,7 +73,7 @@ export let debit = async ({
ourfee || 0,
);
- if (r !== "ok") fail("Insufficient funds");
+ if (r !== "ok") fail("Problem debiting account");
let p = {
id,
diff --git a/routes/payments.js b/routes/payments.js
index 328e4d80..c2c9f324 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -37,7 +37,7 @@ catchUp();
export default {
async create({ body, user }, res) {
warn(user.username, JSON.stringify(body));
- let { amount, hash, maxfee, fund, memo, payreq, username } = body;
+ let { amount, hash, maxfee, fund, memo, payreq, rate, username } = body;
try {
if (await g("freeze")) fail("Problem sending payment");
@@ -59,6 +59,7 @@ export default {
hash,
amount,
memo: username,
+ rate,
user,
type: types.classic,
});
@@ -146,7 +147,7 @@ export default {
res.send(p);
},
- async parse({ body: { payreq } }, res) {
+ async parse({ body: { payreq }, user }, res) {
try {
let hour = 1000 * 60 * 60;
let { last } = store.nodes;
@@ -161,7 +162,13 @@ export default {
let node = nodes.find((n) => n.nodeid === payee);
let alias = node ? node.alias : payee.substr(0, 12);
- res.send({ alias, amount: Math.round(amount_msat / 1000) });
+ let amount = Math.round(amount_msat / 1000);
+ let ourfee = Math.round(amount * config.fee);
+ let credit = await g(`credit:lightning:${user.id}`);
+ let covered = Math.min(credit, ourfee) || 0;
+ ourfee -= covered;
+
+ res.send({ alias, amount, ourfee });
} catch (e) {
bail(res, e.message);
}