aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/binance.js3
-rw-r--r--lib/ln.js3
-rw-r--r--lib/send.js18
-rw-r--r--lib/sync.js131
-rw-r--r--lib/whitelist.js5
5 files changed, 91 insertions, 69 deletions
diff --git a/lib/binance.js b/lib/binance.js
index af8d0b15..5eb2f286 100644
--- a/lib/binance.js
+++ b/lib/binance.js
@@ -27,7 +27,8 @@ export default () => {
};
binance.onerror = async function(error) {
- err("binance socket error", error);
+ console.log(error)
+ err("binance socket error", error.message);
};
return binance;
diff --git a/lib/ln.js b/lib/ln.js
index 8e96efea..7a1b1822 100644
--- a/lib/ln.js
+++ b/lib/ln.js
@@ -2,7 +2,8 @@ import config from "$config";
let ln;
if (config.lna.clightning) {
- ln = (await import("clightning-client"))(config.lna.dir);
+ let { LightningClient } = (await import("clightning-client")).default;
+ ln = new LightningClient(config.lna.dir);
} else {
ln = await import("./lnd");
}
diff --git a/lib/send.js b/lib/send.js
index 77d954f6..9d70b34e 100644
--- a/lib/send.js
+++ b/lib/send.js
@@ -9,6 +9,7 @@ import {
conversionFeeReceiver
} from "../routes/lightning/conversionFee";
import lnd from "$lib/lnd";
+import ln from "$lib/ln";
import { payViaPaymentRequest } from "lightning";
import { l, warn, err } from "$lib/logging";
@@ -89,7 +90,9 @@ export default async (amount, memo, hash, user) => {
let tokens;
if (!payreq.satoshis) tokens = amount;
- let m = await payViaPaymentRequest({
+ let m;
+ if (config.lnd) {
+ m = await payViaPaymentRequest({
lnd,
request: hash,
max_fee: Math.min(10000, account.balance)
@@ -97,8 +100,19 @@ export default async (amount, memo, hash, user) => {
if (!m) throw new Error(`lightning payment failed ${amount} ${hash}`);
if (m.payment_error) throw new Error(m.payment_error);
-
({ fee, secret: preimage, tokens: total } = m);
+ } else {
+ m = await ln.pay(hash, tokens ? `${tokens}sats` : undefined);
+ let sent;
+ ({
+ msatoshi: total,
+ msatoshi_sent: sent,
+ payment_preimage: preimage
+ } = m);
+
+ fee = parseInt((sent - total) / 1000);
+ total = parseInt(total / 1000);
+ }
preimage = preimage.toString("hex");
diff --git a/lib/sync.js b/lib/sync.js
index 467ce107..95abb99d 100644
--- a/lib/sync.js
+++ b/lib/sync.js
@@ -75,82 +75,85 @@ const sync = async () => {
]
});
- let { invoices } = await getInvoices({ lnd, limit: 1000 });
+ let missed, invoices;
+ if (config.lnd) {
+ ({ invoices } = await getInvoices({ lnd, limit: 1000 }));
- let recent = invoices
- .filter(
- i =>
- i.is_confirmed &&
- differenceInDays(new Date(), new Date(i.created_at)) < 2
- )
- .map(i => ({
- amount: parseInt(i.received),
- preimage: i.secret,
- pr: i.request,
- createdAt: new Date(i.created_at)
- }));
-
- const twoDaysAgo = new Date(new Date().setDate(new Date().getDate() - 2));
- let settled = (
- await db.Payment.findAll({
- where: { network: "lightning", createdAt: { [Op.gt]: twoDaysAgo } },
- attributes: ["preimage"]
- })
- ).map(p => p.preimage);
+ let recent = invoices
+ .filter(
+ i =>
+ i.is_confirmed &&
+ differenceInDays(new Date(), new Date(i.created_at)) < 2
+ )
+ .map(i => ({
+ amount: parseInt(i.received),
+ preimage: i.secret,
+ pr: i.request,
+ createdAt: new Date(i.created_at)
+ }));
- let missed = recent.filter(i => !settled.includes(i.preimage));
- for (let i = 0; i < missed.length; i++) {
- let { amount, preimage, pr: text, createdAt } = missed[i];
- if (!text || !text.length) continue;
+ const twoDaysAgo = new Date(new Date().setDate(new Date().getDate() - 2));
+ let settled = (
+ await db.Payment.findAll({
+ where: { network: "lightning", createdAt: { [Op.gt]: twoDaysAgo } },
+ attributes: ["preimage"]
+ })
+ ).map(p => p.preimage);
- try {
- let invoice = await db.Invoice.findOne({
- where: { text },
- include: {
- model: db.User,
- as: "user"
- }
- });
+ missed = recent.filter(i => !settled.includes(i.preimage));
+ for (let i = 0; i < missed.length; i++) {
+ let { amount, preimage, pr: text, createdAt } = missed[i];
+ if (!text || !text.length) continue;
- if (invoice && invoice.user_id) {
- let account = await db.Account.findOne({
- where: {
- user_id: invoice.user_id,
- asset: config.liquid.btcasset,
- pubkey: null
+ try {
+ let invoice = await db.Invoice.findOne({
+ where: { text },
+ include: {
+ model: db.User,
+ as: "user"
}
});
- if (account) {
- let payment = await db.Payment.create({
- account_id: account.id,
- user_id: invoice.user_id,
- hash: text,
- amount,
- currency: invoice.currency,
- preimage,
- rate: invoice.rate,
- received: true,
- confirmed: true,
- network: "lightning",
- tip: invoice.tip,
- invoice_id: invoice.id,
- createdAt,
- updatedAt: createdAt
+ if (invoice && invoice.user_id) {
+ let account = await db.Account.findOne({
+ where: {
+ user_id: invoice.user_id,
+ asset: config.liquid.btcasset,
+ pubkey: null
+ }
});
- await account.increment({ balance: amount });
+ if (account) {
+ let payment = await db.Payment.create({
+ account_id: account.id,
+ user_id: invoice.user_id,
+ hash: text,
+ amount,
+ currency: invoice.currency,
+ preimage,
+ rate: invoice.rate,
+ received: true,
+ confirmed: true,
+ network: "lightning",
+ tip: invoice.tip,
+ invoice_id: invoice.id,
+ createdAt,
+ updatedAt: createdAt
+ });
+
+ await account.increment({ balance: amount });
- l("lightning missing from account", account.id, amount);
+ l("lightning missing from account", account.id, amount);
+ }
}
+ } catch (e) {
+ err(
+ "problem syncing lightning payment",
+ JSON.stringify(missed[i]),
+ e.message,
+ e.stack
+ );
}
- } catch (e) {
- err(
- "problem syncing lightning payment",
- JSON.stringify(missed[i]),
- e.message,
- e.stack
- );
}
}
diff --git a/lib/whitelist.js b/lib/whitelist.js
index a5c7a15f..d3e361d1 100644
--- a/lib/whitelist.js
+++ b/lib/whitelist.js
@@ -16,5 +16,8 @@ export default [
"keys",
"index",
"verified",
- "email"
+ "email",
+ "profile",
+ "banner",
+ "theme"
];