aboutsummaryrefslogtreecommitdiffstats
path: root/routes/lightning
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-01-13 23:50:30 -0800
committerAdam Soltys <[email protected]>2023-01-13 23:50:30 -0800
commit6bafea9bffe24d2227d269812a73a9a513d92ddf (patch)
tree6dd463ffa410f4b7eebc870b24db305785414aa0 /routes/lightning
parent8a114c50efaac41767042766f05390aa906da157 (diff)
downloadcoinos-server-6bafea9bffe24d2227d269812a73a9a513d92ddf.tar.gz
coinos-server-6bafea9bffe24d2227d269812a73a9a513d92ddf.zip
internal payments
Diffstat (limited to 'routes/lightning')
-rw-r--r--routes/lightning/receive.js10
1 files changed, 9 insertions, 1 deletions
diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js
index a37dc716..ffb0ad95 100644
--- a/routes/lightning/receive.js
+++ b/routes/lightning/receive.js
@@ -1,3 +1,4 @@
+import { v4 } from "uuid";
import store from "$lib/store";
import { emit } from "$lib/sockets";
import config from "$config";
@@ -35,7 +36,9 @@ let handle = async () => {
let amount = parseInt(received) - tip;
if (amount < 0) throw new Error("amount out of range");
+ let id = v4();
let payment = {
+ id,
user_id,
hash,
memo,
@@ -44,7 +47,8 @@ let handle = async () => {
secret,
rate,
tip,
- invoice_id: invoice.id
+ invoice_id: invoice.id,
+ created_at: Date.now()
};
total = amount + tip;
@@ -64,6 +68,10 @@ let handle = async () => {
await t();
payment.invoice = invoice;
+
+ await s(`payment:${id}`, payment);
+ await rd.lPush(`${user.id}:payments`, id);
+
callWebhook(invoice, payment);
emit(user.username, "payment", payment);