|
|
@ -1,12 +1,14 @@ |
|
|
|
const fs = require('fs-extra'); |
|
|
|
const path = require('path'); |
|
|
|
|
|
|
|
module.exports = (shepherd) => { |
|
|
|
/* |
|
|
|
* type: GET |
|
|
|
* params: coin, type |
|
|
|
* TODO: reorganize to work with coind |
|
|
|
*/ |
|
|
|
shepherd.get('/kick', (req, res, next) => { |
|
|
|
const _coin = req.query.coin; |
|
|
|
const _type = req.query.type; |
|
|
|
const _keepWallet = req.query.keepwallet; |
|
|
|
|
|
|
|
if (!_coin) { |
|
|
|
const errorObj = { |
|
|
@ -15,131 +17,24 @@ module.exports = (shepherd) => { |
|
|
|
}; |
|
|
|
|
|
|
|
res.end(JSON.stringify(errorObj)); |
|
|
|
} |
|
|
|
|
|
|
|
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]; |
|
|
|
} else { |
|
|
|
const _location = path.join(_coin === 'KMD' ? shepherd.komodoDir : `${shepherd.komodoDir}/${_coin}`); |
|
|
|
|
|
|
|
shepherd.log('deleting ' + currentKickItem.type + (currentKickItem.match ? ' ' + currentKickItem.match : '') + ' ' + iguanaDir + '/' + currentKickItem.name.replace('[coin]', _coin)); |
|
|
|
if (currentKickItem.type === 'folder' || |
|
|
|
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}`); |
|
|
|
} |
|
|
|
});*/ |
|
|
|
if (fs.existsSync(_location)) { |
|
|
|
const items = fs.readdirSync(_location); |
|
|
|
|
|
|
|
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 = { |
|
|
|
msg: 'success', |
|
|
|
result: 'kickstart: brutal is executed', |
|
|
|
result: `${_coin} native is kicked`, |
|
|
|
}; |
|
|
|
|
|
|
|
res.end(JSON.stringify(successObj)); |
|
|
|