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

1
routes/ports.js

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

4
routes/shepherd.js

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

9
routes/shepherd/daemonControl.js

@ -99,14 +99,23 @@ module.exports = (shepherd) => {
if (_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]}`);
} 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]}`);
}
} 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]}`);
}
} 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]}`);
}

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) => {
/*
* type: POST
@ -7,7 +10,7 @@ module.exports = (shepherd) => {
if (req.body.key &&
req.body.string &&
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
// - at least 1 char in upper case
@ -18,7 +21,7 @@ module.exports = (shepherd) => {
const _pin = req.body.key;
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) {
shepherd.log('error writing pin file');
}
@ -56,8 +59,8 @@ module.exports = (shepherd) => {
shepherd.post('/decryptkey', (req, res, next) => {
if (req.body.key &&
req.body.pubkey) {
if (shepherd.fs.existsSync(`${shepherd.agamaDir}/shepherd/pin/${req.body.pubkey}.pin`)) {
shepherd.fs.readFile(`${shepherd.agamaDir}/shepherd/pin/${req.body.pubkey}.pin`, 'utf8', (err, data) => {
if (fs.existsSync(`${shepherd.agamaDir}/shepherd/pin/${req.body.pubkey}.pin`)) {
fs.readFile(`${shepherd.agamaDir}/shepherd/pin/${req.body.pubkey}.pin`, 'utf8', (err, data) => {
if (err) {
const errorObj = {
msg: 'error',
@ -66,7 +69,7 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(errorObj));
} 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
// if not then the key is wrong
const _regexTest = encryptedKey.match(/^[0-9a-zA-Z ]+$/g);
@ -106,8 +109,8 @@ module.exports = (shepherd) => {
});
shepherd.get('/getpinlist', (req, res, next) => {
if (shepherd.fs.existsSync(`${shepherd.agamaDir}/shepherd/pin`)) {
shepherd.fs.readdir(`${shepherd.agamaDir}/shepherd/pin`, (err, items) => {
if (fs.existsSync(`${shepherd.agamaDir}/shepherd/pin`)) {
fs.readdir(`${shepherd.agamaDir}/shepherd/pin`, (err, items) => {
let _pins = [];
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) => {
shepherd.getConf = (chain) => {
let _confLocation = chain === 'komodod' ? `${shepherd.komodoDir}/komodo.conf` : `${shepherd.komodoDir}/${chain}/${chain}.conf`;
@ -6,15 +9,15 @@ module.exports = (shepherd) => {
// any coind
if (chain) {
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`;
_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];
const _rpcConf = shepherd.fs.readFileSync(_confLocation, 'utf8');
const _rpcConf = fs.readFileSync(_confLocation, 'utf8');
// any coind
if (shepherd.nativeCoindList[chain.toLowerCase()]) {
@ -85,7 +88,7 @@ module.exports = (shepherd) => {
if (_cmd === 'debug' &&
_chain !== 'CHIPS') {
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;
if (_chain === 'CHIPS') {

Loading…
Cancel
Save