diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sync.js | 68 |
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); |
