Browse Source

rm komodo/chain data

v0.25
pbca26 7 years ago
parent
commit
cbf38b5ec7
  1. 2
      routes/shepherd/daemonControl.js
  2. 24
      routes/shepherd/dashboardUpdate.js
  3. 5
      routes/shepherd/init.js
  4. 133
      routes/shepherd/kickstart.js
  5. 16
      routes/shepherd/quitDaemon.js
  6. 2
      version
  7. 2
      version_build

2
routes/shepherd/daemonControl.js

@ -289,7 +289,7 @@ module.exports = (shepherd) => {
try { try {
// check if komodod instance is already running // check if komodod instance is already running
shepherd.portscanner.checkPortStatus(_port, '127.0.0.1', (error, status) => { portscanner.checkPortStatus(_port, '127.0.0.1', (error, status) => {
// Status is 'open' if currently in use or 'closed' if available // Status is 'open' if currently in use or 'closed' if available
if (status === 'closed') { if (status === 'closed') {
// start komodod via exec // start komodod via exec

24
routes/shepherd/dashboardUpdate.js

@ -1,3 +1,5 @@
const Promise = require('bluebird');
module.exports = (shepherd) => { module.exports = (shepherd) => {
/* /*
* Combined native dashboard update same as in gui * Combined native dashboard update same as in gui
@ -5,9 +7,9 @@ module.exports = (shepherd) => {
* params: coin * params: coin
*/ */
shepherd.post('/native/dashboard/update', (req, res, next) => { shepherd.post('/native/dashboard/update', (req, res, next) => {
const _coin = req.body.coin;
let _returnObj; let _returnObj;
let _promiseStack; let _promiseStack;
const _coin = req.body.coin;
if (_coin === 'CHIPS') { if (_coin === 'CHIPS') {
_returnObj = { _returnObj = {
@ -49,8 +51,8 @@ module.exports = (shepherd) => {
type.pop(); type.pop();
} }
shepherd.Promise.all(type.map((_type, index) => { Promise.all(type.map((_type, index) => {
return new shepherd.Promise((resolve, reject) => { return new Promise((resolve, reject) => {
_bitcoinRPC( _bitcoinRPC(
coin, coin,
_type === 'public' ? 'getaddressesbyaccount' : 'z_listaddresses', _type === 'public' ? 'getaddressesbyaccount' : 'z_listaddresses',
@ -70,7 +72,9 @@ module.exports = (shepherd) => {
result[0].length) { result[0].length) {
const calcBalance = (result, json) => { const calcBalance = (result, json) => {
if (json && if (json &&
json.length) { json.length &&
json[0] &&
json[0].address) {
const allAddrArray = json.map(res => res.address).filter((x, i, a) => a.indexOf(x) == i); const allAddrArray = json.map(res => res.address).filter((x, i, a) => a.indexOf(x) == i);
for (let a = 0; a < allAddrArray.length; a++) { for (let a = 0; a < allAddrArray.length; a++) {
@ -146,8 +150,8 @@ module.exports = (shepherd) => {
// get zaddr balance // get zaddr balance
if (result[1] && if (result[1] &&
result[1].length) { result[1].length) {
shepherd.Promise.all(result[1].map((_address, index) => { Promise.all(result[1].map((_address, index) => {
return new shepherd.Promise((resolve, reject) => { return new Promise((resolve, reject) => {
_bitcoinRPC(coin, 'z_getbalance', [_address]) _bitcoinRPC(coin, 'z_getbalance', [_address])
.then((__json) => { .then((__json) => {
__json = JSON.parse(__json); __json = JSON.parse(__json);
@ -155,7 +159,7 @@ module.exports = (shepherd) => {
__json.error) { __json.error) {
resolve(0); resolve(0);
} else { } else {
resolve(__json.result) resolve(__json.result);
newAddressArray[1][index] = { newAddressArray[1][index] = {
address: _address, address: _address,
amount: __json.result, amount: __json.result,
@ -229,7 +233,7 @@ module.exports = (shepherd) => {
} }
const _bitcoinRPC = (coin, cmd, params) => { const _bitcoinRPC = (coin, cmd, params) => {
return new shepherd.Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let _payload; let _payload;
if (params) { if (params) {
@ -269,7 +273,7 @@ module.exports = (shepherd) => {
}); });
} }
shepherd.Promise.all(_promiseStack.map((_call, index) => { Promise.all(_promiseStack.map((_call, index) => {
let _params; let _params;
if (_call === 'listtransactions') { if (_call === 'listtransactions') {
@ -280,7 +284,7 @@ module.exports = (shepherd) => {
]; ];
} }
return new shepherd.Promise((resolve, reject) => { return new Promise((resolve, reject) => {
_bitcoinRPC( _bitcoinRPC(
_coin, _coin,
_call, _call,

5
routes/shepherd/init.js

@ -1,5 +1,6 @@
const fs = require('fs-extra'); const fs = require('fs-extra');
const path = require('path'); const path = require('path');
let _foldersInitRan = false;
module.exports = (shepherd) => { module.exports = (shepherd) => {
shepherd.readVersionFile = () => { shepherd.readVersionFile = () => {
@ -11,6 +12,7 @@ module.exports = (shepherd) => {
} }
shepherd.createAgamaDirs = () => { shepherd.createAgamaDirs = () => {
if (!_foldersInitRan) {
const rootLocation = path.join(__dirname, '../../'); const rootLocation = path.join(__dirname, '../../');
fs.readdir(rootLocation, (err, items) => { fs.readdir(rootLocation, (err, items) => {
@ -60,6 +62,9 @@ module.exports = (shepherd) => {
} else { } else {
shepherd.log('zcashparams folder already exists'); shepherd.log('zcashparams folder already exists');
} }
_foldersInitRan = true;
}
} }
return shepherd; return shepherd;

133
routes/shepherd/kickstart.js

@ -1,12 +1,14 @@
const fs = require('fs-extra');
const path = require('path');
module.exports = (shepherd) => { module.exports = (shepherd) => {
/* /*
* type: GET * type: GET
* params: coin, type * params: coin, type
* TODO: reorganize to work with coind
*/ */
shepherd.get('/kick', (req, res, next) => { shepherd.get('/kick', (req, res, next) => {
const _coin = req.query.coin; const _coin = req.query.coin;
const _type = req.query.type; const _keepWallet = req.query.keepwallet;
if (!_coin) { if (!_coin) {
const errorObj = { const errorObj = {
@ -15,131 +17,24 @@ module.exports = (shepherd) => {
}; };
res.end(JSON.stringify(errorObj)); res.end(JSON.stringify(errorObj));
} } else {
const _location = path.join(_coin === 'KMD' ? shepherd.komodoDir : `${shepherd.komodoDir}/${_coin}`);
if (!_type) {
const errorObj = {
msg: 'error',
result: 'no type provided',
};
res.end(JSON.stringify(errorObj));
}
const kickStartDirs = {
soft: [
{
name: 'DB/[coin]',
type: 'pattern',
match: 'balancecrc.',
},
{
name: 'DB/[coin]/utxoaddrs',
type: 'file',
},
{
name: 'DB/[coin]/accounts',
type: 'folder',
},
{
name: 'DB/[coin]/fastfind',
type: 'folder',
},
{
name: 'tmp/[coin]',
type: 'folder',
}
],
hard: [
{
name: 'DB/[coin]',
type: 'pattern',
match: 'balancecrc.',
},
{
name: 'DB/[coin]/utxoaddrs',
type: 'file',
},
{
name: 'DB/[coin]',
type: 'pattern',
match: 'utxoaddrs.',
},
{
name: 'DB/[coin]/accounts',
type: 'folder',
},
{
name: 'DB/[coin]/fastfind',
type: 'folder',
},
{
name: 'DB/[coin]/spends',
type: 'folder',
},
{
name: 'tmp/[coin]',
type: 'folder',
}
],
brutal: [ // delete all coin related data
{
name: 'DB/[coin]',
type: 'folder',
},
{
name: 'DB/purgeable/[coin]',
type: 'folder',
},
{
name: 'DB/ro/[coin]',
type: 'folder',
},
{
name: 'tmp/[coin]',
type: 'folder',
}
]
};
if (_coin &&
_type) {
for (let i = 0; i < kickStartDirs[_type].length; i++) {
let currentKickItem = kickStartDirs[_type][i];
shepherd.log('deleting ' + currentKickItem.type + (currentKickItem.match ? ' ' + currentKickItem.match : '') + ' ' + iguanaDir + '/' + currentKickItem.name.replace('[coin]', _coin)); if (fs.existsSync(_location)) {
if (currentKickItem.type === 'folder' || const items = fs.readdirSync(_location);
currentKickItem.type === 'file') {
/*rimraf(`${iguanaDir}/${currentKickItem.name.replace('[coin]', _coin)}`, function(err) {
if (err) {
shepherd.writeLog(`kickstart err: ${err}`);
shepherd.log(`kickstart err: ${err}`);
}
});*/
} else if (currentKickItem.type === 'pattern') {
let dirItems = shepherd.fs.readdirSync(`${iguanaDir}/currentKickItem.name.replace('[coin]', _coin)`);
if (dirItems &&
dirItems.length) {
for (let j = 0; j < dirItems.length; j++) {
if (dirItems[j].indexOf(currentKickItem.match) > -1) {
/*rimraf(`${iguanaDir}/${currentKickItem.name.replace('[coin]', _coin)}/${dirItems[j]}`, function(err) {
if (err) {
shepherd.writeLog(`kickstart err: ${err}`);
shepherd.log(`kickstart err: ${err}`);
}
});*/
shepherd.log(`deleting ${dirItems[j]}`); for (let i = 0; i < items.length; i++) {
} if (items[i].indexOf('wallet.dat') === -1) {
} fs.removeSync(`${_location}/${items[i]}`);
} else if (!_keepWallet) {
fs.removeSync(`${_location}/${items[i]}`);
} }
} }
} }
const successObj = { const successObj = {
msg: 'success', msg: 'success',
result: 'kickstart: brutal is executed', result: `${_coin} native is kicked`,
}; };
res.end(JSON.stringify(successObj)); res.end(JSON.stringify(successObj));

16
routes/shepherd/quitDaemon.js

@ -1,3 +1,6 @@
const portscanner = require('portscanner');
const execFile = require('child_process').execFile;
module.exports = (shepherd) => { module.exports = (shepherd) => {
shepherd.quitKomodod = (timeout = 100) => { shepherd.quitKomodod = (timeout = 100) => {
// if komodod is under heavy load it may not respond to cli stop the first time // if komodod is under heavy load it may not respond to cli stop the first time
@ -32,7 +35,7 @@ module.exports = (shepherd) => {
} }
_arg.push('stop'); _arg.push('stop');
shepherd.execFile(`${_coindQuitCmd}`, _arg, (error, stdout, stderr) => { execFile(`${_coindQuitCmd}`, _arg, (error, stdout, stderr) => {
shepherd.log(`stdout: ${stdout}`); shepherd.log(`stdout: ${stdout}`);
shepherd.log(`stderr: ${stderr}`); shepherd.log(`stderr: ${stderr}`);
@ -48,7 +51,7 @@ module.exports = (shepherd) => {
// workaround for AGT-65 // workaround for AGT-65
const _port = shepherd.assetChainPorts[key]; const _port = shepherd.assetChainPorts[key];
setTimeout(() => { setTimeout(() => {
shepherd.portscanner.checkPortStatus(_port, '127.0.0.1', (error, status) => { portscanner.checkPortStatus(_port, '127.0.0.1', (error, status) => {
// Status is 'open' if currently in use or 'closed' if available // Status is 'open' if currently in use or 'closed' if available
if (status === 'closed') { if (status === 'closed') {
delete shepherd.coindInstanceRegistry[key]; delete shepherd.coindInstanceRegistry[key];
@ -92,12 +95,11 @@ module.exports = (shepherd) => {
_arg.push(`-datadir=${shepherd.appConfig.dataDir}`); _arg.push(`-datadir=${shepherd.appConfig.dataDir}`);
} }
console.log(JSON.stringify(shepherd.coindInstanceRegistry, null, '\t'));
_arg.push('stop'); _arg.push('stop');
shepherd.execFile(`${_coindQuitCmd}`, _arg, (error, stdout, stderr) => { execFile(`${_coindQuitCmd}`, _arg, (error, stdout, stderr) => {
shepherd.log(`stdout: ${stdout}`); shepherd.log(`stdout: ${stdout}`);
shepherd.log(`stderr: ${stderr}`); shepherd.log(`stderr: ${stderr}`);
shepherd.log(`send stop sig to ${_chain}`);
if (stdout.indexOf('EOF reached') > -1 || if (stdout.indexOf('EOF reached') > -1 ||
stderr.indexOf('EOF reached') > -1 || stderr.indexOf('EOF reached') > -1 ||
@ -134,9 +136,9 @@ module.exports = (shepherd) => {
}); });
shepherd.post('/coins/remove', (req, res) => { shepherd.post('/coins/remove', (req, res) => {
if (req.body.mode === 'native') {
const _chain = req.body.chain; const _chain = req.body.chain;
if (req.body.mode === 'native') {
delete shepherd.coindInstanceRegistry[_chain ? _chain : 'komodod']; delete shepherd.coindInstanceRegistry[_chain ? _chain : 'komodod'];
const obj = { const obj = {
@ -146,7 +148,7 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(obj)); res.end(JSON.stringify(obj));
} else { } else {
delete shepherd.electrumCoins[req.body.chain === 'komodo' ? 'KMD' : req.body.chain]; delete shepherd.electrumCoins[_chain === 'komodo' ? 'KMD' : _chain];
if (Object.keys(shepherd.electrumCoins).length - 1 === 0) { if (Object.keys(shepherd.electrumCoins).length - 1 === 0) {
shepherd.electrumCoins.auth = false; shepherd.electrumCoins.auth = false;

2
version

@ -1,3 +1,3 @@
version=0.2.0.24c version=0.2.0.24d
type=e-beta type=e-beta
minversion=0.2.0.2 minversion=0.2.0.2

2
version_build

@ -1 +1 @@
0.2.0.24c-beta 0.2.0.24d-beta
Loading…
Cancel
Save