Browse Source

minor cleanup

v0.25
pbca26 7 years ago
parent
commit
d33f0cd2c0
  1. 4
      main.js
  2. 1
      routes/ports.js
  3. 4
      routes/shepherd.js
  4. 9
      routes/shepherd/daemonControl.js
  5. 130
      routes/shepherd/explorer/overview.js
  6. 21
      routes/shepherd/explorer/remoteExplorers.js
  7. 17
      routes/shepherd/pin.js
  8. 11
      routes/shepherd/rpc.js

4
main.js

@ -146,6 +146,7 @@ guiapp.use('/shepherd', shepherd);
const server = require('http').createServer(guiapp); const server = require('http').createServer(guiapp);
const io = require('socket.io').listen(server); const io = require('socket.io').listen(server);
const _zcashParamsExist = shepherd.zcashParamsExist();
let willQuitApp = false; let willQuitApp = false;
let mainWindow; let mainWindow;
let loadingWindow; let loadingWindow;
@ -153,7 +154,6 @@ let appCloseWindow;
let appSettingsWindow; let appSettingsWindow;
let closeAppAfterLoading = false; let closeAppAfterLoading = false;
let forceQuitApp = false; let forceQuitApp = false;
const _zcashParamsExist = shepherd.zcashParamsExist();
module.exports = guiapp; module.exports = guiapp;
let agamaIcon; let agamaIcon;
@ -278,7 +278,7 @@ if (process.argv.indexOf('dexonly') > -1) {
app.on('ready', createLoadingWindow); app.on('ready', createLoadingWindow);
setTimeout(() => { setTimeout(() => {
createWindow('open', true); createWindow('open', true);
}, 100); }, 500);
} else { } else {
app.on('ready', createLoadingWindow); app.on('ready', createLoadingWindow);
} }

1
routes/ports.js

@ -1,5 +1,6 @@
const assetChainPorts = { const assetChainPorts = {
'komodod': '7771', 'komodod': '7771',
'markermaker': '7783',
'CHIPS': '57776', 'CHIPS': '57776',
'SUPERNET': '11341', 'SUPERNET': '11341',
'REVS': '10196', 'REVS': '10196',

4
routes/shepherd.js

@ -28,6 +28,7 @@ shepherd.setconf = require('../private/setconf.js');
shepherd.nativeCoind = require('./nativeCoind.js'); shepherd.nativeCoind = require('./nativeCoind.js');
shepherd.nativeCoindList = {}; shepherd.nativeCoindList = {};
shepherd.assetChainPorts = require('./ports.js'); shepherd.assetChainPorts = require('./ports.js');
shepherd.assetChainPortsDefault = require('./ports.js');
shepherd._appConfig = require('./appConfig.js'); shepherd._appConfig = require('./appConfig.js');
shepherd.coindInstanceRegistry = {}; shepherd.coindInstanceRegistry = {};
@ -128,6 +129,9 @@ shepherd = require('./shepherd/auth.js')(shepherd);
shepherd = require('./shepherd/coins.js')(shepherd); shepherd = require('./shepherd/coins.js')(shepherd);
shepherd = require('./shepherd/coindWalletKeys.js')(shepherd); shepherd = require('./shepherd/coindWalletKeys.js')(shepherd);
// explorer
// shepherd = require('./shepherd/explorer/overview.js')(shepherd);
shepherd.printDirs(); shepherd.printDirs();
// default route // default route

9
routes/shepherd/daemonControl.js

@ -99,14 +99,23 @@ module.exports = (shepherd) => {
if (_coindCustomPort[1]) { if (_coindCustomPort[1]) {
shepherd.assetChainPorts[data.ac_name] = _coindCustomPort[1]; shepherd.assetChainPorts[data.ac_name] = _coindCustomPort[1];
shepherd.rpcConf[data.ac_name === 'komodod' ? 'KMD' : data.ac_name].port = _coindCustomPort[1];
shepherd.log(`${data.ac_name} custom port ${_coindCustomPort[1]}`); shepherd.log(`${data.ac_name} custom port ${_coindCustomPort[1]}`);
} else { } else {
shepherd.assetChainPorts[data.ac_name] = shepherd.assetChainPortsDefault[data.ac_name];
shepherd.rpcConf[data.ac_name === 'komodod' ? 'KMD' : data.ac_name].port = shepherd.assetChainPortsDefault[data.ac_name];
shepherd.log(`${data.ac_name} port ${shepherd.assetChainPorts[data.ac_name]}`); shepherd.log(`${data.ac_name} port ${shepherd.assetChainPorts[data.ac_name]}`);
} }
} else { } else {
shepherd.assetChainPorts[data.ac_name] = shepherd.assetChainPortsDefault[data.ac_name];
shepherd.rpcConf[data.ac_name === 'komodod' ? 'KMD' : data.ac_name].port = shepherd.assetChainPortsDefault[data.ac_name];
shepherd.log(`${data.ac_name} port ${shepherd.assetChainPorts[data.ac_name]}`); shepherd.log(`${data.ac_name} port ${shepherd.assetChainPorts[data.ac_name]}`);
} }
} catch (e) { } catch (e) {
if (shepherd.rpcConf[data.ac_name === 'komodod' ? 'KMD' : data.ac_name]) {
shepherd.rpcConf[data.ac_name === 'komodod' ? 'KMD' : data.ac_name].port = shepherd.assetChainPortsDefault[data.ac_name];
}
shepherd.assetChainPorts[data.ac_name] = shepherd.assetChainPortsDefault[data.ac_name];
shepherd.log(`${data.ac_name} port ${shepherd.assetChainPorts[data.ac_name]}`); shepherd.log(`${data.ac_name} port ${shepherd.assetChainPorts[data.ac_name]}`);
} }

130
routes/shepherd/explorer/overview.js

@ -0,0 +1,130 @@
const remoteExplorers = require('./remoteExplorers');
const request = require('request');
const fs = require('fs-extra');
const path = require('path');
let remoteExplorersArray = [];
for (let key in remoteExplorers) {
remoteExplorersArray.push(key);
}
const sortByDate = (data, sortKey) => {
return data.sort(function(b, a) {
if (a[sortKey] < b[sortKey]) {
return -1;
}
if (a[sortKey] > b[sortKey]) {
return 1;
}
return 0;
});
}
module.exports = (shepherd) => {
shepherd.get('/explorer/overview', (req, res, next) => {
if (req.query.coin) {
const options = {
url: `${remoteExplorers[req.query.coin]}/ext/getlasttxs/0.00000001`,
method: 'GET',
};
request(options, (error, response, body) => {
const _parsedBody = JSON.parse(body);
if (response &&
response.statusCode &&
response.statusCode === 200) {
res.end(body);
} else {
res.end(body ? body : JSON.stringify({
result: 'error',
error: {
code: -777,
message: `unable to retrieve remote data from remoteExplorers[req.query.coin]`,
},
}));
}
});
} else {
Promise.all(remoteExplorersArray.map((coin, index) => {
shepherd.log(`explorer ${coin} overview`);
return new Promise((resolve, reject) => {
const options = {
url: `${remoteExplorers[coin]}/ext/getlasttxs/0.00000001`,
method: 'GET',
};
request(options, (error, response, body) => {
if (response &&
response.statusCode &&
response.statusCode === 200) {
resolve({
coin,
result: body,
});
} else {
resolve({
coin,
result: 'unable to get lasttx'
});
}
});
});
}))
.then(result => {
const returnObj = {
msg: 'success',
result,
};
res.end(JSON.stringify(returnObj));
/*if (result &&
result.length) {
} else {
const returnObj = {
msg: 'success',
result: _returnObj,
};
res.end(JSON.stringify(returnObj));
}*/
});
}
});
shepherd.get('/explorer/overview/test', (req, res, next) => {
const testFileLocation = path.join(__dirname, '../explorer/test.json');
const testFile = fs.readJsonSync(testFileLocation, { throws: false });
const resSizeLimit = 1000;
let items = [];
for (let i = 0; i < testFile.result.length; i++) {
const _parseData = JSON.parse(testFile.result[i].result).data;
for (let j = 0; j < _parseData.length; j++) {
items.push({
coin: testFile.result[i].coin,
txid: _parseData[j].txid,
blockhash: _parseData[j].blockhash,
blockindex: _parseData[j].blockindex,
timestamp: _parseData[j].timestamp,
total: _parseData[j].total,
vout: _parseData[j].vout,
vin: _parseData[j].vin,
});
}
}
items = sortByDate(items, 'timestamp');
items = items.slice(0, resSizeLimit + 1);
res.end(JSON.stringify(items));
});
return shepherd;
};

21
routes/shepherd/explorer/remoteExplorers.js

@ -0,0 +1,21 @@
const remoteExplorers = {
KMD: 'http://kmd.komodochainz.info',
MSHARK: 'http://MSHARK.explorer.supernet.org',
REVS: 'http://revs.explorer.supernet.org',
SUPERNET: 'http://SUPERNET.explorer.supernet.org',
DEX: 'http://DEX.explorer.supernet.org',
PANGEA: 'http://PANGEA.explorer.supernet.org',
JUMBLR: 'http://JUMBLR.explorer.supernet.org',
BET: 'http://BET.explorer.supernet.org',
CRYPTO: 'http://CRYPTO.explorer.supernet.org',
HODL: 'http://HODL.explorer.supernet.org',
SHARK: 'http://SHARK.explorer.supernet.org',
BOTS: 'http://BOTS.explorer.supernet.org',
MGW: 'http://MGW.explorer.supernet.org',
WLC: 'http://WIRELESS.explorer.supernet.org',
CHIPS: 'http://CHIPS1.explorer.supernet.org',
COQUI: 'https://explorer.coqui.cash',
MNZ: 'https://www.mnzexplorer.com',
};
module.exports = remoteExplorers;

17
routes/shepherd/pin.js

@ -1,3 +1,6 @@
const fs = require('fs-extra');
const aes256 = require('nodejs-aes256');
module.exports = (shepherd) => { module.exports = (shepherd) => {
/* /*
* type: POST * type: POST
@ -7,7 +10,7 @@ module.exports = (shepherd) => {
if (req.body.key && if (req.body.key &&
req.body.string && req.body.string &&
req.body.pubkey) { req.body.pubkey) {
const encryptedString = shepherd.aes256.encrypt(req.body.key, req.body.string); const encryptedString = aes256.encrypt(req.body.key, req.body.string);
// test pin security // test pin security
// - at least 1 char in upper case // - at least 1 char in upper case
@ -18,7 +21,7 @@ module.exports = (shepherd) => {
const _pin = req.body.key; const _pin = req.body.key;
const _pinTest = _pin.match('^(?=.*[A-Z])(?=.*[^<>{}\"/|;:.,~!?@#$%^=&*\\]\\\\()\\[_+]*$)(?=.*[0-9])(?=.*[a-z]).{8}$'); const _pinTest = _pin.match('^(?=.*[A-Z])(?=.*[^<>{}\"/|;:.,~!?@#$%^=&*\\]\\\\()\\[_+]*$)(?=.*[0-9])(?=.*[a-z]).{8}$');
shepherd.fs.writeFile(`${shepherd.agamaDir}/shepherd/pin/${req.body.pubkey}.pin`, encryptedString, (err) => { fs.writeFile(`${shepherd.agamaDir}/shepherd/pin/${req.body.pubkey}.pin`, encryptedString, (err) => {
if (err) { if (err) {
shepherd.log('error writing pin file'); shepherd.log('error writing pin file');
} }
@ -56,8 +59,8 @@ module.exports = (shepherd) => {
shepherd.post('/decryptkey', (req, res, next) => { shepherd.post('/decryptkey', (req, res, next) => {
if (req.body.key && if (req.body.key &&
req.body.pubkey) { req.body.pubkey) {
if (shepherd.fs.existsSync(`${shepherd.agamaDir}/shepherd/pin/${req.body.pubkey}.pin`)) { if (fs.existsSync(`${shepherd.agamaDir}/shepherd/pin/${req.body.pubkey}.pin`)) {
shepherd.fs.readFile(`${shepherd.agamaDir}/shepherd/pin/${req.body.pubkey}.pin`, 'utf8', (err, data) => { fs.readFile(`${shepherd.agamaDir}/shepherd/pin/${req.body.pubkey}.pin`, 'utf8', (err, data) => {
if (err) { if (err) {
const errorObj = { const errorObj = {
msg: 'error', msg: 'error',
@ -66,7 +69,7 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(errorObj)); res.end(JSON.stringify(errorObj));
} else { } else {
const encryptedKey = shepherd.aes256.decrypt(req.body.key, data); const encryptedKey = aes256.decrypt(req.body.key, data);
// test if stored encrypted passphrase is decrypted correctly // test if stored encrypted passphrase is decrypted correctly
// if not then the key is wrong // if not then the key is wrong
const _regexTest = encryptedKey.match(/^[0-9a-zA-Z ]+$/g); const _regexTest = encryptedKey.match(/^[0-9a-zA-Z ]+$/g);
@ -106,8 +109,8 @@ module.exports = (shepherd) => {
}); });
shepherd.get('/getpinlist', (req, res, next) => { shepherd.get('/getpinlist', (req, res, next) => {
if (shepherd.fs.existsSync(`${shepherd.agamaDir}/shepherd/pin`)) { if (fs.existsSync(`${shepherd.agamaDir}/shepherd/pin`)) {
shepherd.fs.readdir(`${shepherd.agamaDir}/shepherd/pin`, (err, items) => { fs.readdir(`${shepherd.agamaDir}/shepherd/pin`, (err, items) => {
let _pins = []; let _pins = [];
for (let i = 0; i < items.length; i++) { for (let i = 0; i < items.length; i++) {

11
routes/shepherd/rpc.js

@ -1,3 +1,6 @@
const fs = require('fs-extra');
const os = require('os');
module.exports = (shepherd) => { module.exports = (shepherd) => {
shepherd.getConf = (chain) => { shepherd.getConf = (chain) => {
let _confLocation = chain === 'komodod' ? `${shepherd.komodoDir}/komodo.conf` : `${shepherd.komodoDir}/${chain}/${chain}.conf`; let _confLocation = chain === 'komodod' ? `${shepherd.komodoDir}/komodo.conf` : `${shepherd.komodoDir}/${chain}/${chain}.conf`;
@ -6,15 +9,15 @@ module.exports = (shepherd) => {
// any coind // any coind
if (chain) { if (chain) {
if (shepherd.nativeCoindList[chain.toLowerCase()]) { if (shepherd.nativeCoindList[chain.toLowerCase()]) {
const _osHome = shepherd.os.platform === 'win32' ? process.env.APPDATA : process.env.HOME; const _osHome = os.platform === 'win32' ? process.env.APPDATA : process.env.HOME;
let coindDebugLogLocation = `${_osHome}/.${shepherd.nativeCoindList[chain.toLowerCase()].bin.toLowerCase()}/debug.log`; let coindDebugLogLocation = `${_osHome}/.${shepherd.nativeCoindList[chain.toLowerCase()].bin.toLowerCase()}/debug.log`;
_confLocation = `${_osHome}/.${shepherd.nativeCoindList[chain.toLowerCase()].bin.toLowerCase()}/${shepherd.nativeCoindList[chain.toLowerCase()].bin.toLowerCase()}.conf`; _confLocation = `${_osHome}/.${shepherd.nativeCoindList[chain.toLowerCase()].bin.toLowerCase()}/${shepherd.nativeCoindList[chain.toLowerCase()].bin.toLowerCase()}.conf`;
} }
if (shepherd.fs.existsSync(_confLocation)) { if (fs.existsSync(_confLocation)) {
let _port = shepherd.assetChainPorts[chain]; let _port = shepherd.assetChainPorts[chain];
const _rpcConf = shepherd.fs.readFileSync(_confLocation, 'utf8'); const _rpcConf = fs.readFileSync(_confLocation, 'utf8');
// any coind // any coind
if (shepherd.nativeCoindList[chain.toLowerCase()]) { if (shepherd.nativeCoindList[chain.toLowerCase()]) {
@ -85,7 +88,7 @@ module.exports = (shepherd) => {
if (_cmd === 'debug' && if (_cmd === 'debug' &&
_chain !== 'CHIPS') { _chain !== 'CHIPS') {
if (shepherd.nativeCoindList[_chain.toLowerCase()]) { if (shepherd.nativeCoindList[_chain.toLowerCase()]) {
const _osHome = shepherd.os.platform === 'win32' ? process.env.APPDATA : process.env.HOME; const _osHome = os.platform === 'win32' ? process.env.APPDATA : process.env.HOME;
let coindDebugLogLocation; let coindDebugLogLocation;
if (_chain === 'CHIPS') { if (_chain === 'CHIPS') {

Loading…
Cancel
Save