Browse Source

hide all modes

all-modes
pbca26 7 years ago
parent
commit
016484069e
  1. 2
      gui/startup/index.html
  2. 5
      main.js
  3. 247
      routes/cache.js

2
gui/startup/index.html

@ -57,7 +57,7 @@
class="btn btn-primary btn-mode"> class="btn btn-primary btn-mode">
<img src="../EasyDEX-GUI/assets/mainWindow/img/fa-cubes.png"> All modes <img src="../EasyDEX-GUI/assets/mainWindow/img/fa-cubes.png"> All modes
</button> </button>
<div class="margin-top-20"> <div class="margin-top-20 settings-stick-to-right">
<button <button
id="settingsBtn" id="settingsBtn"
onClick="openSettingsWindow()" onClick="openSettingsWindow()"

5
main.js

@ -82,7 +82,7 @@ shepherd.writeLog(`app started in ${(appConfig.dev ? 'dev mode' : ' user mode')}
shepherd.setConfKMD(); shepherd.setConfKMD();
if (appConfig.killIguanaOnStart) { if (appConfig.killIguanaOnStart) {
shepherd.killRogueProcess('iguana'); // shepherd.killRogueProcess('iguana');
} }
guiapp.use(function(req, res, next) { guiapp.use(function(req, res, next) {
@ -531,7 +531,8 @@ app.on('window-all-closed', function() {
// Calling event.preventDefault() will prevent the default behaviour, which is terminating the application. // Calling event.preventDefault() will prevent the default behaviour, which is terminating the application.
app.on('before-quit', function(event) { app.on('before-quit', function(event) {
shepherd.log('before-quit'); shepherd.log('before-quit');
shepherd.killRogueProcess('iguana'); // kill any rogue iguana core instances // shepherd.killRogueProcess('iguana'); // kill any rogue iguana core instances
if (!forceQuitApp && mainWindow === null && loadingWindow != null) { // mainWindow not intitialised and loadingWindow not dereferenced if (!forceQuitApp && mainWindow === null && loadingWindow != null) { // mainWindow not intitialised and loadingWindow not dereferenced
// loading window is still open // loading window is still open
shepherd.log('before-quit prevented'); shepherd.log('before-quit prevented');

247
routes/cache.js

@ -498,7 +498,8 @@ cache.one = function(req, res, next) {
outObj.basilisk[coin][address][key].status = 'in progress'; outObj.basilisk[coin][address][key].status = 'in progress';
request({ request({
url: mock ? `http://localhost:17777/shepherd/mock?url=${dexUrl}` : dexUrl, url: mock ? `http://localhost:17777/shepherd/mock?url=${dexUrl}` : dexUrl,
method: 'GET' method: 'GET',
timeout: 30000,
}, function(error, response, body) { }, function(error, response, body) {
if (response && if (response &&
response.statusCode && response.statusCode &&
@ -519,21 +520,55 @@ cache.one = function(req, res, next) {
}, },
}); });
// basilisk balance fallback // basilisk fallback
const _parsedJSON = JSON.parse(body); const _parsedJSON = JSON.parse(body);
if (key === 'getbalance' && _explorerURL = {
coin === 'KMD'/* && getbalance: `http://kmd.explorer.supernet.org/api/addr/${address}/?noTxList=1`,
((_parsedJSON && _parsedJSON.balance === 0) || body === [])*/) { listtransactions: `https://kmd.explorer.supernet.org/api/txs?address=${address}&pageNum=0`
};
if ((key === 'getbalance' &&
coin === 'KMD' &&
((_parsedJSON && _parsedJSON.balance === 0) || body === [])) ||
(key === 'listtransactions' &&
coin === 'KMD' &&
(_parsedJSON === [] || !_parsedJSON.length))) {
cache.shepherd.log('fallback to kmd explorer ======>'); cache.shepherd.log('fallback to kmd explorer ======>');
request({ request({
url: `http://kmd.explorer.supernet.org/api/addr/${address}/?noTxList=1`, url: _explorerURL[key],
method: 'GET' method: 'GET'
}, function(error, response, body) { }, function(error, response, _body) {
if (response && if (response &&
response.statusCode && response.statusCode &&
response.statusCode === 200) { response.statusCode === 200) {
console.log(JSON.stringify(body)); let _parsedExplorerJSON = JSON.parse(_body);
/*cache.io.emit('messages', { _parsedExplorerJSON['source'] = 'explorer';
let _formattedTxs = [];
if (key === 'listtransactions' &&
_parsedExplorerJSON['txs'] &&
_parsedExplorerJSON['txs'].length) {
const _txList = _parsedExplorerJSON['txs'];
for (let i = 0; i < _txList.length; i++) {
_formattedTxs.push({
type: 'unknown',
height: _txList[i].blockheight,
confirmations: _txList[i].confirmations,
timestamp: _txList[i].time,
amount: _txList[i].vout[1].value,
txid: _txList[i].txid,
source: 'explorer',
});
}
_parsedExplorerJSON = _formattedTxs;
}
if ((key === 'getbalance' &&
Number(_parsedExplorerJSON.balance) !== Number(_parsedJSON.balance) &&
Number(_parsedExplorerJSON.txApperances) < 500) || key === 'listtransactions') {
body = JSON.stringify(_parsedExplorerJSON);
}
cache.io.emit('messages', {
'message': { 'message': {
'shepherd': { 'shepherd': {
'method': 'cache-one', 'method': 'cache-one',
@ -543,62 +578,172 @@ cache.one = function(req, res, next) {
'coin': coin, 'coin': coin,
'address': address, 'address': address,
'status': 'done', 'status': 'done',
'resp': body 'resp': _body
} }
} }
} }
});*/ });
outObj.basilisk[coin][address][key] = {};
outObj.basilisk[coin][address][key].data = JSON.parse(body);
outObj.basilisk[coin][address][key].timestamp = Date.now(); // add timestamp
outObj.basilisk[coin][address][key].status = 'done';
cache.shepherd.log(dexUrl);
cache.shepherd.log(body);
callStack[coin]--;
cache.shepherd.log(`${coin} _stack len ${callStack[coin]}`);
cache.io.emit('messages', {
message: {
shepherd: {
method: 'cache-one',
status: 'in progress',
iguanaAPI: {
currentStackLength: callStack[coin],
},
},
},
});
checkCallStack();
writeCache();
} else { } else {
cache.shepherd.log(`explorer ${key} for address ${address} fallback failed`);
} }
}); });
} } else {
outObj.basilisk[coin][address][key] = {};
outObj.basilisk[coin][address][key] = {}; outObj.basilisk[coin][address][key].data = JSON.parse(body);
outObj.basilisk[coin][address][key].data = JSON.parse(body); outObj.basilisk[coin][address][key].timestamp = Date.now(); // add timestamp
outObj.basilisk[coin][address][key].timestamp = Date.now(); // add timestamp outObj.basilisk[coin][address][key].status = 'done';
outObj.basilisk[coin][address][key].status = 'done'; cache.shepherd.log(dexUrl);
cache.shepherd.log(dexUrl); cache.shepherd.log(body);
cache.shepherd.log(body); callStack[coin]--;
callStack[coin]--; cache.shepherd.log(`${coin} _stack len ${callStack[coin]}`);
cache.shepherd.log(`${coin} _stack len ${callStack[coin]}`); cache.io.emit('messages', {
cache.io.emit('messages', { message: {
message: { shepherd: {
shepherd: { method: 'cache-one',
method: 'cache-one', status: 'in progress',
status: 'in progress', iguanaAPI: {
iguanaAPI: { currentStackLength: callStack[coin],
currentStackLength: callStack[coin], },
}, },
}, },
}, });
}); checkCallStack();
checkCallStack(); writeCache();
}
writeCache();
} }
if (error || if (error ||
!body || !body ||
!response) { !response) {
outObj.basilisk[coin][address][key] = {}; // basilisk fallback
outObj.basilisk[coin][address][key].data = { 'error': 'request failed' }; _explorerURL = {
outObj.basilisk[coin][address][key].timestamp = 1471620867 // add timestamp getbalance: `http://kmd.explorer.supernet.org/api/addr/${address}/?noTxList=1`,
outObj.basilisk[coin][address][key].status = 'done'; listtransactions: `https://kmd.explorer.supernet.org/api/txs?address=${address}&pageNum=0`
callStack[coin]--; };
cache.shepherd.log(`${coin} _stack len ${callStack[coin]}`); if ((key === 'getbalance' &&
cache.io.emit('messages', { coin === 'KMD') ||
message: { (key === 'listtransactions' &&
shepherd: { coin === 'KMD')) {
method: 'cache-one', cache.shepherd.log('fallback to kmd explorer ======>');
status: 'in progress', request({
iguanaAPI: { url: _explorerURL[key],
currentStackLength: callStack[coin], method: 'GET'
}, function(error, response, _body) {
if (response &&
response.statusCode &&
response.statusCode === 200) {
let _parsedExplorerJSON = JSON.parse(_body);
_parsedExplorerJSON['source'] = 'explorer';
if ((key === 'getbalance' &&
Number(_parsedExplorerJSON.balance) !== Number(_parsedJSON.balance) &&
Number(_parsedExplorerJSON.txApperances) < 500) || key === 'listtransactions') {
body = JSON.stringify(_parsedExplorerJSON);
}
cache.io.emit('messages', {
'message': {
'shepherd': {
'method': 'cache-one',
'status': 'in progress',
'iguanaAPI': {
'method': key,
'coin': coin,
'address': address,
'status': 'done',
'resp': _body
}
}
}
});
outObj.basilisk[coin][address][key] = {};
outObj.basilisk[coin][address][key].data = JSON.parse(body);
outObj.basilisk[coin][address][key].timestamp = Date.now(); // add timestamp
outObj.basilisk[coin][address][key].status = 'done';
cache.shepherd.log(dexUrl);
cache.shepherd.log(body);
callStack[coin]--;
cache.shepherd.log(`${coin} _stack len ${callStack[coin]}`);
cache.io.emit('messages', {
message: {
shepherd: {
method: 'cache-one',
status: 'in progress',
iguanaAPI: {
currentStackLength: callStack[coin],
},
},
},
});
checkCallStack();
writeCache();
} else {
cache.shepherd.log(`explorer ${key} for address ${address} fallback failed`);
outObj.basilisk[coin][address][key] = {};
outObj.basilisk[coin][address][key].data = { 'error': 'request failed' };
outObj.basilisk[coin][address][key].timestamp = 1471620867 // add timestamp
outObj.basilisk[coin][address][key].status = 'done';
callStack[coin]--;
cache.shepherd.log(`${coin} request ${key} for address ${address} failed`);
cache.shepherd.log(`${coin} _stack len ${callStack[coin]}`);
cache.io.emit('messages', {
message: {
shepherd: {
method: 'cache-one',
status: 'in progress',
iguanaAPI: {
currentStackLength: callStack[coin],
},
},
},
});
checkCallStack();
writeCache();
}
});
} else {
outObj.basilisk[coin][address][key] = {};
outObj.basilisk[coin][address][key].data = { 'error': 'request failed' };
outObj.basilisk[coin][address][key].timestamp = 1471620867 // add timestamp
outObj.basilisk[coin][address][key].status = 'done';
callStack[coin]--;
cache.shepherd.log(`${coin} request ${key} for address ${address} failed`);
cache.shepherd.log(`${coin} _stack len ${callStack[coin]}`);
cache.io.emit('messages', {
message: {
shepherd: {
method: 'cache-one',
status: 'in progress',
iguanaAPI: {
currentStackLength: callStack[coin],
},
}, },
}, },
}, });
}); checkCallStack();
checkCallStack(); writeCache();
writeCache(); }
} }
}); });
} else { } else {

Loading…
Cancel
Save