diff options
| author | Derrick Schwabe <[email protected]> | 2022-05-01 16:22:16 -0600 |
|---|---|---|
| committer | Derrick Schwabe <[email protected]> | 2022-05-01 16:22:16 -0600 |
| commit | 49561e914cc5d3cb21262cac0e96e5c295d8049c (patch) | |
| tree | ba6816433c379b319763928e46b7da4b25ca04e1 | |
| parent | b7a3b0bc84a18265a5a90aba606c15094ca76c57 (diff) | |
| parent | c80408c08ff2a8ca31df5ef3c7c9df13c9f714e4 (diff) | |
| download | coinos-server-49561e914cc5d3cb21262cac0e96e5c295d8049c.tar.gz coinos-server-49561e914cc5d3cb21262cac0e96e5c295d8049c.zip | |
Merge remote-tracking branch 'origin/master' into stageUpdate2
| -rw-r--r-- | lib/sync.js | 15 | ||||
| -rw-r--r-- | routes/bitcoin/receive.js | 11 | ||||
| -rw-r--r-- | routes/bitcoin/send.js | 3 | ||||
| -rw-r--r-- | routes/lightning/receive.js | 3 |
4 files changed, 14 insertions, 18 deletions
diff --git a/lib/sync.js b/lib/sync.js index d6adba2e..fedb6798 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -116,7 +116,7 @@ const sync = async () => { preimage, rate: invoice.rate, received: true, - confirmed: true, + confirmed: false, network: "lightning", tip: invoice.tip, invoice_id: invoice.id, @@ -124,9 +124,9 @@ const sync = async () => { updatedAt: createdAt }); - await account.increment({ balance: amount }); + // await account.increment({ balance: amount }); - l.info("rectified account", account.id, amount); + l.info("lightning missing from account", account.id, amount); } } } @@ -185,7 +185,9 @@ const sync = async () => { transactions.map(tx => { if ( !payments.find(p => p.hash === tx.txid) && - !exceptions.includes(tx.txid) + !exceptions.includes(tx.txid) && + !unaccounted.find(a => a.txid === tx.txid) && + new Date(tx.blocktime * 1000) >= twoWeeksAgo ) { unaccounted.push(tx); } @@ -251,6 +253,8 @@ const sync = async () => { amount = toSats(amount); await db.transaction(async transaction => { + l.info("found pending balance", user.username, amount); + /* payments.push(hash); let p = await db.Payment.create( { @@ -272,10 +276,9 @@ const sync = async () => { await account.increment({ pending: amount }, { transaction }); - l.info("found pending balance", user.username, amount); - emit(user.username, "account", account); emit(user.username, "payment", p); + */ }); } } diff --git a/routes/bitcoin/receive.js b/routes/bitcoin/receive.js index e74f9394..5d8e21e7 100644 --- a/routes/bitcoin/receive.js +++ b/routes/bitcoin/receive.js @@ -68,15 +68,6 @@ zmqRawTx.on("message", async (topic, message, sequence) => { if (!invoice) return; - let payment = await db.Payment.findOne({ - where: { - invoice_id: invoice.id - }, - order: [["id", "DESC"]], - }); - - if (payment) return; - const currency = invoice ? invoice.currency : user.currency; const rate = invoice ? invoice.rate : app.get("rates")[user.currency]; const tip = invoice ? invoice.tip : 0; @@ -113,7 +104,7 @@ zmqRawTx.on("message", async (topic, message, sequence) => { } let fee = totalInputs - totalOutputs; - payment = await db.Payment.create({ + let payment = await db.Payment.create({ account_id: account.id, user_id: user.id, hash, diff --git a/routes/bitcoin/send.js b/routes/bitcoin/send.js index fe2b2862..9d64bb59 100644 --- a/routes/bitcoin/send.js +++ b/routes/bitcoin/send.js @@ -54,7 +54,7 @@ module.exports = ah(async (req, res) => { if (total > account.balance) { l.error("amount exceeds balance", amount, fee, account.balance); - throw new Error("Insufficient funds"); + throw new Error("low balance"); } await account.decrement({ balance: total }, { transaction }); @@ -92,6 +92,7 @@ module.exports = ah(async (req, res) => { payments.push(params.hash); l.info("sent bitcoin", user.username, total); } catch (e) { + if (e.message.includes("Insufficient")) e.message = "The coinos server hot wallet has insufficient funds to complete the payment, try again later"; l.error("error sending bitcoin", e.message); return res.status(500).send(e.message); } diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js index ffc0ae03..6723d577 100644 --- a/routes/lightning/receive.js +++ b/routes/lightning/receive.js @@ -1,4 +1,5 @@ const handlePayment = async (msg) => { + l.info("incoming lightning payment", msg.value, msg.payment_request, msg.settled); if (!msg.settled) return; let account, total, user; @@ -15,7 +16,7 @@ const handlePayment = async (msg) => { await db.transaction(async (transaction) => { const { text: hash, currency, memo, rate, tip, user_id } = invoice; const amount = parseInt(msg.amt_paid_sat) - tip; - if (amount > 10000000 || amount < 0) + if (amount < 0) throw new Error("amount out of range"); account = await db.Account.findOne({ |
