feat: monero files and config feat: monero interface feat: monero rpc digest request feat: add monero to wallet wizard splash fix: tarball unzipping fix: monero files fix: monero zipped folder path fix: undefined variable chore: xmr stagenet fix: prune-blockchain flag fix: monero wallet arguments chore: rpc-bind-port on monero wallet chore: monero wallet directory fix: fetch digest request fix: monero authentication fix: monero address creation fix: monero config port fix: wallet creation fix: wallet rpc daemon login fix: get monero funding fix: unauthorized issue with multiple requests on Promise.all fix: generate funding addresses fix: destination address balance for XMR cashout fix: transaction creation feat: transaction recommended mixin and ring size fix: monero wallet error handling fix: error handling fix: monero wallet error feat: guide to add new cryptos chore: small code shortcuts fix: crypto implementation guide chore: add XMR to exchange files
132 lines
3.5 KiB
JavaScript
132 lines
3.5 KiB
JavaScript
const fs = require('fs')
|
|
const path = require('path')
|
|
const process = require('process')
|
|
const os = require('os')
|
|
|
|
const makeDir = require('make-dir')
|
|
const inquirer = require('inquirer')
|
|
const _ = require('lodash/fp')
|
|
|
|
const { utils: coinUtils } = require('lamassu-coins')
|
|
const options = require('../options')
|
|
|
|
const common = require('./common')
|
|
const doVolume = require('./do-volume')
|
|
|
|
const cryptos = coinUtils.cryptoCurrencies()
|
|
|
|
const logger = common.logger
|
|
|
|
const PLUGINS = {
|
|
BTC: require('./bitcoin.js'),
|
|
BCH: require('./bitcoincash.js'),
|
|
DASH: require('./dash.js'),
|
|
ETH: require('./ethereum.js'),
|
|
LTC: require('./litecoin.js'),
|
|
ZEC: require('./zcash.js'),
|
|
XMR: require('./monero.js')
|
|
}
|
|
|
|
module.exports = {run}
|
|
|
|
function installedVolumeFilePath (crypto) {
|
|
return path.resolve(coinUtils.cryptoDir(crypto, options.blockchainDir), '.installed')
|
|
}
|
|
|
|
function isInstalledVolume (crypto) {
|
|
return fs.existsSync(installedVolumeFilePath(crypto))
|
|
}
|
|
|
|
function isInstalledSoftware (crypto) {
|
|
return common.isInstalledSoftware(crypto)
|
|
}
|
|
|
|
function processCryptos (codes) {
|
|
if (_.isEmpty(codes)) {
|
|
logger.info('No cryptos selected. Exiting.')
|
|
process.exit(0)
|
|
}
|
|
|
|
logger.info('Thanks! Installing: %s. Will take a while...', _.join(', ', codes))
|
|
|
|
const goodVolume = doVolume.prepareVolume()
|
|
|
|
if (!goodVolume) {
|
|
logger.error('There was an error preparing the disk volume. Exiting.')
|
|
process.exit(1)
|
|
}
|
|
|
|
const selectedCryptos = _.map(code => _.find(['code', code], cryptos), codes)
|
|
_.forEach(setupCrypto, selectedCryptos)
|
|
common.es('sudo supervisorctl reread')
|
|
common.es('sudo supervisorctl update')
|
|
|
|
const blockchainDir = options.blockchainDir
|
|
const backupDir = path.resolve(os.homedir(), 'backups')
|
|
const rsyncCmd = `( \
|
|
(crontab -l 2>/dev/null || echo -n "") | grep -v "@daily rsync ".*"wallet.dat"; \
|
|
echo "@daily rsync -r --prune-empty-dirs --include='*/' \
|
|
--include='wallet.dat' \
|
|
--exclude='*' ${blockchainDir} ${backupDir} > /dev/null" \
|
|
) | crontab -`
|
|
common.es(rsyncCmd)
|
|
|
|
_.forEach(updateCrypto, selectedCryptos)
|
|
|
|
logger.info('Installation complete.')
|
|
}
|
|
|
|
function setupCrypto (crypto) {
|
|
logger.info(`Installing ${crypto.display}...`)
|
|
const cryptoDir = coinUtils.cryptoDir(crypto, options.blockchainDir)
|
|
makeDir.sync(cryptoDir)
|
|
const cryptoPlugin = plugin(crypto)
|
|
const oldDir = process.cwd()
|
|
const tmpDir = '/tmp/blockchain-install'
|
|
|
|
makeDir.sync(tmpDir)
|
|
process.chdir(tmpDir)
|
|
common.es('rm -rf *')
|
|
common.fetchAndInstall(crypto)
|
|
|
|
cryptoPlugin.setup(cryptoDir)
|
|
|
|
common.writeFile(installedVolumeFilePath(crypto), '')
|
|
process.chdir(oldDir)
|
|
}
|
|
|
|
function updateCrypto (crypto) {
|
|
if (!common.isUpdateDependent(crypto.cryptoCode)) return
|
|
const cryptoPlugin = plugin(crypto)
|
|
cryptoPlugin.updateCore(common.getBinaries(crypto.cryptoCode))
|
|
}
|
|
|
|
function plugin (crypto) {
|
|
const plugin = PLUGINS[crypto.cryptoCode]
|
|
if (!plugin) throw new Error(`No such plugin: ${crypto.cryptoCode}`)
|
|
return plugin
|
|
}
|
|
|
|
function run () {
|
|
const choices = _.map(c => {
|
|
const checked = isInstalledSoftware(c) && isInstalledVolume(c)
|
|
return {
|
|
name: c.display,
|
|
value: c.code,
|
|
checked,
|
|
disabled: checked && 'Installed'
|
|
}
|
|
}, cryptos)
|
|
|
|
const questions = []
|
|
|
|
questions.push({
|
|
type: 'checkbox',
|
|
name: 'crypto',
|
|
message: 'Which cryptocurrencies would you like to install?',
|
|
choices
|
|
})
|
|
|
|
inquirer.prompt(questions)
|
|
.then(answers => processCryptos(answers.crypto))
|
|
}
|