aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--db/index.js1
-rw-r--r--lib/redis.js4
-rw-r--r--lib/sendInternal.js4
-rw-r--r--lib/sync.js128
-rw-r--r--lib/utils.js8
-rw-r--r--routes/invoices.js14
-rw-r--r--routes/locations.js12
-rw-r--r--routes/payments.js2
8 files changed, 87 insertions, 86 deletions
diff --git a/db/index.js b/db/index.js
index 0437ece6..e88c8432 100644
--- a/db/index.js
+++ b/db/index.js
@@ -152,7 +152,6 @@ Invoice.hasOne(Request, {
foreignKey: "invoice_id"
});
-
db.Order = Order;
export default db;
diff --git a/lib/redis.js b/lib/redis.js
index 98a71856..3aed1bd0 100644
--- a/lib/redis.js
+++ b/lib/redis.js
@@ -1,10 +1,10 @@
import { createClient } from "redis";
const redis = createClient({
- url: "redis://redis",
+ url: "redis://redis"
});
-redis.on("error", (err) => console.log("redis error", err));
+redis.on("error", err => console.log("redis error", err));
await redis.connect();
diff --git a/lib/sendInternal.js b/lib/sendInternal.js
index 7204f769..b49a6c64 100644
--- a/lib/sendInternal.js
+++ b/lib/sendInternal.js
@@ -149,7 +149,7 @@ export default async (
if (tip) {
params.tip = tip;
params.amount -= tip;
- }
+ }
await invoice.increment({ received: amount }, { transaction });
await invoice.reload({ transaction });
@@ -200,7 +200,7 @@ export default async (
hash: `#${v4().substr(0, 6)} ${
username ? `Payment to ${username}` : "Internal Transfer"
}`,
- network: "COINOS",
+ network: "COINOS"
};
if (!username) {
diff --git a/lib/sync.js b/lib/sync.js
index 42291a94..97207752 100644
--- a/lib/sync.js
+++ b/lib/sync.js
@@ -16,7 +16,7 @@ import lq from "./liquid";
const init = async () => {
try {
- read(fs.createReadStream("exceptions"), (data) =>
+ read(fs.createReadStream("exceptions"), data =>
store.exceptions.push(data)
);
} catch (e) {
@@ -30,13 +30,13 @@ const init = async () => {
await db.Invoice.findAll({
where: {
createdAt: {
- [Op.gt]: thirtyDays,
- },
+ [Op.gt]: thirtyDays
+ }
},
include: {
model: db.User,
- as: "user",
- },
+ as: "user"
+ }
})
).map(({ address, user, unconfidential }) => {
if (address && user) store.addresses[address] = user.username;
@@ -49,9 +49,9 @@ const init = async () => {
store.payments = (
await db.Payment.findAll({
- attributes: ["hash"],
+ attributes: ["hash"]
})
- ).map((p) => p.hash);
+ ).map(p => p.hash);
};
init();
@@ -66,13 +66,13 @@ const sync = async () => {
include: [
{
model: db.Account,
- as: "account",
+ as: "account"
},
{
model: db.User,
- as: "user",
- },
- ],
+ as: "user"
+ }
+ ]
});
let missed, invoices, recent;
@@ -81,49 +81,49 @@ const sync = async () => {
recent = invoices
.filter(
- (i) =>
+ i =>
i.is_confirmed &&
differenceInDays(new Date(), new Date(i.created_at)) < 2
)
- .map((i) => ({
+ .map(i => ({
amount: parseInt(i.received),
preimage: i.secret,
pr: i.request,
- createdAt: new Date(i.created_at),
+ createdAt: new Date(i.created_at)
}));
} else {
({ invoices } = await ln.listinvoices());
recent = invoices
.filter(
- (i) =>
+ i =>
i.status === "paid" &&
Math.round(Date.now() / 1000) - i.paid_at < 60 * 60 * 48
)
- .map((i) => ({
+ .map(i => ({
amount: parseInt(Math.round(i.msatoshi_received / 1000)),
preimage: i.payment_preimage,
pr: i.bolt11,
- createdAt: new Date(i.paid_at * 1000),
+ createdAt: new Date(i.paid_at * 1000)
}));
}
- await db.transaction(async (transaction) => {
+ await db.transaction(async transaction => {
const twoDaysAgo = new Date(new Date().setDate(new Date().getDate() - 2));
let settled = (
await db.Payment.findAll(
{
where: {
network: "lightning",
- createdAt: { [Op.gt]: twoDaysAgo },
+ createdAt: { [Op.gt]: twoDaysAgo }
},
- attributes: ["preimage"],
+ attributes: ["preimage"]
},
transaction
)
- ).map((p) => p.preimage);
+ ).map(p => p.preimage);
- missed = recent.filter((i) => !settled.includes(i.preimage));
+ 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;
@@ -133,9 +133,9 @@ const sync = async () => {
where: { text },
include: {
model: db.User,
- as: "user",
+ as: "user"
},
- transaction,
+ transaction
});
if (invoice && invoice.user_id) {
@@ -143,9 +143,9 @@ const sync = async () => {
where: {
user_id: invoice.user_id,
asset: config.liquid.btcasset,
- pubkey: null,
+ pubkey: null
},
- transaction,
+ transaction
});
if (account) {
@@ -163,7 +163,7 @@ const sync = async () => {
tip: invoice.tip,
invoice_id: invoice.id,
createdAt,
- updatedAt: createdAt,
+ updatedAt: createdAt
});
await invoice.increment({ received: amount }, { transaction });
@@ -181,48 +181,48 @@ const sync = async () => {
const unconfirmed = await db.Payment.findAll({
where: {
- confirmed: 0,
+ confirmed: 0
},
include: [
{
model: db.Account,
- as: "account",
+ as: "account"
},
{
model: db.Invoice,
- as: "invoice",
+ as: "invoice"
},
{
model: db.User,
- as: "user",
- },
- ],
+ as: "user"
+ }
+ ]
});
- let hashes = unconfirmed.map((p) => p.hash);
+ let hashes = unconfirmed.map(p => p.hash);
const transactions = [
...(await bc.listTransactions("*", 500)),
- ...(await lq.listTransactions("*", 500)),
+ ...(await lq.listTransactions("*", 500))
].filter(
- (tx) =>
+ tx =>
["send", "receive"].includes(tx.category) &&
new Date(tx.time * 1000) > twoWeeksAgo
);
missed = transactions.filter(
- (tx) =>
+ tx =>
tx.category === "receive" &&
tx.confirmations > 2 &&
hashes.includes(tx.txid)
);
for (let i = 0; i < missed.length; i++) {
- let p = unconfirmed.find((p) => p.hash === missed[i].txid);
+ let p = unconfirmed.find(p => p.hash === missed[i].txid);
p.confirmed = 1;
try {
- await db.transaction(async (transaction) => {
+ await db.transaction(async transaction => {
l("confirming payment", p.id, p.user_id, p.hash, p.address);
await p.save({ transaction });
@@ -242,11 +242,11 @@ const sync = async () => {
store.unaccounted = [];
- transactions.map((tx) => {
+ transactions.map(tx => {
if (
- !payments.find((p) => p.hash === tx.txid) &&
+ !payments.find(p => p.hash === tx.txid) &&
!store.exceptions.includes(tx.txid) &&
- !store.unaccounted.find((a) => a.txid === tx.txid) &&
+ !store.unaccounted.find(a => a.txid === tx.txid) &&
new Date(tx.blocktime * 1000) >= twoWeeksAgo
) {
store.unaccounted.push(tx);
@@ -256,34 +256,34 @@ const sync = async () => {
if (store.unaccounted.length)
warn(
"wallet transactions missing from database",
- store.unaccounted.map((tx) => tx.txid)
+ store.unaccounted.map(tx => tx.txid)
);
let receipts = store.unaccounted
.filter(
- (tx) =>
+ tx =>
tx.category === "receive" &&
(!tx.asset || tx.asset === config.liquid.btcasset)
)
- .map((tx) => tx.address);
+ .map(tx => tx.address);
invoices = await db.Invoice.findAll({
where: {
[Op.or]: {
address: receipts,
- unconfidential: receipts,
- },
+ unconfidential: receipts
+ }
},
include: [
{
model: db.Account,
- as: "account",
+ as: "account"
},
{
model: db.User,
- as: "user",
- },
- ],
+ as: "user"
+ }
+ ]
});
for (let i = 0; i < invoices.length; i++) {
@@ -298,13 +298,13 @@ const sync = async () => {
rate,
tip,
user,
- user_id,
+ user_id
} = invoices[i];
l("unaccounted", address);
let pending = store.unaccounted.filter(
- (tx) => tx.address === address || tx.address === unconfidential
+ tx => tx.address === address || tx.address === unconfidential
);
for (let i = 0; i < pending.length; i++) {
@@ -313,7 +313,7 @@ const sync = async () => {
amount = toSats(amount);
try {
- await db.transaction(async (transaction) => {
+ await db.transaction(async transaction => {
l("found pending transaction", user.username, amount, hash);
store.payments.push(hash);
let p = await db.Payment.create(
@@ -329,7 +329,7 @@ const sync = async () => {
rate,
received: true,
tip,
- user_id,
+ user_id
},
{ transaction }
);
@@ -357,8 +357,8 @@ setTimeout(sync, 5000);
app.get("/conversions", async (req, res) => {
const transactions = [
...(await bc.listTransactions("*", 500)),
- ...(await lq.listTransactions("*", 500)),
- ].filter((tx) => ["receive"].includes(tx.category));
+ ...(await lq.listTransactions("*", 500))
+ ].filter(tx => ["receive"].includes(tx.category));
const { addr } = req.query;
const { invoices } = require("./invoices");
@@ -366,19 +366,19 @@ app.get("/conversions", async (req, res) => {
let conversions = persist("data/conversions.json");
const payments = (
await db.Payment.findAll({
- attributes: ["hash"],
+ attributes: ["hash"]
})
- ).map((p) => p.hash);
+ ).map(p => p.hash);
res.send(
Object.keys(conversions)
- .filter((c) => conversions[c].address === addr)
- .filter((c) => {
+ .filter(c => conversions[c].address === addr)
+ .filter(c => {
return (
invoices.find(
- (i) => i.payment_request === c && i.state === "SETTLED"
- ) || transactions.find((tx) => tx.txid === c)
+ i => i.payment_request === c && i.state === "SETTLED"
+ ) || transactions.find(tx => tx.txid === c)
);
})
- .filter((c) => !payments.includes(c))
+ .filter(c => !payments.includes(c))
);
});
diff --git a/lib/utils.js b/lib/utils.js
index c9670339..45e50243 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -166,8 +166,8 @@ export const derivePayRequest = async ({ amount, memo, tip }) => {
if (!tip) tip = 0;
let value = amount + tip;
- if (!memo) memo = "coinos";
- return (
- await ln.invoice(value ? `${value}sat` : "any", new Date(), memo, 360)
- ).bolt11;
+ if (!memo) memo = "coinos";
+ return (
+ await ln.invoice(value ? `${value}sat` : "any", new Date(), memo, 360)
+ ).bolt11;
};
diff --git a/routes/invoices.js b/routes/invoices.js
index 7fa82afb..d689775f 100644
--- a/routes/invoices.js
+++ b/routes/invoices.js
@@ -183,13 +183,13 @@ app.post("/invoice", optionalAuth, async (req, res, next) => {
if (!existing)
emit(request.requester.username, "invoice", {
- amount: invoice.amount,
- currency: invoice.currency,
- rate: invoice.rate,
- request_id,
- uuid: invoice.uuid,
- user: { username: user.username, profile: user.profile }
- });
+ amount: invoice.amount,
+ currency: invoice.currency,
+ rate: invoice.rate,
+ request_id,
+ uuid: invoice.uuid,
+ user: { username: user.username, profile: user.profile }
+ });
}
}
diff --git a/routes/locations.js b/routes/locations.js
index 3e0fee4c..63bfe1a1 100644
--- a/routes/locations.js
+++ b/routes/locations.js
@@ -8,12 +8,14 @@ app.get("/locations", async (req, res) => {
});
let getLocations = async () => {
- let { data } = await axios.get('https://api.btcmap.org/v2/elements?updated_since=2022-09-19');
- locations = data.filter(
- (l) => l['osm_json'].tags && l['osm_json'].tags['payment:coinos'] === 'yes'
- );
+ let { data } = await axios.get(
+ "https://api.btcmap.org/v2/elements?updated_since=2022-09-19"
+ );
+ locations = data.filter(
+ l => l["osm_json"].tags && l["osm_json"].tags["payment:coinos"] === "yes"
+ );
setTimeout(getLocations, 60000);
-}
+};
getLocations();
diff --git a/routes/payments.js b/routes/payments.js
index 96791bb3..da55f1ec 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -154,7 +154,7 @@ app.get("/payment/:redeemcode", async (req, res) => {
});
payment = payment.get({ plain: true });
- payment.redeemer = payment['with'];
+ payment.redeemer = payment["with"];
if (!payment) fail("invalid code");