aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-09-09 10:27:32 -0400
committerAdam Soltys <[email protected]>2022-09-09 10:27:32 -0400
commitb075ae593d619a860c0b38350cada35f29f65c23 (patch)
tree153f3bb2b230de1a71927dd7535b5d48833fcaa8
parentb727f70be4af1c9604f5827d8a2e310632910f4a (diff)
downloadcoinos-server-b075ae593d619a860c0b38350cada35f29f65c23.tar.gz
coinos-server-b075ae593d619a860c0b38350cada35f29f65c23.zip
use actual received amount for lightning payments
-rw-r--r--lib/sync.js12
-rw-r--r--routes/lightning/invoice.js3
-rw-r--r--routes/lightning/receive.js4
3 files changed, 8 insertions, 11 deletions
diff --git a/lib/sync.js b/lib/sync.js
index 7b72b20a..536bd582 100644
--- a/lib/sync.js
+++ b/lib/sync.js
@@ -80,14 +80,14 @@ const sync = async () => {
let recent = invoices
.filter(
i =>
- i.settled &&
- differenceInDays(new Date(), new Date(i.settle_date * 1000)) < 2
+ i.secret &&
+ differenceInDays(new Date(), new Date(i.created_at)) < 2
)
.map(i => ({
- amount: parseInt(i.amt_paid_sat),
- preimage: i.r_preimage.toString("hex"),
- pr: i.payment_request.toString("hex"),
- createdAt: new Date(i.settle_date * 1000)
+ amount: parseInt(i.received),
+ preimage: i.secret,
+ pr: i.request.toString("hex"),
+ createdAt: new Date(i.created_at)
}));
const twoDaysAgo = new Date(new Date().setDate(new Date().getDate() - 2));
diff --git a/routes/lightning/invoice.js b/routes/lightning/invoice.js
index 3ef0e109..94aac768 100644
--- a/routes/lightning/invoice.js
+++ b/routes/lightning/invoice.js
@@ -8,7 +8,6 @@ export default async (req, res) => {
if (!tip) tip = 0;
let value = amount + tip;
- console.log("getting invoice");
try {
if (config.lna.clightning) {
if (!memo) memo = "coinos";
@@ -20,13 +19,11 @@ export default async (req, res) => {
);
res.send({ text: invoice.bolt11 });
} else {
- console.log("creating invoice");
const invoice = await createInvoice({
lnd,
tokens: value,
description: memo
});
- console.log("created");
res.send({ text: invoice.request });
}
} catch (e) {
diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js
index 8141e5d3..3ecc4ce9 100644
--- a/routes/lightning/receive.js
+++ b/routes/lightning/receive.js
@@ -12,7 +12,7 @@ import { l, err, warn } from "$lib/logging";
const handlePayment = async msg => {
try {
- l("incoming lightning payment", msg.tokens, msg.request.substr(0,20));
+ l("incoming lightning payment", msg.received, msg.request.substr(0,20));
if (!msg.secret) return;
let account, total, user;
@@ -28,7 +28,7 @@ const handlePayment = async msg => {
await db.transaction(async transaction => {
const { text: hash, currency, memo, rate, tip, user_id } = invoice;
- const amount = parseInt(msg.tokens) - tip;
+ const amount = parseInt(msg.received) - tip;
if (amount < 0) throw new Error("amount out of range");
account = await db.Account.findOne({