From 9be9e162c19c6f000a69b1502245603688f39411 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Tue, 14 Nov 2017 23:04:21 +0300 Subject: [PATCH] missing spv random server pick cond --- routes/electrumjs/electrumServers.js | 4 ++-- routes/shepherd/auth.js | 7 ++----- routes/shepherd/electrum/coins.js | 20 ++++++++++++++------ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/routes/electrumjs/electrumServers.js b/routes/electrumjs/electrumServers.js index 55d37bc..d08fdd1 100644 --- a/routes/electrumjs/electrumServers.js +++ b/routes/electrumjs/electrumServers.js @@ -26,7 +26,7 @@ let electrumServers = { '136.243.45.140:10002', '18.216.195.109:10002', '52.41.58.116:10002', - '52.67.48.29 :10002', + '52.67.48.29:10002', '13.124.87.194:10002', '52.63.107.102:10002' ], @@ -64,7 +64,7 @@ let electrumServers = { '136.243.45.140:10001', '18.216.195.109:10001', '52.41.58.116:10001', - '52.67.48.29 :10001', + '52.67.48.29:10001', '13.124.87.194:10001', '52.63.107.102:10001' ], diff --git a/routes/shepherd/auth.js b/routes/shepherd/auth.js index 75ed1c9..25f9cc0 100644 --- a/routes/shepherd/auth.js +++ b/routes/shepherd/auth.js @@ -8,7 +8,8 @@ module.exports = (shepherd) => { let _status = false; if (Object.keys(shepherd.coindInstanceRegistry).length) { - if (Object.keys(shepherd.electrumCoins).length > 1 && shepherd.electrumCoins.auth) { + if (Object.keys(shepherd.electrumCoins).length > 1 && + shepherd.electrumCoins.auth) { _status = true; } else if (Object.keys(shepherd.electrumCoins).length === 1 && !shepherd.electrumCoins.auth) { _status = true; @@ -20,11 +21,7 @@ module.exports = (shepherd) => { } successObj = { - pubkey: 'nativeonly', - result: 'success', - handle: '', status: _status ? 'unlocked' : 'locked', - duration: 2507830, }; res.end(JSON.stringify(successObj)); diff --git a/routes/shepherd/electrum/coins.js b/routes/shepherd/electrum/coins.js index 19ac9da..1130163 100644 --- a/routes/shepherd/electrum/coins.js +++ b/routes/shepherd/electrum/coins.js @@ -16,7 +16,7 @@ module.exports = (shepherd) => { return Math.floor(Math.random() * (max - min + 1)) + min; // the maximum is inclusive and the minimum is inclusive } - let randomServer = {}; + let randomServer; // pick a random server to communicate with if (servers && @@ -26,8 +26,10 @@ module.exports = (shepherd) => { const _serverDetails = _randomServer.split(':'); if (_serverDetails.length === 2) { - randomServer.ip = _serverDetails[0]; - randomServer.port = _serverDetails[1]; + randomServer = { + ip: _serverDetails[0], + port: _serverDetails[1], + }; } } @@ -37,15 +39,21 @@ module.exports = (shepherd) => { name: key, abbr: coin, server: { - ip: randomServer.ip, // shepherd.electrumServers[key].address, - port: randomServer.port, // shepherd.electrumServers[key].port, + ip: randomServer ? randomServer.ip : shepherd.electrumServers[key].address, + port: randomServer ? randomServer.port : shepherd.electrumServers[key].port, }, serverList: shepherd.electrumServers[key].serverList ? shepherd.electrumServers[key].serverList : 'none', txfee: 'calculated' /*shepherd.electrumServers[key].txfee*/, }; shepherd.log(`default ${coin} electrum server ${shepherd.electrumServers[key].address + ':' + shepherd.electrumServers[key].port}`, true); - shepherd.log(`random ${coin} electrum server ${randomServer.ip + ':' + randomServer.port}`, true); + + if (randomServer) { + shepherd.log(`random ${coin} electrum server ${randomServer.ip + ':' + randomServer.port}`, true); + } else { + shepherd.log(`${coin} doesnt have any backup electrum servers`, true); + } + return true; } }