aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-04-02 03:19:06 -0400
committerAdam Soltys <[email protected]>2022-04-02 03:19:06 -0400
commitd72de475b6621fb6ef31c03c2cf4d3ca1e82f5f2 (patch)
tree7a474e4a28e814c51282ab1e88b3314234736b70
parent2e585488fd58e90264da5a5e5c25e1e397b56145 (diff)
downloadcoinos-server-d72de475b6621fb6ef31c03c2cf4d3ca1e82f5f2.tar.gz
coinos-server-d72de475b6621fb6ef31c03c2cf4d3ca1e82f5f2.zip
find missed payments
-rw-r--r--lib/sync.js68
1 files changed, 39 insertions, 29 deletions
diff --git a/lib/sync.js b/lib/sync.js
index 6c048388..d6adba2e 100644
--- a/lib/sync.js
+++ b/lib/sync.js
@@ -17,7 +17,7 @@ const init = async () => {
await db.Invoice.findAll({
where: {
createdAt: {
- [Op.gt]: thirtyDays
+ [Op.gt]: thirtyDays
}
},
include: {
@@ -150,8 +150,8 @@ const sync = async () => {
let hashes = unconfirmed.map(p => p.hash);
const transactions = [
- ...(await bc.listTransactions("*", 50)),
- ...(await lq.listTransactions("*", 50))
+ ...(await bc.listTransactions("*", 500)),
+ ...(await lq.listTransactions("*", 500))
].filter(tx => ["send", "receive"].includes(tx.category));
missed = transactions.filter(
@@ -199,7 +199,9 @@ const sync = async () => {
let receipts = unaccounted
.filter(
- tx => tx.category === "receive" && tx.asset === config.liquid.btcasset
+ tx =>
+ tx.category === "receive" &&
+ (!tx.asset || tx.asset === config.liquid.btcasset)
)
.map(tx => tx.address);
@@ -237,37 +239,45 @@ const sync = async () => {
user_id
} = invoices[i];
- let { amount, txid: hash } = unaccounted.find(
+ l.info("unaccounted", address);
+
+ let pending = unaccounted.filter(
tx => tx.address === address || tx.address === unconfidential
);
- amount = toSats(amount);
+ for (let i = 0; i < pending.length; i++) {
+ let { amount, txid: hash } = pending[i];
- await db.transaction(async transaction => {
- payments.push(hash);
- let p = await db.Payment.create(
- {
- account_id,
- address: address || unconfidential,
- amount,
- confirmed: false,
- currency,
- hash,
- invoice_id,
- network,
- rate,
- received: true,
- tip,
- user_id
- },
- { transaction }
- );
+ amount = toSats(amount);
- await account.increment({ pending: amount }, { transaction });
+ await db.transaction(async transaction => {
+ payments.push(hash);
+ let p = await db.Payment.create(
+ {
+ account_id,
+ address: address || unconfidential,
+ amount,
+ confirmed: false,
+ currency,
+ hash,
+ invoice_id,
+ network,
+ rate,
+ received: true,
+ tip,
+ user_id
+ },
+ { transaction }
+ );
- emit(user.username, "account", account);
- emit(user.username, "payment", p);
- });
+ await account.increment({ pending: amount }, { transaction });
+
+ l.info("found pending balance", user.username, amount);
+
+ emit(user.username, "account", account);
+ emit(user.username, "payment", p);
+ });
+ }
}
} catch (e) {
l.error("sync check failed", e.message, e.stack);