aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-02-03 09:58:47 -0800
committerAdam Soltys <[email protected]>2023-02-03 09:58:47 -0800
commit17a2a698de2a522f05d9ec813411b5a01b95234d (patch)
treef23a88b4dbac920cba169e54f6160aa4c1bab07b /lib
parent549590ceb8bdd2954d2b96c14d530063104b352f (diff)
downloadcoinos-server-17a2a698de2a522f05d9ec813411b5a01b95234d.tar.gz
coinos-server-17a2a698de2a522f05d9ec813411b5a01b95234d.zip
contacts
Diffstat (limited to 'lib')
-rw-r--r--lib/db.js2
-rw-r--r--lib/lightning.js9
-rw-r--r--lib/nostr.js1
-rw-r--r--lib/payments.js5
-rw-r--r--lib/register.js3
-rw-r--r--lib/upload.js2
6 files changed, 11 insertions, 11 deletions
diff --git a/lib/db.js b/lib/db.js
index 516db236..86f8082e 100644
--- a/lib/db.js
+++ b/lib/db.js
@@ -1,4 +1,4 @@
-import config from "$config"
+import config from "$config";
import { sleep } from "$lib/utils";
import { createClient } from "redis";
diff --git a/lib/lightning.js b/lib/lightning.js
index c8daf8c8..2915b7c7 100644
--- a/lib/lightning.js
+++ b/lib/lightning.js
@@ -8,6 +8,7 @@ import { g, s, t, db } from "$lib/db";
import { credit, types } from "$lib/payments";
export async function listenForLightning() {
+ let event = await ln.waitanyinvoice(await g("pay_index"));
let {
payment_hash: hash,
bolt11,
@@ -15,7 +16,7 @@ export async function listenForLightning() {
status,
msatoshi_received,
payment_preimage: preimage
- } = await ln.waitanyinvoice(await g("pay_index"));
+ } = event;
await s("pay_index", pay_index);
setTimeout(listenForLightning);
@@ -30,11 +31,7 @@ export async function listenForLightning() {
let invoice = await g(`invoice:${hash}`);
if (!invoice) return warn("received lightning with no invoice", bolt11);
- let { currency, memo, rate, tip, uid } = invoice;
- let amount = parseInt(received) - tip;
- if (amount < 0) throw new Error("amount out of range");
-
- await credit(hash, amount, memo, preimage, types.lightning);
+ await credit(hash, received, invoice.memo, preimage, types.lightning);
} catch (e) {
console.log(e);
err("problem receiving lightning payment", e.message);
diff --git a/lib/nostr.js b/lib/nostr.js
index 23ea937b..065fafb0 100644
--- a/lib/nostr.js
+++ b/lib/nostr.js
@@ -15,6 +15,7 @@ export let fillPool = () => {
});
pool.on("event", async (relay, sub, ev) => {
+ if (!coinos) return;
if (timeouts[sub]) timeouts[sub].extend(ev);
try {
let content;
diff --git a/lib/payments.js b/lib/payments.js
index 47cb11f4..6fd595d4 100644
--- a/lib/payments.js
+++ b/lib/payments.js
@@ -36,8 +36,8 @@ export let debit = async (
if (!amount || amount < 0) fail("Amount must be greater than zero");
let ourfee = [types.bitcoin, types.lightning].includes(type)
- ? 0
- : Math.round(amount * config.fee);
+ ? Math.round(amount * config.fee)
+ : 0;
await t(`balance:${uid}`, async (balance, db) => {
await t(`credit:${type}:${uid}`, async (credit, db) => {
@@ -85,6 +85,7 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => {
amount = parseInt(amount);
let invoice = await g(`invoice:${hash}`);
if (!invoice) return;
+ if (!memo) ({ memo } = invoice);
let user = await g(`user:${invoice.uid}`);
diff --git a/lib/register.js b/lib/register.js
index a3ebfc86..a222a416 100644
--- a/lib/register.js
+++ b/lib/register.js
@@ -8,7 +8,7 @@ import { s, g } from "$lib/db";
import { got } from "got";
export default async (user, ip, requireChallenge) => {
- let { password, username } = user;
+ let { password, pubkey, username } = user;
l("registering", username);
if (!username) throw new Error("Username required");
@@ -54,6 +54,7 @@ export default async (user, ip, requireChallenge) => {
await s(`user:${id}`, user);
await s(`user:${user.username}`, id);
+ await s(`user:${pubkey}`, id);
l("new user", user.username);
return user;
diff --git a/lib/upload.js b/lib/upload.js
index 2f8180a0..954e8d4d 100644
--- a/lib/upload.js
+++ b/lib/upload.js
@@ -12,7 +12,7 @@ export default async (req, res) => {
params: { type },
user
} = req;
- console.log("TYPE", type)
+ console.log("TYPE", type);
if (!["banner", "profile"].includes(type)) throw new Error("invalid upload");
let data = await req.file();