Browse Source

Merge branch 'master' into pkg_automation

pkg_automation_electrum
ca333 7 years ago
committed by GitHub
parent
commit
de6a79470e
  1. 2
      gui/EasyDEX-GUI
  2. 1
      gui/app-closing.html
  3. 110
      main.js
  4. 1
      make-patch.sh
  5. 12
      private/mainmenu.js
  6. 152
      routes/appConfig.js
  7. 502
      routes/cache.js
  8. 969
      routes/shepherd.js

2
gui/EasyDEX-GUI

@ -1 +1 @@
Subproject commit 7399c05db6464596edf4c242f5a3a57445c70ded
Subproject commit 0092ac50871b6964e6462f3ba68ac7d1cd8c1421

1
gui/app-closing.html

@ -20,6 +20,5 @@
<div id="agamaModeStatus">App is closing. Please wait...</div>
</div>
</div>
<!--script type="text/javascript" src="EasyDEX-GUI/assets/mainWindow/js/init.js"></script-->
</body>
</html>

110
main.js

@ -54,6 +54,7 @@ const appBasicInfo = {
app.setName(appBasicInfo.name);
app.setVersion(appBasicInfo.version);
shepherd.binFixRights();
shepherd.createIguanaDirs();
const appSessionHash = md5(Date.now());
@ -75,45 +76,8 @@ shepherd.writeLog(`app started in ${(appConfig.dev ? 'dev mode' : ' user mode')}
shepherd.setConfKMD();
// kill rogue iguana copies on start
if (appConfig.killIguanaOnStart) {
let iguanaGrep;
switch (osPlatform) {
case 'darwin':
iguanaGrep = "ps -p $(ps -A | grep -m1 iguana | awk '{print $1}') | grep -i iguana";
break;
case 'linux':
iguanaGrep = 'ps -p $(pidof iguana) | grep -i iguana';
break;
case 'win32':
iguanaGrep = 'tasklist';
break;
}
exec(iguanaGrep, function(error, stdout, stderr) {
if (stdout.indexOf('iguana') > -1) {
const pkillCmd = osPlatform === 'win32' ? 'taskkill /f /im iguana.exe' : 'pkill -15 iguana';
console.log('found another iguana process(es)');
shepherd.writeLog('found another iguana process(es)');
exec(pkillCmd, function(error, stdout, stderr) {
console.log(`${pkillCmd} is issued`);
shepherd.writeLog(`${pkillCmd} is issued`);
if (error !== null) {
console.log(`${pkillCmd} exec error: ${error}`);
shepherd.writeLog(`${pkillCmd} exec error: ${error}`);
};
});
}
if (error !== null) {
console.log(`${iguanaGrep} exec error: ${error}`);
shepherd.writeLog(`${iguanaGrep} exec error: ${error}`);
};
});
shepherd.killRogueProcess('iguana');
}
guiapp.use(function(req, res, next) {
@ -126,8 +90,8 @@ guiapp.use(function(req, res, next) {
});
// preload.js
const _setImmediate = setImmediate,
_clearImmediate = clearImmediate;
const _setImmediate = setImmediate;
const _clearImmediate = clearImmediate;
process.once('loaded', () => {
global.setImmediate = _setImmediate;
@ -150,10 +114,10 @@ process.once('loaded', () => {
guiapp.use(bodyParser.json({ limit: '50mb' })); // support json encoded bodies
guiapp.use(bodyParser.urlencoded({
limit: '50mb',
extended: true
extended: true,
})); // support encoded bodies
guiapp.get('/', function (req, res) {
guiapp.get('/', function(req, res) {
res.send('Agama app server');
});
@ -168,6 +132,7 @@ let mainWindow;
let loadingWindow;
let appCloseWindow;
let closeAppAfterLoading = false;
const _zcashParamsExist = shepherd.zcashParamsExist();
module.exports = guiapp;
let iguanaIcon;
@ -251,7 +216,7 @@ function createLoadingWindow() {
// loadingWindow.webContents.openDevTools()
// if window closed we kill iguana proc
loadingWindow.on('hide', function () {
loadingWindow.on('hide', function() {
// our app does not have multiwindow - so we dereference the window object instead of
// putting them into an window_arr
loadingWindow = null;
@ -337,10 +302,13 @@ function createWindow(status) {
if (appConfig.v2) {
shepherd.writeLog('show edex gui');
mainWindow.appConfig = appConfig;
mainWindow.appConfigSchema = shepherd.appConfigSchema;
mainWindow.appBasicInfo = appBasicInfo;
mainWindow.appSessionHash = appSessionHash;
mainWindow.assetChainPorts = require('./routes/ports.js');
mainWindow.zcashParamsExist = shepherd.zcashParamsExist();
mainWindow.zcashParamsExist = _zcashParamsExist;
mainWindow.iguanaIcon = iguanaIcon;
mainWindow.testLocation = shepherd.testLocation;
if (appConfig.dev) {
mainWindow.loadURL('http://127.0.0.1:3000');
@ -421,16 +389,16 @@ function createWindow(status) {
shepherd.writeLog(result);
resolve(result);
}, 2000)
}, 2000);
})
}
const HideMainWindow = function() {
return new Promise(function(resolve, reject) {
const result = 'Hiding Main Window: done';
console.log('Exiting App...');
mainWindow = null;
const result = 'Hiding Main Window: done';
console.log(result);
resolve(result);
});
@ -445,9 +413,10 @@ function createWindow(status) {
const QuitApp = function() {
return new Promise(function(resolve, reject) {
const result = 'Quiting App: done';
KillPm2(); // required for normal app quit in iguana-less mode
app.quit();
const result = 'Quiting App: done';
console.log(result);
resolve(result);
});
@ -468,13 +437,13 @@ function createWindow(status) {
if (!Object.keys(shepherd.coindInstanceRegistry).length) {
closeApp();
} else {
createAppCloseWindow();
shepherd.quitKomodod(1000);
_appClosingInterval = setInterval(function() {
if (!Object.keys(shepherd.coindInstanceRegistry).length) {
closeApp();
}
}, 1000);
createAppCloseWindow();
}
}
@ -485,7 +454,7 @@ function createWindow(status) {
}
}
app.on('window-all-closed', function () {
app.on('window-all-closed', function() {
//if (os.platform() !== 'win32') { ig.kill(); }
// in osx apps stay active in menu bar until explictly closed or quitted by CMD Q
// so we do not kill the app --> for the case user clicks again on the iguana icon
@ -497,7 +466,7 @@ app.on('window-all-closed', function () {
// Emitted before the application starts closing its windows.
// 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) {
console.log('before-quit');
if (mainWindow === null && loadingWindow != null) { // mainWindow not intitialised and loadingWindow not dereferenced
// loading window is still open
@ -512,7 +481,7 @@ app.on('before-quit', function (event) {
// Emitted when all windows have been closed and the application will quit.
// Calling event.preventDefault() will prevent the default behaviour, which is terminating the application.
app.on('will-quit', function (event) {
app.on('will-quit', function(event) {
if (mainWindow === null && loadingWindow != null) {
// loading window is still open
console.log('will-quit while loading window active');
@ -522,37 +491,38 @@ app.on('will-quit', function (event) {
// Emitted when the application is quitting.
// Calling event.preventDefault() will prevent the default behaviour, which is terminating the application.
app.on('quit', function (event) {
app.on('quit', function(event) {
if (mainWindow === null && loadingWindow != null) {
console.log('quit while loading window active');
event.preventDefault();
}
})
app.on('activate', function () {
app.on('activate', function() {
if (mainWindow === null) {
// createWindow('open');
}
});
function formatBytes(bytes, decimals) {
if (bytes === 0)
if (bytes === 0) {
return '0 Bytes';
const k = 1000,
dm = decimals + 1 || 3,
sizes = [
'Bytes',
'KB',
'MB',
'GB',
'TB',
'PB',
'EB',
'ZB',
'YB'
],
i = Math.floor(Math.log(bytes) / Math.log(k));
}
const k = 1000;
const dm = decimals + 1 || 3;
const sizes = [
'Bytes',
'KB',
'MB',
'GB',
'TB',
'PB',
'EB',
'ZB',
'YB'
];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
}

1
make-patch.sh

@ -17,6 +17,7 @@ mkdir patch/gui/EasyDEX-GUI/react
cp -R gui/EasyDEX-GUI/react/build patch/gui/EasyDEX-GUI/react/build
cp -R gui/EasyDEX-GUI/assets patch/gui/EasyDEX-GUI
cp gui/index.html patch/gui/index.html
cp gui/app-closing.html patch/gui/app-closing.html
cp ./main.js patch
cp ./version patch
cp -R routes patch/routes

12
private/mainmenu.js

@ -1,7 +1,7 @@
const {Menu} = require('electron'),
electron = require('electron'),
app = electron.app,
{shell} = require('electron');
const {Menu} = require('electron');
const electron = require('electron');
const app = electron.app;
const {shell} = require('electron');
const template = [
{
@ -86,7 +86,7 @@ const template = [
}
]
},
{
/*{
role: 'help',
label: 'Support',
submenu: [
@ -121,7 +121,7 @@ const template = [
}
}
]
}
}*/
]
if (process.platform === 'darwin') {

152
routes/appConfig.js

@ -0,0 +1,152 @@
const appConfig = {
config: {
edexGuiOnly: true,
iguanaGuiOnly: false,
manualIguanaStart: false,
skipBasiliskNetworkCheck: true,
minNotaries: 8,
host: '127.0.0.1',
agamaPort: 17777,
iguanaCorePort: 7778,
maxDescriptors: {
darwin: 90000,
linux: 1000000,
},
killIguanaOnStart: true,
dev: false,
v2: true,
useBasiliskInstance: true,
debug: false,
cli: {
passthru: true,
default: true,
},
iguanaLessMode: true,
roundValues: false,
dataDir: '',
},
schema: {
edexGuiOnly: {
display: false,
type: 'boolean',
displayName: 'EDEX GUI only',
},
iguanaGuiOnly: {
display: false,
type: 'boolean',
displayName: 'Iguana GUI only',
},
manualIguanaStart: {
display: false,
type: 'boolean',
displayName: 'Manual Iguana Start',
},
skipBasiliskNetworkCheck: {
display: false,
type: 'boolean',
displayName: 'Skip Basilisk Network Check',
},
minNotaries: {
display: false,
type: 'number',
displayName: 'Minimum notaries count',
info: 'Minimum number of notaries to connect to on startup',
},
host: {
display: true,
type: 'string',
displayName: 'Hostname',
info: 'Application hostname',
},
agamaPort: {
display: true,
type: 'number',
displayName: 'Agama Port',
info: 'Agama HTTP port. Required to run GUI.',
},
iguanaCorePort: {
display: true,
type: 'number',
displayName: 'Iguana Core Port',
info: 'Default Iguana Core Port. Change it if you have conflicts with other applications.',
},
maxDescriptors: {
display: false,
displayName: 'Max Descriptors per Process',
darwin: {
display: true,
displayName: 'MacOS (Darwin)',
type: 'number',
},
linux: {
display: true,
displayName: 'Linux',
type: 'number',
},
},
killIguanaOnStart: {
display: true,
displayName: 'Kill Iguana Core Processes on Startup',
info: 'Kill any rogue Iguana Core processes during app startup',
type: 'boolean',
},
dev: {
display: true,
displayName: 'Developer mode',
info: 'Enable developer mode.',
type: 'boolean',
},
v2: {
display: false,
type: 'boolean',
},
useBasiliskInstance: {
display: true,
displayName: 'Iguana Core Basilisk Instance',
info: 'Enable dedicated Iguana Core instance to handle all Basilisk network requests',
type: 'boolean',
},
debug: {
display: true,
displayName: 'Debug',
info: 'Enable debug output',
type: 'boolean',
},
cli: {
display: true,
displayName: 'Direct BitcoinRPC passthru interface',
info: 'Enable direct BitcoinRPC passthru interface. It will bypass Iguana Core and send requests directly to Bitcoin JSON server.',
passthru: {
display: true,
displayName: 'Enable Direct Passthru',
type: 'boolean',
},
default: {
display: true,
displayName: 'Enable CLI passthru',
info: 'Enable komodo-cli passthru. This allows you to send CLI compatible commands directly from UI to komodo-cli.',
type: 'boolean',
},
},
iguanaLessMode: {
display: true,
displayName: 'Enable Native Only mode',
info: 'Limited to only Komodo native mode to speed up loading and reduce hardware resources consumption.',
type: 'boolean',
},
roundValues: {
display: true,
displayName: 'Enable amount rounding',
info: 'Round \"dust\" amounts to save screen space.',
type: 'boolean',
},
dataDir: {
display: true,
displayName: 'Komodo data directory',
info: 'The data directory is the location where Komodo data files are stored, including the wallet data file.',
type: 'folder',
},
},
};
module.exports = appConfig;

502
routes/cache.js

@ -1,6 +1,6 @@
const fs = require('fs-extra'),
request = require('request'),
async = require('async');
const fs = require('fs-extra');
const request = require('request');
const async = require('async');
var cache = {};
var inMemCache;
@ -33,18 +33,18 @@ cache.get = function(req, res, next) {
fs.readFile(`${cache.iguanaDir}/shepherd/cache-${pubkey}.json`, 'utf8', function (err, data) {
if (err) {
const errorObj = {
'msg': 'error',
'result': err
msg: 'error',
result: err,
};
res.end(JSON.stringify(errorObj));
} else {
} else { // deprecated
try {
const parsedJSON = JSON.parse(data),
successObj = {
'msg': 'success',
'result': parsedJSON
};
const parsedJSON = JSON.parse(data);
const successObj = {
msg: 'success',
result: parsedJSON,
};
inMemCache = parsedJSON;
res.end(JSON.stringify(successObj));
@ -59,8 +59,8 @@ cache.get = function(req, res, next) {
fs.writeFile(`${cache.iguanaDir}/shepherd/cache-${pubkey}.json`, data.substring(0, errorPos[errorPos.length - 1]), function(err) {
const successObj = {
'msg': 'success',
'result': data.substring(0, errorPos[errorPos.length - 1])
msg: 'success',
result: data.substring(0, errorPos[errorPos.length - 1]),
};
inMemCache = JSON.parse(data.substring(0, errorPos[errorPos.length - 1]));
@ -72,24 +72,24 @@ cache.get = function(req, res, next) {
});
} else {
const errorObj = {
'msg': 'error',
'result': `no file with handle ${pubkey}`
msg: 'error',
result: `no file with handle ${pubkey}`,
};
res.end(JSON.stringify(errorObj));
}
} else {
const successObj = {
'msg': 'success',
'result': inMemCache
msg: 'success',
result: inMemCache,
};
res.end(JSON.stringify(successObj));
}
} else {
const errorObj = {
'msg': 'error',
'result': 'no pubkey provided'
msg: 'error',
result: 'no pubkey provided',
};
res.end(JSON.stringify(errorObj));
@ -104,15 +104,15 @@ cache.groomGet = function(req, res, next) {
fs.readFile(`${cache.iguanaDir}/shepherd/cache-${_filename}.json`, 'utf8', function (err, data) {
if (err) {
const errorObj = {
'msg': 'error',
'result': err
msg: 'error',
result: err,
};
res.end(JSON.stringify(errorObj));
} else {
const successObj = {
'msg': 'success',
'result': data ? JSON.parse(data) : ''
msg: 'success',
result: data ? JSON.parse(data) : '',
};
res.end(JSON.stringify(successObj));
@ -120,16 +120,16 @@ cache.groomGet = function(req, res, next) {
});
} else {
const errorObj = {
'msg': 'error',
'result': `no file with name ${_filename}`
msg: 'error',
result: `no file with name ${_filename}`,
};
res.end(JSON.stringify(errorObj));
}
} else {
const errorObj = {
'msg': 'error',
'result': 'no file name provided'
msg: 'error',
result: 'no file name provided',
};
res.end(JSON.stringify(errorObj));
@ -146,15 +146,15 @@ cache.groomDelete = function(req, res, next) {
fs.unlink(`${cache.iguanaDir}/shepherd/cache-${_filename}.json`, function(err) {
if (err) {
const errorObj = {
'msg': 'error',
'result': err
msg: 'error',
result: err,
};
res.end(JSON.stringify(errorObj));
} else {
const successObj = {
'msg': 'success',
'result': 'deleted'
msg: 'success',
result: 'deleted',
};
res.end(JSON.stringify(successObj));
@ -162,16 +162,16 @@ cache.groomDelete = function(req, res, next) {
});
} else {
const errorObj = {
'msg': 'error',
'result': `no file with name ${_filename}`
msg: 'error',
result: `no file with name ${_filename}`,
};
res.end(JSON.stringify(errorObj));
}
} else {
const errorObj = {
'msg': 'error',
'result': 'no file name provided'
msg: 'error',
result: 'no file name provided',
};
res.end(JSON.stringify(errorObj));
@ -179,8 +179,8 @@ cache.groomDelete = function(req, res, next) {
}
cache.groomPost = function(req, res) {
const _filename = req.body.filename,
_payload = req.body.payload;
const _filename = req.body.filename;
const _payload = req.body.payload;
if (!cacheCallInProgress) {
cacheCallInProgress = true;
@ -188,8 +188,8 @@ cache.groomPost = function(req, res) {
if (_filename) {
if (!_payload) {
const errorObj = {
'msg': 'error',
'result': 'no payload provided'
msg: 'error',
result: 'no payload provided',
};
res.end(JSON.stringify(errorObj));
@ -201,16 +201,16 @@ cache.groomPost = function(req, res) {
fs.writeFile(`${cache.iguanaDir}/shepherd/cache-${_filename}.json`, _payload, function (err) {
if (err) {
const errorObj = {
'msg': 'error',
'result': err
msg: 'error',
result: err,
};
cacheCallInProgress = false;
res.end(JSON.stringify(errorObj));
} else {
const successObj = {
'msg': 'success',
'result': 'done'
msg: 'success',
result: 'done',
};
cacheCallInProgress = false;
@ -220,33 +220,33 @@ cache.groomPost = function(req, res) {
}
} else {
const errorObj = {
'msg': 'error',
'result': 'no file name provided'
msg: 'error',
result: 'no file name provided',
};
res.end(JSON.stringify(errorObj));
}
} else {
const errorObj = {
'msg': 'error',
'result': 'another job is in progress'
msg: 'error',
result: 'another job is in progress',
};
res.end(JSON.stringify(errorObj));
}
}
var cacheCallInProgress = false,
cacheGlobLifetime = 600; // sec
var cacheCallInProgress = false;
const cacheGlobLifetime = 600; // sec
// TODO: reset calls' states on new /cache call start
var mock = require('./mock');
var callStack = {},
checkCallStack = function() {
var total = 0;
var callStack = {};
const checkCallStack = function() {
let total = 0;
for (var coin in callStack) {
for (let coin in callStack) {
total =+ callStack[coin];
}
@ -254,13 +254,13 @@ checkCallStack = function() {
cache.dumpCacheBeforeExit();
cacheCallInProgress = false;
cache.io.emit('messages', {
'message': {
'shepherd': {
'method': 'cache-one',
'status': 'done',
'resp': 'success'
}
}
message: {
shepherd: {
method: 'cache-one',
status: 'done',
resp: 'success',
},
},
});
}
};
@ -284,45 +284,45 @@ cache.one = function(req, res, next) {
if (fs.existsSync(`${cache.iguanaDir}/shepherd/cache-${req.query.pubkey}.json`)) {
let _data = fs.readFileSync(`${cache.iguanaDir}/shepherd/cache-${req.query.pubkey}.json`, 'utf8');
if (_data) {
inMemCache = JSON.parse(_data);
_data = _data.replace('waiting', 'failed');
cache.dumpCacheBeforeExit();
inMemCache = JSON.parse(_data);
_data = _data.replace('waiting', 'failed');
cache.dumpCacheBeforeExit();
}
}
// TODO: add check to allow only one cache call/sequence in progress
cacheCallInProgress = true;
var sessionKey = req.query.userpass,
coin = req.query.coin,
address = req.query.address,
addresses = req.query.addresses && req.query.addresses.indexOf(':') > -1 ? req.query.addresses.split(':') : null,
pubkey = req.query.pubkey,
mock = req.query.mock,
skipTimeout = req.query.skip,
callsArray = req.query.calls.split(':'),
iguanaCorePort = req.query.port ? req.query.port : cache.appConfig.iguanaCorePort,
errorObj = {
'msg': 'error',
'result': 'error'
},
outObj = {},
pubkey,
writeCache = function(timeStamp) {
if (timeStamp) {
outObj.timestamp = timeStamp;
}
let sessionKey = req.query.userpass;
let coin = req.query.coin;
let address = req.query.address;
let addresses = req.query.addresses && req.query.addresses.indexOf(':') > -1 ? req.query.addresses.split(':') : null;
let pubkey = req.query.pubkey;
let mock = req.query.mock;
let skipTimeout = req.query.skip;
let callsArray = req.query.calls.split(':');
let iguanaCorePort = req.query.port ? req.query.port : cache.appConfig.iguanaCorePort;
let errorObj = {
msg: 'error',
result: 'error',
};
let outObj = {};
const writeCache = function(timeStamp) {
if (timeStamp) {
outObj.timestamp = timeStamp;
}
inMemCache = outObj;
},
checkTimestamp = function(dateToCheck) {
var currentEpochTime = new Date(Date.now()) / 1000,
secondsElapsed = Number(currentEpochTime) - Number(dateToCheck / 1000);
inMemCache = outObj;
};
const checkTimestamp = function(dateToCheck) {
const currentEpochTime = new Date(Date.now()) / 1000;
const secondsElapsed = Number(currentEpochTime) - Number(dateToCheck / 1000);
return Math.floor(secondsElapsed);
},
internalError = false;
return Math.floor(secondsElapsed);
};
let internalError = false;
inMemPubkey = pubkey;
callStack[coin] = 1;
@ -331,8 +331,8 @@ cache.one = function(req, res, next) {
if (!sessionKey) {
const errorObj = {
'msg': 'error',
'result': 'no session key provided'
msg: 'error',
result: 'no session key provided',
};
res.end(JSON.stringify(errorObj));
@ -341,8 +341,8 @@ cache.one = function(req, res, next) {
if (!pubkey) {
const errorObj = {
'msg': 'error',
'result': 'no pubkey provided'
msg: 'error',
result: 'no pubkey provided',
};
res.end(JSON.stringify(errorObj));
@ -352,7 +352,8 @@ cache.one = function(req, res, next) {
console.log('cache-one call started');
function fixJSON(data) {
if (data && data.length) {
if (data &&
data.length) {
try {
const parsedJSON = JSON.parse(data);
@ -375,12 +376,14 @@ cache.one = function(req, res, next) {
}
}
if (fs.existsSync(`${cache.iguanaDir}/shepherd/cache-${pubkey}.json`) && coin !== 'all') {
if (fs.existsSync(`${cache.iguanaDir}/shepherd/cache-${pubkey}.json`) &&
coin !== 'all') {
if (inMemCache) {
console.log('cache one from mem');
outObj = inMemCache;
} else {
const _file = fs.readFileSync(`${cache.iguanaDir}/shepherd/cache-${pubkey}.json`, 'utf8');
console.log('cache one from disk');
outObj = fixJSON(_file);
}
@ -402,28 +405,28 @@ cache.one = function(req, res, next) {
}
res.end(JSON.stringify({
'msg': 'success',
'result': 'call is initiated'
msg: 'success',
result: 'call is initiated',
}));
if (!internalError) {
cache.io.emit('messages', {
'message': {
'shepherd': {
'method': 'cache-one',
'status': 'in progress'
}
}
message: {
shepherd: {
method: 'cache-one',
status: 'in progress',
},
},
});
function execDEXRequests(coin, address) {
let dexUrls = {
'listunspent': `http://${cache.appConfig.host}:${iguanaCorePort}/api/dex/listunspent?userpass=${sessionKey}&symbol=${coin}&address=${address}`,
'listtransactions': `http://${cache.appConfig.host}:${iguanaCorePort}/api/dex/listtransactions?userpass=${sessionKey}&count=100&skip=0&symbol=${coin}&address=${address}`,
'getbalance': `http://${cache.appConfig.host}:${iguanaCorePort}/api/dex/getbalance?userpass=${sessionKey}&symbol=${coin}&address=${address}`,
'refresh': `http://${cache.appConfig.host}:${iguanaCorePort}/api/basilisk/refresh?userpass=${sessionKey}&symbol=${coin}&address=${address}`
},
_dexUrls = {};
listunspent: `http://${cache.appConfig.host}:${iguanaCorePort}/api/dex/listunspent?userpass=${sessionKey}&symbol=${coin}&address=${address}`,
listtransactions: `http://${cache.appConfig.host}:${iguanaCorePort}/api/dex/listtransactions?userpass=${sessionKey}&count=100&skip=0&symbol=${coin}&address=${address}`,
getbalance: `http://${cache.appConfig.host}:${iguanaCorePort}/api/dex/getbalance?userpass=${sessionKey}&symbol=${coin}&address=${address}`,
refresh: `http://${cache.appConfig.host}:${iguanaCorePort}/api/basilisk/refresh?userpass=${sessionKey}&symbol=${coin}&address=${address}`
};
let _dexUrls = {};
for (let a = 0; a < callsArray.length; a++) {
_dexUrls[callsArray[a]] = dexUrls[callsArray[a]];
@ -455,41 +458,42 @@ cache.one = function(req, res, next) {
async.forEachOf(_dexUrls, function(dexUrl, key) {
var tooEarly = false;
if (outObj.basilisk[coin][address][key] &&
outObj.basilisk[coin][address][key].timestamp &&
(!skipTimeout && checkTimestamp(outObj.basilisk[coin][address][key].timestamp) < cacheGlobLifetime)) {
tooEarly = true;
outObj.basilisk[coin][address][key].status = 'done';
cache.io.emit('messages', {
'message': {
'shepherd': {
'method': 'cache-one',
'status': 'in progress',
'iguanaAPI': {
'method': key,
'coin': coin,
'address': address,
'status': 'done',
'resp': 'too early'
}
}
}
message: {
shepherd: {
method: 'cache-one',
status: 'in progress',
iguanaAPI: {
method: key,
coin: coin,
address: address,
status: 'done',
resp: 'too early',
},
},
},
});
}
if (!tooEarly) {
cache.io.emit('messages', {
'message': {
'shepherd': {
'method': 'cache-one',
'status': 'in progress',
'iguanaAPI': {
'method': key,
'coin': coin,
'address': address,
'status': 'in progress'
}
}
}
message: {
shepherd: {
method: 'cache-one',
status: 'in progress',
iguanaAPI: {
method: key,
coin: coin,
address: address,
status: 'in progress',
},
},
},
});
outObj.basilisk[coin][address][key].status = 'in progress';
request({
@ -500,25 +504,25 @@ cache.one = function(req, res, next) {
response.statusCode &&
response.statusCode === 200) {
cache.io.emit('messages', {
'message': {
'shepherd': {
'method': 'cache-one',
'status': 'in progress',
'iguanaAPI': {
'method': key,
'coin': coin,
'address': address,
'status': 'done',
'resp': body
}
}
}
message: {
shepherd: {
method: 'cache-one',
status: 'in progress',
iguanaAPI: {
method: key,
coin: coin,
address: address,
status: 'done',
resp: body,
},
},
},
});
// basilisk balance fallback
const _parsedJSON = JSON.parse(body);
if (key === 'getbalance' &&
coin === 'KMD'/* &&
coin === 'KMD'/* &&
((_parsedJSON && _parsedJSON.balance === 0) || body === [])*/) {
console.log('fallback to kmd explorer ======>');
request({
@ -559,15 +563,15 @@ cache.one = function(req, res, next) {
callStack[coin]--;
console.log(`${coin} _stack len ${callStack[coin]}`);
cache.io.emit('messages', {
'message': {
'shepherd': {
'method': 'cache-one',
'status': 'in progress',
'iguanaAPI': {
'currentStackLength': callStack[coin]
}
}
}
message: {
shepherd: {
method: 'cache-one',
status: 'in progress',
iguanaAPI: {
currentStackLength: callStack[coin],
},
},
},
});
checkCallStack();
@ -583,15 +587,15 @@ cache.one = function(req, res, next) {
callStack[coin]--;
console.log(`${coin} _stack len ${callStack[coin]}`);
cache.io.emit('messages', {
'message': {
'shepherd': {
'method': 'cache-one',
'status': 'in progress',
'iguanaAPI': {
'currentStackLength': callStack[coin]
}
}
}
message: {
shepherd: {
method: 'cache-one',
status: 'in progress',
iguanaAPI: {
currentStackLength: callStack[coin],
},
},
},
});
checkCallStack();
writeCache();
@ -602,15 +606,15 @@ cache.one = function(req, res, next) {
callStack[coin]--;
console.log(`${coin} _stack len ${callStack[coin]}`);
cache.io.emit('messages', {
'message': {
'shepherd': {
'method': 'cache-one',
'status': 'in progress',
'iguanaAPI': {
'currentStackLength': callStack[coin]
}
}
}
message: {
shepherd: {
method: 'cache-one',
status: 'in progress',
iguanaAPI: {
currentStackLength: callStack[coin],
},
},
},
});
checkCallStack();
}
@ -619,18 +623,18 @@ cache.one = function(req, res, next) {
function parseAddresses(coin, addrArray) {
cache.io.emit('messages', {
'message': {
'shepherd': {
'method': 'cache-one',
'status': 'in progress',
'iguanaAPI': {
'method': 'getaddressesbyaccount',
'coin': coin,
'status': 'done',
'resp': addrArray
}
}
}
message: {
shepherd: {
method: 'cache-one',
status: 'in progress',
iguanaAPI: {
method: 'getaddressesbyaccount',
coin: coin,
status: 'done',
resp: addrArray,
},
},
},
});
outObj.basilisk[coin].addresses = addrArray;
console.log(addrArray);
@ -649,15 +653,15 @@ cache.one = function(req, res, next) {
console.log(`${coin} stack len ${callStack[coin]}`);
cache.io.emit('messages', {
'message': {
'shepherd': {
'method': 'cache-one',
'status': 'in progress',
'iguanaAPI': {
'totalStackLength': callStack[coin]
}
}
}
message: {
shepherd: {
method: 'cache-one',
status: 'in progress',
iguanaAPI: {
totalStackLength: callStack[coin],
},
},
},
});
async.each(outObj.basilisk[coin].addresses, function(address) {
execDEXRequests(coin, address);
@ -687,17 +691,17 @@ cache.one = function(req, res, next) {
// update all available coin addresses
if (!address) {
cache.io.emit('messages', {
'message': {
'shepherd': {
'method': 'cache-one',
'status': 'in progress',
'iguanaAPI': {
'method': 'getaddressesbyaccount',
'coin': coin,
'status': 'in progress'
}
}
}
message: {
shepherd: {
method: 'cache-one',
status: 'in progress',
iguanaAPI: {
method: 'getaddressesbyaccount',
coin: coin,
status: 'in progress',
},
},
},
});
if (coin === 'all') {
@ -711,17 +715,17 @@ cache.one = function(req, res, next) {
response.statusCode === 200) {
console.log(JSON.parse(body).basilisk);
cache.io.emit('messages', {
'message': {
'shepherd': {
'method': 'cache-one',
'status': 'in progress',
'iguanaAPI': {
'method': 'allcoins',
'status': 'done',
'resp': body
}
}
}
message: {
shepherd: {
method: 'cache-one',
status: 'in progress',
iguanaAPI: {
method: 'allcoins',
status: 'done',
resp: body,
},
},
},
});
body = JSON.parse(body);
// basilisk coins
@ -737,17 +741,17 @@ cache.one = function(req, res, next) {
writeCache();
cache.io.emit('messages', {
'message': {
'shepherd': {
'method': 'cache-one',
'status': 'in progress',
'iguanaAPI': {
'method': 'getaddressesbyaccount',
'coin': coin,
'status': 'in progress'
}
}
}
message: {
shepherd: {
method: 'cache-one',
status: 'in progress',
iguanaAPI: {
method: 'getaddressesbyaccount',
coin: coin,
status: 'in progress',
},
},
},
});
getAddresses(coin);
@ -776,36 +780,36 @@ cache.one = function(req, res, next) {
console.log(`${coin} stack len ${callStack[coin]}`);
cache.io.emit('messages', {
'message': {
'shepherd': {
'method': 'cache-one',
'status': 'in progress',
'iguanaAPI': {
'totalStackLength': callStack[coin],
'currentStackLength': callStack[coin]
}
}
}
message: {
shepherd: {
method: 'cache-one',
status: 'in progress',
iguanaAPI: {
totalStackLength: callStack[coin],
currentStackLength: callStack[coin],
},
},
},
});
execDEXRequests(coin, address);
}
} else {
cache.io.emit('messages', {
'message': {
'shepherd': {
'method': 'cache-all',
'status': 'done',
'resp': 'internal error'
}
}
message: {
shepherd: {
method: 'cache-all',
status: 'done',
resp: 'internal error',
},
},
});
cacheCallInProgress = false;
}
} else {
res.end(JSON.stringify({
'msg': 'error',
'result': 'another call is in progress already'
msg: 'error',
result: 'another call is in progress already',
}));
}
};

969
routes/shepherd.js

File diff suppressed because it is too large
Loading…
Cancel
Save