From 075361f1b32f52b220814aae0355c565e6ed7471 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 29 Nov 2018 11:29:04 -0800 Subject: combine balances --- index.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 85ffe932..46c4633e 100644 --- a/index.js +++ b/index.js @@ -256,7 +256,7 @@ const l = console.log l('channel error', peer, err) let msg = err.message - if (msg.startsWith('Multiple') || msg.startsWith('You gave')) { + if (msg.startsWith('Multiple') || msg.startsWith('You gave') || msg.startsWith('peer')) { busypeers.push(peer) peer = lna.channelpeers.find(p => !busypeers.includes(p)) if (peer) { @@ -314,7 +314,11 @@ const l = console.log } if (req.user.channelbalance < payreq.satoshis) { - return res.status(500).send('Not enough satoshis') + if (req.user.balance + req.user.channelbalance < payreq.satoshis) { + return res.status(500).send('Not enough satoshis') + } + req.user.balance -= (payreq.satoshis - req.user.channelbalance) + req.user.channelbalance = 0 } const stream = lna.sendPayment(lna.meta, {}) @@ -362,8 +366,11 @@ const l = console.log } if (req.user.balance < amount - MINFEE) { - res.status(500).send('Not enough funds') - return + if (req.user.balance + req.user.channelbalance < amount - MINFEE) { + return res.status(500).send('Not enough satoshis') + } + req.user.channelbalance -= (payreq.satoshis - req.user.balance) + req.user.balance = 0 } try { -- cgit v1.2.3