From 5d4a7d623b8beeda5fa20779acd64fd4d6ac1aa9 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Mon, 19 Feb 2018 21:32:35 +0300 Subject: [PATCH] spv close connections fix --- routes/shepherd/electrum/balance.js | 9 +++++++-- routes/shepherd/electrum/listunspent.js | 2 ++ routes/shepherd/electrum/merkle.js | 6 +++++- routes/shepherd/electrum/transactions.js | 2 ++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/routes/shepherd/electrum/balance.js b/routes/shepherd/electrum/balance.js index 2c25708..6b73d9b 100644 --- a/routes/shepherd/electrum/balance.js +++ b/routes/shepherd/electrum/balance.js @@ -13,9 +13,8 @@ module.exports = (shepherd) => { json.hasOwnProperty('confirmed') && json.hasOwnProperty('unconfirmed')) { if (network === 'komodo') { - ecl.connect(); ecl.blockchainAddressListunspent(req.query.address) - .then((utxoList) => { + .then((utxoList) => { if (utxoList && utxoList.length) { // filter out < 10 KMD amounts @@ -81,6 +80,8 @@ module.exports = (shepherd) => { res.end(JSON.stringify(successObj)); }); } else { + ecl.close(); + const successObj = { msg: 'success', result: { @@ -98,6 +99,8 @@ module.exports = (shepherd) => { res.end(JSON.stringify(successObj)); } } else { + ecl.close(); + const successObj = { msg: 'success', result: { @@ -133,6 +136,8 @@ module.exports = (shepherd) => { res.end(JSON.stringify(successObj)); } } else { + ecl.close(); + const successObj = { msg: 'error', result: shepherd.CONNECTION_ERROR_OR_INCOMPLETE_DATA, diff --git a/routes/shepherd/electrum/listunspent.js b/routes/shepherd/electrum/listunspent.js index f8b2fe3..b280ee4 100644 --- a/routes/shepherd/electrum/listunspent.js +++ b/routes/shepherd/electrum/listunspent.js @@ -26,6 +26,7 @@ module.exports = (shepherd) => { } if (!_utxo.length) { // no confirmed utxo + ecl.close(); resolve('no valid utxo'); } else { shepherd.Promise.all(_utxo.map((_utxoItem, index) => { @@ -129,6 +130,7 @@ module.exports = (shepherd) => { }); } } else { + ecl.close(); resolve('cant get current height'); } }); diff --git a/routes/shepherd/electrum/merkle.js b/routes/shepherd/electrum/merkle.js index 07bfd29..39cde0e 100644 --- a/routes/shepherd/electrum/merkle.js +++ b/routes/shepherd/electrum/merkle.js @@ -83,13 +83,16 @@ module.exports = (shepherd) => { resolve(false); } } else { + ecl.close(); resolve(shepherd.CONNECTION_ERROR_OR_INCOMPLETE_DATA); } } else { + ecl.close(); resolve(shepherd.CONNECTION_ERROR_OR_INCOMPLETE_DATA); } }); } else { + ecl.close(); resolve(shepherd.CONNECTION_ERROR_OR_INCOMPLETE_DATA); } }); @@ -118,7 +121,8 @@ module.exports = (shepherd) => { height, _filteredServerList, shepherd.electrumCoins[coin].server.ip + ':' + shepherd.electrumCoins[coin].server.port + ':' + shepherd.electrumServers[coin === 'KMD' || coin === 'komodo' ? 'komodo' : coin.toLowerCase()].proto - ).then((proof) => { + ) + .then((proof) => { resolve(proof); }); } else { diff --git a/routes/shepherd/electrum/transactions.js b/routes/shepherd/electrum/transactions.js index f571962..55d4463 100644 --- a/routes/shepherd/electrum/transactions.js +++ b/routes/shepherd/electrum/transactions.js @@ -188,6 +188,8 @@ module.exports = (shepherd) => { res.end(JSON.stringify(successObj)); }); } else { + ecl.close(); + const successObj = { msg: 'success', result: [],