Browse Source

Merge pull request #172 from SuperNETorg/master

master update
pkg_automation_electrum
ca333 7 years ago
committed by GitHub
parent
commit
580f04423a
  1. 28
      gui/agama-instance-error.html
  2. 24
      gui/app-closing.html
  3. 35
      gui/index.html
  4. 35
      gui/startup/agama-instance-error.html
  5. 31
      gui/startup/app-closing.html
  6. 72
      gui/startup/app-settings.html
  7. 69
      gui/startup/index.html
  8. 0
      gui/startup/main.html
  9. 86
      main.js
  10. 3
      make-patch.sh
  11. 2
      package.json
  12. 27
      routes/appConfig.js
  13. 696
      routes/shepherd.js
  14. 2
      version
  15. 2
      version_build

28
gui/agama-instance-error.html

@ -1,28 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="EasyDEX-GUI/assets/global/css/bootstrap.min.css">
<link rel="stylesheet" href="EasyDEX-GUI/assets/mainWindow/css/jRoll.min.css">
<link rel="stylesheet" href="EasyDEX-GUI/assets/mainWindow/css/loading.css">
<script type="text/javascript" src="EasyDEX-GUI/assets/mainWindow/js/module-hack.js"></script>
<script type="text/javascript" src="EasyDEX-GUI/assets/global/vendor/jquery/jquery.min.js"></script>
<script type="text/javascript" src="EasyDEX-GUI/assets/scripts/config.js"></script>
<script type="text/javascript" src="EasyDEX-GUI/assets/mainWindow/js/bluebird.min.js"></script>
<script type="text/javascript" src="EasyDEX-GUI/assets/mainWindow/js/loading.js"></script>
<script type="text/javascript" src="EasyDEX-GUI/assets/mainWindow/js/jRoll.min.js"></script>
<script>if (window.module) module = window.module;</script>
</head>
<body class="agamaMode">
<div class="text-center">
<div id="agamaMode">
<img src="EasyDEX-GUI/assets/mainWindow/img/agama-icon.svg" class="agama-logo" alt="Agama Wallet" width="80" height="100" />
<div id="agamaModeStatus">Another Agama instance is already running!</div>
<div>Please close all other instances and restart the app.</div>
<br />
<button onClick="quitApp()" class="btn btn-primary btn-close-app">Quit</button>
</div>
</div>
<script type="text/javascript" src="EasyDEX-GUI/assets/mainWindow/js/init.js"></script>
</body>
</html>

24
gui/app-closing.html

@ -1,24 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="EasyDEX-GUI/assets/global/css/bootstrap.min.css">
<link rel="stylesheet" href="EasyDEX-GUI/assets/mainWindow/css/jRoll.min.css">
<link rel="stylesheet" href="EasyDEX-GUI/assets/mainWindow/css/loading.css">
<script type="text/javascript" src="EasyDEX-GUI/assets/mainWindow/js/module-hack.js"></script>
<script type="text/javascript" src="EasyDEX-GUI/assets/global/vendor/jquery/jquery.min.js"></script>
<script type="text/javascript" src="EasyDEX-GUI/assets/scripts/config.js"></script>
<script type="text/javascript" src="EasyDEX-GUI/assets/mainWindow/js/bluebird.min.js"></script>
<script type="text/javascript" src="EasyDEX-GUI/assets/mainWindow/js/loading.js"></script>
<script type="text/javascript" src="EasyDEX-GUI/assets/mainWindow/js/jRoll.min.js"></script>
<script>if (window.module) module = window.module;</script>
</head>
<body class="agamaMode">
<div class="text-center">
<div id="agamaMode" class="app-closing">
<img src="EasyDEX-GUI/assets/mainWindow/img/agama-icon.svg" class="agama-logo" alt="Agama Wallet" width="80" height="100" />
<div id="agamaModeStatus">App is closing. Please wait...</div>
</div>
</div>
</body>
</html>

35
gui/index.html

@ -1,35 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="EasyDEX-GUI/assets/global/css/bootstrap.min.css">
<link rel="stylesheet" href="EasyDEX-GUI/assets/mainWindow/css/jRoll.min.css">
<link rel="stylesheet" href="EasyDEX-GUI/assets/mainWindow/css/loading.css">
<script type="text/javascript" src="EasyDEX-GUI/assets/mainWindow/js/module-hack.js"></script>
<script type="text/javascript" src="EasyDEX-GUI/assets/global/vendor/jquery/jquery.min.js"></script>
<script type="text/javascript" src="EasyDEX-GUI/assets/scripts/config.js"></script>
<script type="text/javascript" src="EasyDEX-GUI/assets/mainWindow/js/bluebird.min.js"></script>
<script type="text/javascript" src="EasyDEX-GUI/assets/mainWindow/js/loading.js"></script>
<script type="text/javascript" src="EasyDEX-GUI/assets/mainWindow/js/jRoll.min.js"></script>
<script>if (window.module) module = window.module;</script>
</head>
<body class="agamaMode">
<div class="text-center">
<!--div id="normalStart">
<div class="loader-block">
<div id="loading_status_text">Starting Wallet. Please wait...</div>
<div id="loading_sub_status_text"></div>
<div id="loading_sub_status_output_text"></div>
</div>
<div id="pulse" class="pulse-loader"></div>
</div-->
<div id="agamaMode">
<img src="EasyDEX-GUI/assets/mainWindow/img/agama-icon.svg" class="agama-logo" alt="Agama Wallet" width="80" height="100" />
<div id="agamaModeStatus">Choose Agama mode</div>
<button onClick="closeMainWindow()" class="btn btn-primary">Native only</button>
<button onClick="normalStart()" class="btn btn-primary">Normal start</button>
</div>
</div>
<script type="text/javascript" src="EasyDEX-GUI/assets/mainWindow/js/init.js"></script>
</body>
</html>

35
gui/startup/agama-instance-error.html

@ -0,0 +1,35 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="../EasyDEX-GUI/assets/global/css/bootstrap.min.css">
<link rel="stylesheet" href="../EasyDEX-GUI/assets/mainWindow/css/jRoll.min.css">
<link rel="stylesheet" href="../EasyDEX-GUI/assets/mainWindow/css/loading.css">
<script type="text/javascript" src="../EasyDEX-GUI/assets/mainWindow/js/module-hack.js"></script>
<script type="text/javascript" src="../EasyDEX-GUI/assets/global/vendor/jquery/jquery.min.js"></script>
<script type="text/javascript" src="../EasyDEX-GUI/assets/scripts/config.js"></script>
<script type="text/javascript" src="../EasyDEX-GUI/assets/mainWindow/js/bluebird.min.js"></script>
<script type="text/javascript" src="../EasyDEX-GUI/assets/mainWindow/js/loading.js"></script>
<script type="text/javascript" src="../EasyDEX-GUI/assets/mainWindow/js/jRoll.min.js"></script>
<script>if (window.module) module = window.module;</script>
</head>
<body class="agamaMode agama-default-window-height">
<div class="text-center">
<div id="agamaMode">
<img
src="../EasyDEX-GUI/assets/mainWindow/img/agama-icon.svg"
class="agama-logo"
alt="Agama Wallet"
width="80"
height="100" />
<div id="agamaModeStatus">Another Agama instance is already running!</div>
<div>Please close all other instances and restart the app.</div>
<br />
<button
onClick="quitApp()"
class="btn btn-primary btn-close-app">Quit</button>
</div>
</div>
<script type="text/javascript" src="../EasyDEX-GUI/assets/mainWindow/js/init.js"></script>
</body>
</html>

31
gui/startup/app-closing.html

@ -0,0 +1,31 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="../EasyDEX-GUI/assets/global/css/bootstrap.min.css">
<link rel="stylesheet" href="../EasyDEX-GUI/assets/mainWindow/css/jRoll.min.css">
<link rel="stylesheet" href="../EasyDEX-GUI/assets/mainWindow/css/loading.css">
<script type="text/javascript" src="../EasyDEX-GUI/assets/mainWindow/js/module-hack.js"></script>
<script type="text/javascript" src="../EasyDEX-GUI/assets/global/vendor/jquery/jquery.min.js"></script>
<script type="text/javascript" src="../EasyDEX-GUI/assets/scripts/config.js"></script>
<script type="text/javascript" src="../EasyDEX-GUI/assets/mainWindow/js/bluebird.min.js"></script>
<script type="text/javascript" src="../EasyDEX-GUI/assets/mainWindow/js/loading.js"></script>
<script type="text/javascript" src="../EasyDEX-GUI/assets/mainWindow/js/jRoll.min.js"></script>
<script>if (window.module) module = window.module;</script>
</head>
<body class="agamaMode agama-default-window-height">
<div class="text-center">
<div
id="agamaMode"
class="app-closing">
<img
src="../EasyDEX-GUI/assets/mainWindow/img/agama-icon.svg"
class="agama-logo"
alt="Agama Wallet"
width="80"
height="100" />
<div id="agamaModeStatus">App is closing. Please wait...</div>
</div>
</div>
</body>
</html>

72
gui/startup/app-settings.html

@ -0,0 +1,72 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="../EasyDEX-GUI/assets/global/css/bootstrap.min.css">
<link rel="stylesheet" href="../EasyDEX-GUI/assets/mainWindow/css/jRoll.min.css">
<link rel="stylesheet" href="../EasyDEX-GUI/assets/mainWindow/css/loading.css">
<script type="text/javascript" src="../EasyDEX-GUI/assets/mainWindow/js/module-hack.js"></script>
<script type="text/javascript" src="../EasyDEX-GUI/assets/global/vendor/jquery/jquery.min.js"></script>
<script type="text/javascript" src="../EasyDEX-GUI/assets/scripts/config.js"></script>
<script type="text/javascript" src="../EasyDEX-GUI/assets/mainWindow/js/bluebird.min.js"></script>
<script type="text/javascript" src="../EasyDEX-GUI/assets/mainWindow/js/loading.js"></script>
<script type="text/javascript" src="../EasyDEX-GUI/assets/mainWindow/js/jRoll.min.js"></script>
<script>if (window.module) module = window.module;</script>
</head>
<body class="agamaMode agama-app-settings-window">
<div id="debugOut"></div>
<div class="text-center">
<div
id="agamaMode"
class="app-settings">
<div
class="btn-close"
onClick="closeSettingsWindow()">
<img src="../EasyDEX-GUI/assets/mainWindow/img/fa-close.png">
</div>
<img
src="../EasyDEX-GUI/assets/mainWindow/img/agama-icon.svg"
class="agama-logo"
alt="Agama Wallet"
width="80"
height="100" />
<div id="agamaModeStatus">App configuration (selected options only)</div>
<div
id="agamaConfigBlock"
class="agama-config-block"></div>
<!-- debug overlay -->
<div
id="debugOverlay"
class="debug-overlay hide"></div>
<div class="settings-buttons-block">
<button
onClick="testBins('komodod')"
class="btn btn-info pull-left">Test binaries</button>
<button
onClick="handleSaveSettings()"
class="btn btn-primary margin-right-20">Save</button>
<button
onClick="initSettingsForm()"
class="btn btn-primary">Reset changes</button>
<button
onClick="setDefaultAppSettings()"
class="btn btn-primary">Reset all settings</button>
</div>
<!-- toaster -->
<div
id="toast-container"
class="single-toast toast-bottom-right hide">
<div class="toast toast-success">
<button
class="toast-close-button"
onClick="hideToastImmediate()">×</button>
<div class="toast-title">Settings notification</div>
<div class="toast-message"></div>
</div>
</div>
<button onClick="reloadSettingsWindow()" class="btn btn-primary" style="margin-top: 20px">Reload</button>
</div>
<script>initSettingsForm()</script>
</div>
</body>
</html>

69
gui/startup/index.html

@ -0,0 +1,69 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="../EasyDEX-GUI/assets/global/css/bootstrap.min.css">
<link rel="stylesheet" href="../EasyDEX-GUI/assets/mainWindow/css/jRoll.min.css">
<link rel="stylesheet" href="../EasyDEX-GUI/assets/mainWindow/css/loading.css">
<script type="text/javascript" src="../EasyDEX-GUI/assets/mainWindow/js/module-hack.js"></script>
<script type="text/javascript" src="../EasyDEX-GUI/assets/global/vendor/jquery/jquery.min.js"></script>
<script type="text/javascript" src="../EasyDEX-GUI/assets/scripts/config.js"></script>
<script type="text/javascript" src="../EasyDEX-GUI/assets/mainWindow/js/bluebird.min.js"></script>
<script type="text/javascript" src="../EasyDEX-GUI/assets/mainWindow/js/loading.js"></script>
<script type="text/javascript" src="../EasyDEX-GUI/assets/mainWindow/js/jRoll.min.js"></script>
<script>if (window.module) module = window.module;</script>
</head>
<body class="agamaMode">
<div class="text-center">
<div id="agamaMode">
<div
class="btn-close"
onClick="quitApp()">
<img src="../EasyDEX-GUI/assets/mainWindow/img/fa-close.png">
</div>
<img
src="../EasyDEX-GUI/assets/mainWindow/img/agama-icon.svg"
class="agama-logo"
alt="Agama Wallet"
width="80"
height="100" />
<div id="agamaModeStatus">Choose Agama mode</div>
<button
id="nativeOnlyBtn"
onClick="closeMainWindow(true)"
class="btn btn-primary btn-mode btn-native">
<img src="../EasyDEX-GUI/assets/mainWindow/img/fa-cube.png"> KMD native
</button>
<div
id="nativeOnlyBtnCarret"
class="btn btn-primary btn-caret margin-right-20"
onClick="toggleDropdown()">
<img src="../EasyDEX-GUI/assets/mainWindow/img/fa-caret-down.png">
</div>
<ul class="dropdown-menu hide">
<li onClick="closeMainWindow()">
<a>KMD + REVS + JUMBLR</a>
</li>
<li onClick="closeMainWindow(null, true)">
<a>Custom</a>
</li>
</ul>
<button
id="normalStartBtn"
onClick="normalStart()"
class="btn btn-primary btn-mode">
<img src="../EasyDEX-GUI/assets/mainWindow/img/fa-cubes.png"> All modes
</button>
<div class="margin-top-20">
<button
id="settingsBtn"
onClick="openSettingsWindow()"
class="btn btn-info btn-mode">
<img src="../EasyDEX-GUI/assets/mainWindow/img/fa-cogs.png"> Settings
</button>
</div>
</div>
</div>
<script type="text/javascript" src="../EasyDEX-GUI/assets/mainWindow/js/init.js"></script>
</body>
</html>

0
gui/main.html → gui/startup/main.html

86
main.js

@ -71,6 +71,11 @@ shepherd.writeLog(`os_release: ${os.release()}`);
shepherd.writeLog(`os_type: ${os.type()}`);
var appConfig = shepherd.loadLocalConfig(); // load app config
appConfig['daemonOutput'] = false; // shadow setting
let __defaultAppSettings = require('./routes/appConfig.js').config;
__defaultAppSettings['daemonOutput'] = false; // shadow setting
const _defaultAppSettings = __defaultAppSettings;
shepherd.writeLog(`app started in ${(appConfig.dev ? 'dev mode' : ' user mode')}`);
@ -131,7 +136,9 @@ let willQuitApp = false;
let mainWindow;
let loadingWindow;
let appCloseWindow;
let appSettingsWindow;
let closeAppAfterLoading = false;
let forceQuitApp = false;
const _zcashParamsExist = shepherd.zcashParamsExist();
module.exports = guiapp;
@ -151,7 +158,7 @@ function createLoadingWindow() {
try {
loadingWindow = new BrowserWindow({
width: 500,
height: 300,
height: 335,
frame: false,
icon: iguanaIcon,
show: false,
@ -190,10 +197,10 @@ function createLoadingWindow() {
console.log(`guiapp and sockets.io are listening on port ${appConfig.agamaPort + 1}`);
shepherd.writeLog(`guiapp and sockets.io are listening on port ${appConfig.agamaPort + 1}`);
});
loadingWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort + 1}/gui/agama-instance-error.html`);
loadingWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort + 1}/gui/startup/agama-instance-error.html`);
console.log('another agama app is already running');
}
})
});
shepherd.setIO(io); // pass sockets object to shepherd router
shepherd.setVar('appBasicInfo', appBasicInfo);
@ -202,9 +209,11 @@ function createLoadingWindow() {
loadingWindow.createWindow = createWindow; // expose createWindow to front-end scripts
loadingWindow.appConfig = appConfig;
loadingWindow.forseCloseApp = forseCloseApp;
loadingWindow.createAppSettingsWindow = createAppSettingsWindow;
loadingWindow.startKMDNative = shepherd.startKMDNative;
// load our index.html (i.e. easyDEX GUI)
loadingWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/`);
loadingWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/startup`);
loadingWindow.webContents.on('did-finish-load', function() {
setTimeout(function() {
loadingWindow.show();
@ -223,6 +232,7 @@ function createLoadingWindow() {
});
loadingWindow.on('close', (e) => {
if (!forseCloseApp) {
if (willQuitApp) {
/* the user tried to quit the app */
loadingWindow = null;
@ -231,16 +241,25 @@ function createLoadingWindow() {
closeAppAfterLoading = true;
e.preventDefault();
}
}
});
}
// close app
function forseCloseApp() {
loadingWindow = null;
mainWindow = null;
forceQuitApp = true;
app.quit();
}
function setDefaultAppSettings() {
shepherd.saveLocalAppConf(_defaultAppSettings);
}
function updateAppSettings(_settings) {
shepherd.saveLocalAppConf(_settings);
appConfig = _settings;
}
app.on('ready', createLoadingWindow);
function createAppCloseWindow() {
@ -253,7 +272,7 @@ function createAppCloseWindow() {
show: false,
});
appCloseWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/app-closing.html`);
appCloseWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/startup/app-closing.html`);
appCloseWindow.webContents.on('did-finish-load', function() {
setTimeout(function() {
@ -262,7 +281,49 @@ function createAppCloseWindow() {
});
}
function reloadSettingsWindow() {
appSettingsWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/startup/app-settings.html`);
}
function createAppSettingsWindow() {
// initialise window
appSettingsWindow = new BrowserWindow({ // dirty hack to prevent main window flash on quit
width: 750,
height: 820,
frame: false,
icon: iguanaIcon,
show: false,
});
appSettingsWindow.appConfig = appConfig;
appSettingsWindow.appConfigSchema = shepherd.appConfigSchema;
appSettingsWindow.defaultAppSettings = _defaultAppSettings;
appSettingsWindow.destroyAppSettingsWindow = destroyAppSettingsWindow;
appSettingsWindow.reloadSettingsWindow = reloadSettingsWindow;
appSettingsWindow.testLocation = shepherd.testLocation;
appSettingsWindow.setDefaultAppSettings = setDefaultAppSettings;
appSettingsWindow.updateAppSettings = updateAppSettings;
appSettingsWindow.testBins = shepherd.testBins;
appSettingsWindow.zcashParamsExist = _zcashParamsExist;
appSettingsWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/startup/app-settings.html`);
appSettingsWindow.webContents.on('did-finish-load', function() {
setTimeout(function() {
appSettingsWindow.show();
}, 40);
});
}
function destroyAppSettingsWindow() {
appSettingsWindow.hide();
appSettingsWindow = null;
}
function createWindow(status) {
if (appSettingsWindow) {
destroyAppSettingsWindow();
}
if (status === 'open') {
require(path.join(__dirname, 'private/mainmenu'));
@ -326,7 +387,7 @@ function createWindow(status) {
mainWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/EasyDEX-GUI/`);
}
} else {
mainWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/main.html`);
mainWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/startup/main.html`);
}
mainWindow.webContents.on('context-menu', (e, params) => { // context-menu returns params
@ -349,7 +410,7 @@ function createWindow(status) {
shepherd.writeLog('exiting app...');
shepherd.dumpCacheBeforeExit();
shepherd.quitKomodod();
shepherd.quitKomodod(1000);
pm2.connect(true, function(err) {
console.log('connecting to pm2...');
@ -468,7 +529,8 @@ app.on('window-all-closed', function() {
// Calling event.preventDefault() will prevent the default behaviour, which is terminating the application.
app.on('before-quit', function(event) {
console.log('before-quit');
if (mainWindow === null && loadingWindow != null) { // mainWindow not intitialised and loadingWindow not dereferenced
shepherd.killRogueProcess('iguana'); // kill any rogue iguana core instances
if (!forceQuitApp && mainWindow === null && loadingWindow != null) { // mainWindow not intitialised and loadingWindow not dereferenced
// loading window is still open
console.log('before-quit prevented');
shepherd.writeLog('quit app after loading is done');
@ -482,7 +544,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) {
if (mainWindow === null && loadingWindow != null) {
if (!forceQuitApp && mainWindow === null && loadingWindow != null) {
// loading window is still open
console.log('will-quit while loading window active');
event.preventDefault();
@ -492,7 +554,7 @@ 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) {
if (mainWindow === null && loadingWindow != null) {
if (!forceQuitApp && mainWindow === null && loadingWindow != null) {
console.log('quit while loading window active');
event.preventDefault();
}

3
make-patch.sh

@ -16,8 +16,7 @@ mkdir patch/gui/EasyDEX-GUI/react
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 -R gui/startup patch/gui/startup
cp ./main.js patch
cp ./version patch
cp -R routes patch/routes

2
package.json

@ -1,7 +1,7 @@
{
"name": "agama_app",
"productName": "Agama",
"version": "0.1.6",
"version": "0.2.22",
"description": "Agama Desktop App",
"main": "main.js",
"scripts": {

27
routes/appConfig.js

@ -1,5 +1,5 @@
const appConfig = {
config: {
config: { // default config
edexGuiOnly: true,
iguanaGuiOnly: false,
manualIguanaStart: false,
@ -23,6 +23,7 @@ const appConfig = {
},
iguanaLessMode: true,
roundValues: false,
experimentalFeatures: false,
dataDir: '',
},
schema: {
@ -66,6 +67,7 @@ const appConfig = {
},
iguanaCorePort: {
display: true,
initDisplay: true,
type: 'number',
displayName: 'Iguana Core Port',
info: 'Default Iguana Core Port. Change it if you have conflicts with other applications.',
@ -92,8 +94,9 @@ const appConfig = {
},
dev: {
display: true,
initDisplay: true,
displayName: 'Developer mode',
info: 'Enable developer mode.',
info: 'Enable developer mode',
type: 'boolean',
},
v2: {
@ -102,12 +105,14 @@ const appConfig = {
},
useBasiliskInstance: {
display: true,
initDisplay: true,
displayName: 'Iguana Core Basilisk Instance',
info: 'Enable dedicated Iguana Core instance to handle all Basilisk network requests',
type: 'boolean',
},
debug: {
display: true,
initDisplay: true,
displayName: 'Debug',
info: 'Enable debug output',
type: 'boolean',
@ -137,15 +142,29 @@ const appConfig = {
roundValues: {
display: true,
displayName: 'Enable amount rounding',
info: 'Round \"dust\" amounts to save screen space.',
info: 'Round \"dust\" amounts to save screen space',
type: 'boolean',
},
experimentalFeatures: {
display: true,
initDisplay: true,
displayName: 'Enable experimental features',
type: 'boolean',
},
dataDir: {
display: true,
initDisplay: true,
displayName: 'Komodo data directory',
info: 'The data directory is the location where Komodo data files are stored, including the wallet data file.',
info: 'The data directory is the location where Komodo data files are stored, including the wallet data file',
type: 'folder',
},
daemonOutput: {
display: false,
initDisplay: true,
displayName: 'Output daemon prints (debug)',
info: 'Output daemon prints to GUI for debug purposes',
type: 'boolean',
},
},
};

696
routes/shepherd.js

@ -35,7 +35,8 @@ var ps = require('ps-node'),
syncOnlyIguanaInstanceInfo = {},
syncOnlyInstanceInterval = -1,
guiLog = {},
rpcConf = {};
rpcConf = {},
lockDownAddCoin = false;
shepherd.appConfig = _appConfig.config;
@ -48,6 +49,7 @@ if (os.platform() === 'darwin') {
fixPath();
var iguanaBin = path.join(__dirname, '../assets/bin/osx/iguana'),
iguanaDir = `${process.env.HOME}/Library/Application Support/iguana`,
iguanaTestDir = `${process.env.HOME}/Library/Application Support/iguana/test`,
iguanaConfsDir = `${iguanaDir}/confs`,
komododBin = path.join(__dirname, '../assets/bin/osx/komodod'),
komodocliBin = path.join(__dirname, '../assets/bin/osx/komodo-cli'),
@ -61,6 +63,7 @@ if (os.platform() === 'darwin') {
if (os.platform() === 'linux') {
var iguanaBin = path.join(__dirname, '../assets/bin/linux64/iguana'),
iguanaDir = `${process.env.HOME}/.iguana`,
iguanaTestDir = `${process.env.HOME}/.iguana/test`,
iguanaConfsDir = `${iguanaDir}/confs`,
iguanaIcon = path.join(__dirname, '/assets/icons/agama_icons/128x128.png'),
komododBin = path.join(__dirname, '../assets/bin/linux64/komodod'),
@ -74,6 +77,8 @@ if (os.platform() === 'win32') {
iguanaBin = path.normalize(iguanaBin);
iguanaDir = `${process.env.APPDATA}/iguana`;
iguanaDir = path.normalize(iguanaDir);
iguanaTestDir = `${process.env.APPDATA}/iguana/test`;
iguanaTestDir = path.normalize(iguanaTestDir);
iguanaConfsDir = `${process.env.APPDATA}/iguana/confs`;
iguanaConfsDir = path.normalize(iguanaConfsDir);
iguanaIcon = path.join(__dirname, '/assets/icons/agama_icons/agama_app_icon.ico'),
@ -93,17 +98,612 @@ shepherd.defaultAppConfig = Object.assign({}, shepherd.appConfig);
shepherd.coindInstanceRegistry = coindInstanceRegistry;
shepherd.startKMDNative = function(selection) {
if (selection === 'KMD') {
const herdData = {
'ac_name': 'komodod',
'ac_options': [
'-daemon=0',
'-addnode=78.47.196.146',
]
};
const options = {
url: `http://127.0.0.1:${shepherd.appConfig.agamaPort}/shepherd/herd`,
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
'herd': 'komodod',
'options': herdData,
})
};
request(options, function(error, response, body) {
if (response &&
response.statusCode &&
response.statusCode === 200) {
//resolve(body);
} else {
//resolve(body);
}
});
} else {
const herdData = [{
'ac_name': 'komodod',
'ac_options': [
'-daemon=0',
'-addnode=78.47.196.146',
]
}, {
'ac_name': 'REVS',
'ac_options': [
'-daemon=0',
'-server',
`-ac_name=REVS`,
'-addnode=78.47.196.146',
'-ac_supply=1300000'
]
}, {
'ac_name': 'JUMBLR',
'ac_options': [
'-daemon=0',
'-server',
`-ac_name=JUMBLR`,
'-addnode=78.47.196.146',
'-ac_supply=999999'
]
}];
for (let i = 0; i < herdData.length; i++) {
setTimeout(() => {
const options = {
url: `http://127.0.0.1:${shepherd.appConfig.agamaPort}/shepherd/herd`,
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
'herd': 'komodod',
'options': herdData[i],
})
};
request(options, function(error, response, body) {
if (response &&
response.statusCode &&
response.statusCode === 200) {
//resolve(body);
} else {
//resolve(body);
}
});
}, 100);
}
}
};
/*
* Combined native dashboard update same as in gui
* type: GET
* params: coin
*/
shepherd.post('/native/dashboard/update', function(req, res, next) {
let _returnObj = {
getinfo: {},
listtransactions: [],
z_gettotalbalance: {},
z_getoperationstatus: {},
listunspent: {},
addresses: {},
};
const _promiseStack = [
'getinfo',
'listtransactions',
'z_gettotalbalance',
'z_getoperationstatus'
];
const _coin = req.body.coin;
function getAddressesNative(coin) {
const type = [
'public',
'private'
];
Promise.all(type.map((_type, index) => {
return new Promise((resolve, reject) => {
_bitcoinRPC(
coin,
_type === 'public' ? 'getaddressesbyaccount' : 'z_listaddresses',
['']
).then(function(_json) {
resolve(JSON.parse(_json).result);
});
});
}))
.then(result => {
function calcBalance(result, json) {
if (json &&
json.length) {
const allAddrArray = json.map(res => res.address).filter((x, i, a) => a.indexOf(x) == i);
for (let a = 0; a < allAddrArray.length; a++) {
const filteredArray = json.filter(res => res.address === allAddrArray[a]).map(res => res.amount);
let isNewAddr = true;
for (let x = 0; x < result.length && isNewAddr; x++) {
for (let y = 0; y < result[x].length && isNewAddr; y++) {
if (allAddrArray[a] === result[x][y]) {
isNewAddr = false;
}
}
}
if (isNewAddr &&
(allAddrArray[a].substring(0, 2) === 'zc' ||
allAddrArray[a].substring(0, 2) === 'zt')) {
result[1][result[1].length] = allAddrArray[a];
} else {
result[0][result[0].length] = allAddrArray[a];
}
}
}
// remove addr duplicates
if (result[0]) {
result[0] = result[0].filter(function(elem, pos) {
return result[0].indexOf(elem) === pos;
});
}
if (result[1]) {
result[1] = result[1].filter(function(elem, pos) {
return result[1].indexOf(elem) === pos;
});
}
let newAddressArray = [];
for (let a = 0; a < result.length; a++) {
newAddressArray[a] = [];
if (result[a]) {
for (let b = 0; b < result[a].length; b++) {
let filteredArray;
filteredArray = json.filter(res => res.address === result[a][b]).map(res => res.amount);
let sum = 0;
for (let i = 0; i < filteredArray.length; i++) {
sum += filteredArray[i];
}
newAddressArray[a][b] = {
address: result[a][b],
amount: sum,
type: a === 0 ? 'public': 'private',
};
}
}
}
// get zaddr balance
if (result[1] &&
result[1].length) {
Promise.all(result[1].map((_address, index) => {
return new Promise((resolve, reject) => {
_bitcoinRPC(coin, 'z_getbalance', [_address])
.then(function(__json) {
__json = JSON.parse(__json);
if (__json &&
__json.error) {
resolve(0);
} else {
resolve(__json.result)
newAddressArray[1][index] = {
address: _address,
amount: __json.result,
type: 'private',
};
}
});
});
}))
.then(zresult => {
_returnObj.addresses = {
public: newAddressArray[0],
private: newAddressArray[1],
};
const returnObj = {
msg: 'success',
result: _returnObj,
};
res.end(JSON.stringify(returnObj));
});
} else {
_returnObj.addresses = {
public: newAddressArray[0],
private: newAddressArray[1],
};
const returnObj = {
msg: 'success',
result: _returnObj,
};
res.end(JSON.stringify(returnObj));
}
}
_bitcoinRPC(coin, 'listunspent')
.then(function(__json) {
_returnObj.listunspent = JSON.parse(__json);
calcBalance(
result,
JSON.parse(__json).result
);
});
})
}
function _bitcoinRPC(coin, cmd, params) {
return new Promise(function(resolve, reject) {
let _payload;
if (params) {
_payload = {
mode: null,
chain: coin,
cmd: cmd,
params: params,
};
} else {
_payload = {
mode: null,
chain: coin,
cmd: cmd,
};
}
const options = {
url: `http://127.0.0.1:${shepherd.appConfig.agamaPort}/shepherd/cli`,
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ payload: _payload })
};
request(options, function(error, response, body) {
if (response &&
response.statusCode &&
response.statusCode === 200) {
resolve(body);
} else {
resolve(body);
}
});
});
}
Promise.all(_promiseStack.map((_call, index) => {
return new Promise((resolve, reject) => {
_bitcoinRPC(
_coin,
_call
)
.then(function(json) {
_returnObj[_call] = JSON.parse(json);
resolve(json);
});
});
}))
.then(result => {
getAddressesNative(_coin);
});
});
// TODO: test functions are wip
shepherd.testNearestIguanaPort = function() {
return new Promise(function(resolve, reject) {
const port = shepherd.appConfig.iguanaCorePort;
portscanner.findAPortNotInUse(port, port + 100, '127.0.0.1', function(error, _port) {
resolve(_port);
});
});
}
shepherd.testClearAll = function() {
return new Promise(function(resolve, reject) {
fs.removeSync(`${iguanaTestDir}`);
resolve('done');
});
}
shepherd.testBins = function(daemonName) {
return new Promise(function(resolve, reject) {
const _bins = {
komodod: komododBin,
komodoCli: komodocliBin,
iguana: iguanaBin,
};
const _arg = null;
let _pid;
console.log('testBins exec ' + _bins[daemonName]);
if (!fs.existsSync(iguanaTestDir)) {
fs.mkdirSync(iguanaTestDir);
}
if (daemonName === 'iguana') {
shepherd.killRogueProcess('iguana');
}
try {
_fs.access(`${iguanaTestDir}/${daemonName}Test.log`, fs.constants.R_OK, function(err) {
if (!err) {
_fs.unlink(`${iguanaTestDir}/${daemonName}Test.log`);
} else {
console.log(`path ${iguanaTestDir}/${daemonName}Test.log doesnt exist`);
}
});
} catch (e) {}
if (daemonName === 'iguana') {
pm2.connect(true,function(err) { //start up pm2 god
if (err) {
console.error(err);
process.exit(2);
}
console.log(`iguana core port ${shepherd.appConfig.iguanaCorePort}`);
shepherd.writeLog(`iguana core port ${shepherd.appConfig.iguanaCorePort}`);
pm2.start({
script: iguanaBin, // path to binary
name: 'iguana',
exec_mode : 'fork',
args: [`-port=${shepherd.appConfig.iguanaCorePort}`],
output: `${iguanaTestDir}/iguanaTest.log`,
mergeLogs: true,
cwd: iguanaDir // set correct iguana directory
}, function(err, apps) {
if (apps[0] &&
apps[0].process &&
apps[0].process.pid) {
console.log(`test: got iguana instance pid = ${apps[0].process.pid}`);
shepherd.writeLog(`test: iguana core started at port ${shepherd.appConfig.iguanaCorePort} pid ${apps[0].process.pid}`);
} else {
console.log(`test: unable to start iguana core at port ${shepherd.appConfig.iguanaCorePort}`);
}
pm2.disconnect(); // Disconnect from PM2
if (err) {
shepherd.writeLog(`test: iguana core port ${shepherd.appConfig.iguanaCorePort}`);
console.log(`test: iguana fork error: ${err}`);
throw err;
}
});
});
setTimeout(function() {
pm2.delete('iguana');
const _iguanaTestRunLog = fs.readFileSync(`${iguanaTestDir}/iguanaTest.log`, 'utf8');
if (_iguanaTestRunLog.indexOf('iguana main') > -1 &&
_iguanaTestRunLog.indexOf('Basilisk initialized') > -1) {
let _portTest = 'unknown';
if (_iguanaTestRunLog.indexOf(`iguana_rpcloop 127.0.0.1:${shepherd.appConfig.iguanaCorePort}`) > -1) {
_portTest = 'passed';
}
if (_iguanaTestRunLog.indexOf(`ERROR BINDING PORT.${shepherd.appConfig.iguanaCorePort}`) > -1) {
_portTest = 'failed';
}
resolve({
res: 'success',
port: _portTest,
iguanaPort: shepherd.appConfig.iguanaCorePort,
});
} else {
resolve({ res: 'error' });
}
}, 30000);
} else if (daemonName === 'komodod') {
try {
_fs.access(`${iguanaTestDir}/debug.log`, fs.constants.R_OK, function(err) {
if (!err) {
_fs.unlinkSync(`${iguanaTestDir}/db.log`);
_fs.unlinkSync(`${iguanaTestDir}/debug.log`);
_fs.unlinkSync(`${iguanaTestDir}/komodo.conf`);
_fs.unlinkSync(`${iguanaTestDir}/komodod.pid`);
_fs.unlinkSync(`${iguanaTestDir}/komodostate`);
_fs.unlinkSync(`${iguanaTestDir}/realtime`);
_fs.unlinkSync(`${iguanaTestDir}/wallet.dat`);
_fs.unlinkSync(`${iguanaTestDir}/.lock`);
fs.removeSync(`${iguanaTestDir}/blocks`);
fs.removeSync(`${iguanaTestDir}/chainstate`);
fs.removeSync(`${iguanaTestDir}/database`);
execKomodod();
} else {
console.log(`test: nothing to remove in ${iguanaTestDir}`);
execKomodod();
}
});
} catch (e) {}
function execKomodod() {
let _komododTest = {
port: 'unknown',
start: 'unknown',
getinfo: 'unknown',
errors: {
assertFailed: false,
zcashParams: false,
},
};
const _komodoConf = 'rpcuser=user83f3afba8d714993\n' +
'rpcpassword=0d4430ca1543833e35bce5a0cc9e16b3\n' +
'server=1\n' +
'addnode=78.47.196.146\n' +
'addnode=5.9.102.210\n' +
'addnode=178.63.69.164\n' +
'addnode=88.198.65.74\n' +
'addnode=5.9.122.241\n' +
'addnode=144.76.94.3\n' +
'addnode=144.76.94.38\n' +
'addnode=89.248.166.91\n' +
'addnode=148.251.57.148\n' +
'addnode=149.56.28.84\n' +
'addnode=176.9.26.39\n' +
'addnode=94.102.63.199\n' +
'addnode=94.102.63.200\n' +
'addnode=104.255.64.3\n' +
'addnode=221.121.144.140\n' +
'addnode=103.18.58.150\n' +
'addnode=103.18.58.146\n' +
'addnode=213.202.253.10\n' +
'addnode=185.106.121.32\n' +
'addnode=27.100.36.201\n';
fs.writeFile(`${iguanaTestDir}/komodo.conf`, _komodoConf, function(err) {
if (err) {
console.log(`test: error writing komodo conf in ${iguanaTestDir}`);
}
});
portscanner.checkPortStatus('7771', '127.0.0.1', function(error, status) {
// Status is 'open' if currently in use or 'closed' if available
if (status === 'closed') {
_komododTest.port = 'passed';
} else {
_komododTest.port = 'failed';
}
});
pm2.connect(true,function(err) { //start up pm2 god
if (err) {
console.error(err);
process.exit(2);
}
pm2.start({
script: komododBin, // path to binary
name: 'komodod',
exec_mode : 'fork',
args: [
'-daemon=0',
'-addnode=78.47.196.146',
`-datadir=${iguanaTestDir}/`
],
output: `${iguanaTestDir}/komododTest.log`,
mergeLogs: true,
}, function(err, apps) {
if (apps[0] &&
apps[0].process &&
apps[0].process.pid) {
_komododTest.start = 'success';
console.log(`test: got komodod instance pid = ${apps[0].process.pid}`);
shepherd.writeLog(`test: komodod started with pid ${apps[0].process.pid}`);
} else {
_komododTest.start = 'failed';
console.log(`unable to start komodod`);
}
pm2.disconnect(); // Disconnect from PM2
if (err) {
shepherd.writeLog(`test: error starting komodod`);
console.log(`komodod fork err: ${err}`);
throw err;
}
});
});
setTimeout(function() {
const options = {
url: `http://localhost:7771`,
method: 'POST',
auth: {
user: 'user83f3afba8d714993',
pass: '0d4430ca1543833e35bce5a0cc9e16b3',
},
body: JSON.stringify({
agent: 'bitcoinrpc',
method: 'getinfo',
}),
};
request(options, function(error, response, body) {
if (response &&
response.statusCode &&
response.statusCode === 200) {
// res.end(body);
console.log(JSON.stringify(body, null, '\t'));
} else {
// res.end(body);
console.log(JSON.stringify(body, null, '\t'));
}
});
}, 10000);
setTimeout(function() {
pm2.delete('komodod');
resolve(_komododTest);
}, 20000);
}
// komodod debug.log hooks
//"{\"result\":{\"version\":1000850,\"protocolversion\":170002,\"KMDversion\":\"0.1.1\",\"notarized\":0,\"notarizedhash\":\"0000000000000000000000000000000000000000000000000000000000000000\",\"notarizedtxid\":\"0000000000000000000000000000000000000000000000000000000000000000\",\"notarizedtxid_height\":\"mempool\",\"notarized_confirms\":0,\"walletversion\":60000,\"balance\":0.00000000,\"interest\":0.00000000,\"blocks\":128,\"longestchain\":472331,\"timeoffset\":0,\"tiptime\":1473827710,\"connections\":1,\"proxy\":\"\",\"difficulty\":1,\"testnet\":false,\"keypoololdest\":1504118047,\"keypoolsize\":101,\"paytxfee\":0.00000000,\"relayfee\":0.00000100,\"errors\":\"\"},\"error\":null,\"id\":null}\n"
//2017-08-30 17:51:33 Error: Cannot find the Zcash network parameters in the following directory:
//"/home/pbca/.zcash-params"
//Please run 'zcash-fetch-params' or './zcutil/fetch-params.sh' and then restart.
//EXCEPTION: St13runtime_error
//Assertion failed.
//2017-08-30 17:51:14 Using config file /home/pbca/.iguana/test/komodo.conf
//2017-08-30 18:23:43 UpdateTip: new best=0a47c1323f393650f7221c217d19d149d002d35444f47fde61be2dd90fbde8e6 height=1 log2_work=5.0874628 tx=2 date=2016-09-13 19:04:01 progress=0.000001 cache=0.0MiB(1tx)
//2017-08-30 18:23:43 UpdateTip: new best=05076a4e1fc9af0f5fda690257b17ae20c12d4796dfba1624804d012c9ec00be height=2 log2_work=5.6724253 tx=3 date=2016-09-13 19:05:28 progress=0.000001 cache=0.0MiB(2tx)
/*execFile(`${komododBin}`, _arg, {
maxBuffer: 1024 * 10000 // 10 mb
}, function(error, stdout, stderr) {
shepherd.writeLog(`stdout: ${stdout}`);
shepherd.writeLog(`stderr: ${stderr}`);
if (error !== null) {
console.log(`exec error: ${error}`);
shepherd.writeLog(`exec error: ${error}`);
if (error.toString().indexOf('using -reindex') > -1) {
cache.io.emit('service', {
komodod: {
error: 'run -reindex',
}
});
}
}
});*/
}
});
}
shepherd.testLocation = function(path) {
return new Promise(function(resolve, reject) {
fs.lstat(path, (err, stats) => {
if (err) {
console.log('error testing path ' + path);
console.log(`error testing path ${path}`);
resolve(-1);
} else {
if (stats.isDirectory()) {
resolve(true);
} else {
console.log('error testing path ' + path + ' not a folder');
console.log(`error testing path ${path} not a folder`);
resolve(false);
}
}
@ -156,7 +756,7 @@ shepherd.killRogueProcess = function(processName) {
exec(processGrep, function(error, stdout, stderr) {
if (stdout.indexOf(processName) > -1) {
const pkillCmd = osPlatform === 'win32' ? 'taskkill /f /im ' + processName + '.exe' : 'pkill -15 ' + processName;
const pkillCmd = osPlatform === 'win32' ? `taskkill /f /im ${processName}.exe` : `pkill -15 ${processName}`;
console.log(`found another ${processName} process(es)`);
shepherd.writeLog(`found another ${processName} process(es)`);
@ -180,15 +780,43 @@ shepherd.killRogueProcess = function(processName) {
}
shepherd.zcashParamsExist = function() {
if (_fs.existsSync(zcashParamsDir) &&
_fs.existsSync(`${zcashParamsDir}/sprout-proving.key`) &&
_fs.existsSync(`${zcashParamsDir}/sprout-verifying.key`)) {
console.log('zcashparams exist');
return true;
let _checkList = {
rootDir: _fs.existsSync(zcashParamsDir),
provingKey: _fs.existsSync(`${zcashParamsDir}/sprout-proving.key`),
provingKeySize: false,
verifyingKey: _fs.existsSync(`${zcashParamsDir}/sprout-verifying.key`),
verifyingKeySize: false,
errors: false,
};
if (_checkList.rootDir &&
_checkList.provingKey &&
_checkList.verifyingKey) {
// verify each key size
const _provingKeySize = fs.lstatSync(`${zcashParamsDir}/sprout-proving.key`);
const _verifyingKeySize = fs.lstatSync(`${zcashParamsDir}/sprout-verifying.key`);
if (_provingKeySize.size === 910173851) {
_checkList.provingKeySize = true;
}
if (_verifyingKeySize.size === 1449) {
_checkList.verifyingKeySize = true;
}
console.log('zcashparams exist');
} else {
console.log('zcashparams doesnt exist');
return false;
}
if (!_checkList.rootDir ||
!_checkList.provingKey ||
!_checkList.verifyingKey ||
!_checkList.provingKeySize ||
!_checkList.verifyingKeySize) {
_checkList.errors = true;
}
return _checkList;
}
shepherd.readVersionFile = function() {
@ -571,7 +1199,7 @@ shepherd.get('/update/bins', function(req, res, next) {
file: binsToUpdate[i].name,
bytesTotal: total,
bytesReceived: received,
}
},
});
console.log(`${binsToUpdate[i].name} ${percentage}% | ${received} bytes out of ${total} bytes.`);
}
@ -587,7 +1215,7 @@ shepherd.get('/update/bins', function(req, res, next) {
type: 'bins-update',
file: binsToUpdate[i].name,
status: 'done',
}
},
});
console.log(`file ${binsToUpdate[i].name} succesfully downloaded`);
} else {
@ -596,7 +1224,7 @@ shepherd.get('/update/bins', function(req, res, next) {
type: 'bins-update',
file: binsToUpdate[i].name,
message: 'size mismatch',
}
},
});
console.log(`error: ${binsToUpdate[i].name} file size doesnt match remote!`);
}
@ -606,7 +1234,7 @@ shepherd.get('/update/bins', function(req, res, next) {
/*
* DL app patch
* type:
* type: GET
* params: patchList
*/
shepherd.get('/update/patch', function(req, res, next) {
@ -901,11 +1529,12 @@ shepherd.quitKomodod = function(timeout = 100) {
// if komodod is under heavy load it may not respond to cli stop the first time
// exit komodod gracefully
let coindExitInterval = {};
lockDownAddCoin = true;
for (let key in coindInstanceRegistry) {
const chain = key !== 'komodod' ? key : null;
coindExitInterval[key] = setInterval(function() {
function execCliStop() {
let _arg = [];
if (chain) {
_arg.push(`-ac_name=${chain}`);
@ -929,12 +1558,18 @@ shepherd.quitKomodod = function(timeout = 100) {
}
shepherd.killRogueProcess('komodo-cli');
});
}
execCliStop();
coindExitInterval[key] = setInterval(function() {
execCliStop();
}, timeout);
}
}
shepherd.getConf = function(chain) {
const _confLocation = chain === 'komodod' ? `${komodoDir}/komodo.conf` : `${komodoDir}/${chain}/${chain}.conf`;
const _confLocation = chain === 'komodod' ? (os.platform() === 'darwin' ? `${komodoDir}/Komodo.conf` : `${komodoDir}/komodo.conf`) : `${komodoDir}/${chain}/${chain}.conf`;
// komodoDir
if (fs.existsSync(_confLocation)) {
const _port = assetChainPorts[chain];
@ -1432,7 +2067,10 @@ shepherd.post('/forks', function(req, res, next) {
args: [`-port=${_port}`],
cwd: iguanaDir //set correct iguana directory
}, function(err, apps) {
if (apps && apps[0] && apps[0].process && apps[0].process.pid) {
if (apps &&
apps[0] &&
apps[0].process &&
apps[0].process.pid) {
iguanaInstanceRegistry[_port] = {
mode: mode,
coin: coin,
@ -1648,7 +2286,6 @@ shepherd.post('/debuglog', function(req, res) {
_location = `${komodoDir}/${_ac}`;
}
console.log('komodo dir ' + komodoDir);
shepherd.readDebugLog(`${_location}/debug.log`, _lastNLines)
.then(function(result) {
const _obj = {
@ -1676,6 +2313,7 @@ shepherd.post('/herd', function(req, res) {
console.log(req.body);
function testCoindPort() {
if (!lockDownAddCoin) {
const _port = assetChainPorts[req.body.options.ac_name];
portscanner.checkPortStatus(_port, '127.0.0.1', function(error, status) {
@ -1685,13 +2323,13 @@ shepherd.post('/herd', function(req, res) {
shepherd.writeLog(`komodod service start error at port ${_port}, reason: port is closed`);
cache.io.emit('service', {
komodod: {
error: 'error starting ' + req.body.herd + ' ' + req.body.options.ac_name + ' daemon. Port ' + _port + ' is already taken!',
error: `error starting ${req.body.herd} ${req.body.options.ac_name} daemon. Port ${_port} is already taken!`,
},
});
const obj = {
msg: 'error',
result: 'error starting ' + req.body.herd + ' ' + req.body.options.ac_name + ' daemon. Port ' + _port + ' is already taken!',
result: `error starting ${req.body.herd} ${req.body.options.ac_name} daemon. Port ${_port} is already taken!`,
};
res.status(500);
@ -1708,6 +2346,7 @@ shepherd.post('/herd', function(req, res) {
}
});
}
}
if (req.body.herd === 'komodod') {
// check if komodod instance is already running
@ -1967,6 +2606,7 @@ shepherd.readDebugLog = function(fileLocation, lastNLines) {
return new Promise(
function(resolve, reject) {
if (lastNLines) {
try {
_fs.access(fileLocation, fs.constants.R_OK, function(err) {
if (err) {
console.log(`error reading ${fileLocation}`);
@ -1985,6 +2625,9 @@ shepherd.readDebugLog = function(fileLocation, lastNLines) {
});
}
});
} catch (e) {
reject(`readDebugLog error: ${e}`);
}
} else {
reject('readDebugLog error: lastNLines param is not provided!');
}
@ -2053,6 +2696,9 @@ function herder(flock, data) {
args: [`-port=${shepherd.appConfig.iguanaCorePort}`],
cwd: iguanaDir // set correct iguana directory
}, function(err, apps) {
if (apps[0] &&
apps[0].process &&
apps[0].process.pid) {
iguanaInstanceRegistry[shepherd.appConfig.iguanaCorePort] = {
mode: 'main',
coin: 'none',
@ -2060,6 +2706,10 @@ function herder(flock, data) {
pmid: apps[0].pm2_env.pm_id,
};
shepherd.writeLog(`iguana core started at port ${shepherd.appConfig.iguanaCorePort} pid ${apps[0].process.pid}`);
} else {
shepherd.writeLog(`unable to start iguana core at port ${shepherd.appConfig.iguanaCorePort}`);
console.log(`unable to start iguana core at port ${shepherd.appConfig.iguanaCorePort}`);
}
pm2.disconnect(); // Disconnect from PM2
if (err) {
@ -2077,7 +2727,7 @@ function herder(flock, data) {
let kmdDebugLogLocation = (data.ac_name !== 'komodod' ? komodoDir + '/' + data.ac_name : komodoDir) + '/debug.log';
console.log('komodod flock selected...');
console.log(`selected data: ${data}`);
console.log('selected data: ' + JSON.stringify(data, null, '\t'));
shepherd.writeLog('komodod flock selected...');
shepherd.writeLog(`selected data: ${data}`);
@ -2235,7 +2885,7 @@ shepherd.setConfKMD = function() {
}
// check if kmd conf exists
_fs.access(`${komodoDir}/komodo.conf`, fs.constants.R_OK, function(err) {
_fs.access(os.platform() === 'darwin' ? `${komodoDir}/Komodo.conf` : `${komodoDir}/komodo.conf`, fs.constants.R_OK, function(err) {
if (err) {
console.log('creating komodo conf');
shepherd.writeLog(`creating komodo conf in ${komodoDir}/komodo.conf`);
@ -2272,7 +2922,7 @@ function setConf(flock) {
let DaemonConfPath;
switch (flock) {
case 'komodod':
DaemonConfPath = `${komodoDir}/komodo.conf`;
DaemonConfPath = os.platform() === 'darwin' ? `${komodoDir}/Komodo.conf` : `${komodoDir}/komodo.conf`;
if (os.platform() === 'win32') {
DaemonConfPath = path.normalize(DaemonConfPath);

2
version

@ -1,3 +1,3 @@
version=0.2.0.21a
version=0.2.0.22a
type=e-beta
minversion=0.2.0.2

2
version_build

@ -1 +1 @@
0.2.0.1a-beta
0.2.0.22a-beta

Loading…
Cancel
Save