aboutsummaryrefslogtreecommitdiffstats
path: root/routes/payments.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2021-08-04 07:00:20 -0700
committerAdam Soltys <[email protected]>2021-08-04 08:16:43 -0700
commitea2c9ed23c2b80f4a6200ee19fb4a6c77c3ccb95 (patch)
tree1bb8ebcdf7b5bdbdc92ee536ef5517e711e9388c /routes/payments.js
parentcfa93d65f113b4eed50cc88be76eeefa04a900eb (diff)
downloadcoinos-server-ea2c9ed23c2b80f4a6200ee19fb4a6c77c3ccb95.tar.gz
coinos-server-ea2c9ed23c2b80f4a6200ee19fb4a6c77c3ccb95.zip
config update, lnd support
Diffstat (limited to 'routes/payments.js')
-rw-r--r--routes/payments.js69
1 files changed, 42 insertions, 27 deletions
diff --git a/routes/payments.js b/routes/payments.js
index a171b92f..70b711da 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -2,6 +2,7 @@ const BitcoinCore = require("@asoltys/bitcoin-core");
const { Op } = require("sequelize");
const { join } = require("path");
const fs = require("fs");
+const lnd = require("../lib/lnd");
const read = require("../lib/read");
ah(async () => {
@@ -12,34 +13,34 @@ ah(async () => {
const exceptions = [];
try {
- read(fs.createReadStream("exceptions"), (data) => exceptions.push(data));
+ read(fs.createReadStream("exceptions"), data => exceptions.push(data));
} catch (e) {
l.warn("couldn't read exceptions file", e.message);
}
try {
- (
- await db.Invoice.findAll({
- include: {
- model: db.User,
- as: "user",
- },
- })
- ).map(({ address, user, unconfidential }) => {
- if (address && user) addresses[address] = user.username;
- if (unconfidential && user) addresses[unconfidential] = user.username;
- });
- } catch(e) {
+ (
+ await db.Invoice.findAll({
+ include: {
+ model: db.User,
+ as: "user"
+ }
+ })
+ ).map(({ address, user, unconfidential }) => {
+ if (address && user) addresses[address] = user.username;
+ if (unconfidential && user) addresses[unconfidential] = user.username;
+ });
+ } catch (e) {
console.log(e);
- }
+ }
try {
const accounts = await db.Account.findAll({
where: { pubkey: { [Op.ne]: null } },
include: {
model: db.User,
- as: "user",
- },
+ as: "user"
+ }
});
accounts.map(({ address, user: { username } }) => {
@@ -51,36 +52,35 @@ ah(async () => {
payments = (
await db.Payment.findAll({
- attributes: ["hash"],
+ attributes: ["hash"]
})
- ).map((p) => p.hash);
-
+ ).map(p => p.hash);
setInterval(async () => {
const unconfirmed = (
await db.Payment.findAll({
where: {
- confirmed: 0,
- },
+ confirmed: 0
+ }
})
- ).map((p) => p.hash);
+ ).map(p => p.hash);
const transactions = await bc.listTransactions("*", 1000);
transactions
.filter(
- (tx) =>
+ tx =>
tx.category === "receive" &&
tx.confirmations > 0 &&
unconfirmed.includes(tx.txid)
)
- .map((tx) => {
+ .map(tx => {
l.warn("tx unconfirmed in db", tx.txid, tx.address);
});
const unaccounted = [];
- transactions.map((tx) => {
+ transactions.map(tx => {
if (!payments.includes(tx.txid) && !exceptions.includes(tx.txid)) {
unaccounted.push(tx.txid);
}
@@ -96,7 +96,22 @@ ah(async () => {
if (config.lna.clightning) {
lna = require("clightning-client")(config.lna.dir);
} else {
- lna = lnd(config.lna);
+ lna = lnd.default;
+ lnp = [
+ "addInvoice",
+ "channelBalance",
+ "connectPeer",
+ "decodePayReq",
+ "getInfo",
+ "listInvoices",
+ "listPayments",
+ "sendPaymentSync",
+ "walletBalance"
+ ].reduce(
+ (a, b) =>
+ (a[b] = args => new Promise(r => lna[b](args, (e, v) => r(v)))) && a,
+ {}
+ );
}
app.post("/lightning/channel", require("./lightning/channel"));
@@ -152,7 +167,7 @@ ah(async () => {
const parts = hdkeypath.split("/");
app.set("lqAddressIndex", parts[parts.length - 1].slice(0, -1));
} catch (e) {
- console.error("Problem getting liquid address", e);
+ l.warn("Problem getting liquid address index", e.message);
}
}, 50);
}