diff --git a/bin/lamassu-update-wallet-nodes b/bin/lamassu-update-wallet-nodes new file mode 100644 index 00000000..701bf411 --- /dev/null +++ b/bin/lamassu-update-wallet-nodes @@ -0,0 +1,36 @@ +#!/usr/bin/env node + +const _ = require('lodash/fp') +const common = require('../lib/blockchain/common') +const { utils: coinUtils } = require('lamassu-coins') + +const cryptos = coinUtils.cryptoCurrencies() + +const PLUGINS = { + BTC: require('../lib/blockchain/bitcoin.js'), + LTC: require('../lib/blockchain/litecoin.js'), + ETH: require('../lib/blockchain/ethereum.js'), + DASH: require('../lib/blockchain/dash.js'), + ZEC: require('../lib/blockchain/zcash.js'), + BCH: require('../lib/blockchain/bitcoincash.js') +} + +function plugin (crypto) { + const plugin = PLUGINS[crypto.cryptoCode] + if (!plugin) throw new Error(`No such plugin: ${crypto.cryptoCode}`) + return plugin +} + +function run () { + _.forEach((crypto) => { + if (!_.includes(crypto.cryptoCode, _.keys(PLUGINS))) return + + const cryptoPlugin = plugin(crypto) + const status = common.es(`sudo supervisorctl status ${crypto.code} | awk '{ print $2 }'`).trim() + + if (status === 'RUNNING') cryptoPlugin.updateCore(common.getBinaries(crypto.cryptoCode), true) + if (status === 'STOPPED') cryptoPlugin.updateCore(common.getBinaries(crypto.cryptoCode), false) + }, cryptos) +} + +run() diff --git a/lib/blockchain/bitcoin.js b/lib/blockchain/bitcoin.js index bab38493..ddee67a4 100644 --- a/lib/blockchain/bitcoin.js +++ b/lib/blockchain/bitcoin.js @@ -16,9 +16,9 @@ function setup (dataDir) { common.writeSupervisorConfig(coinRec, cmd) } -function updateCore (coinRec) { - common.logger.info('Updating Bitcoin Core. This may take a minute.') - common.es(`sudo supervisorctl stop bitcoin`) +function updateCore (coinRec, isCurrentlyRunning) { + common.logger.info('Updating Bitcoin Core. This may take a minute...') + if (isCurrentlyRunning) common.es(`sudo supervisorctl stop bitcoin`) common.es(`curl -#o /tmp/bitcoin.tar.gz ${coinRec.url}`) common.es(`tar -xzf /tmp/bitcoin.tar.gz -C /tmp/`) @@ -27,8 +27,10 @@ function updateCore (coinRec) { common.es(`rm -r /tmp/${coinRec.dir.replace('/bin', '')}`) common.es(`rm /tmp/bitcoin.tar.gz`) - common.logger.info('Starting wallet...') - common.es(`sudo supervisorctl start bitcoin`) + if (isCurrentlyRunning) { + common.logger.info('Starting wallet...') + common.es(`sudo supervisorctl start bitcoin`) + } common.logger.info('Bitcoin Core is updated!') } diff --git a/lib/blockchain/bitcoincash.js b/lib/blockchain/bitcoincash.js index 8cc99961..09275ebe 100644 --- a/lib/blockchain/bitcoincash.js +++ b/lib/blockchain/bitcoincash.js @@ -4,7 +4,7 @@ const { utils: coinUtils } = require('lamassu-coins') const common = require('./common') -module.exports = {setup} +module.exports = { setup, updateCore } const coinRec = coinUtils.getCryptoCurrency('BCH') @@ -16,6 +16,26 @@ function setup (dataDir) { common.writeSupervisorConfig(coinRec, cmd) } +function updateCore (coinRec, isCurrentlyRunning) { + common.logger.info('Updating Bitcoin Cash. This may take a minute...') + if (isCurrentlyRunning) common.es(`sudo supervisorctl stop bitcoincash`) + common.es(`curl -#Lo /tmp/bitcoincash.tar.gz ${coinRec.url}`) + common.es(`tar -xzf /tmp/bitcoincash.tar.gz -C /tmp/`) + + common.logger.info('Updating wallet...') + common.es(`cp /tmp/${coinRec.dir}/bitcoind /usr/local/bin/bitcoincashd`) + common.es(`cp /tmp/${coinRec.dir}/bitcoin-cli /usr/local/bin/bitcoincash-cli`) + common.es(`rm -r /tmp/${coinRec.dir.replace('/bin', '')}`) + common.es(`rm /tmp/bitcoincash.tar.gz`) + + if (isCurrentlyRunning) { + common.logger.info('Starting wallet...') + common.es(`sudo supervisorctl start bitcoincash`) + } + + common.logger.info('Bitcoin Cash is updated!') +} + function buildConfig () { return `rpcuser=lamassuserver rpcpassword=${common.randomPass()} diff --git a/lib/blockchain/dash.js b/lib/blockchain/dash.js index af6b4d85..85fa82c6 100644 --- a/lib/blockchain/dash.js +++ b/lib/blockchain/dash.js @@ -4,7 +4,7 @@ const { utils: coinUtils } = require('lamassu-coins') const common = require('./common') -module.exports = {setup} +module.exports = { setup, updateCore } const coinRec = coinUtils.getCryptoCurrency('DASH') @@ -16,6 +16,52 @@ function setup (dataDir) { common.writeSupervisorConfig(coinRec, cmd) } +function updateCore (coinRec, isCurrentlyRunning) { + common.logger.info('Updating Dash Core. This may take a minute...') + if (isCurrentlyRunning) common.es(`sudo supervisorctl stop dash`) + common.es(`curl -#Lo /tmp/dash.tar.gz ${coinRec.url}`) + common.es(`tar -xzf /tmp/dash.tar.gz -C /tmp/`) + + common.logger.info('Updating wallet...') + common.es(`cp /tmp/${coinRec.dir}/* /usr/local/bin/`) + common.es(`rm -r /tmp/${coinRec.dir.replace('/bin', '')}`) + common.es(`rm /tmp/dash.tar.gz`) + + if (common.es(`grep -x "enableprivatesend=." /mnt/blockchains/dash/dash.conf`)) { + common.logger.info(`Switching from 'PrivateSend' to 'CoinJoin'...`) + common.es(`sed -i 's/enableprivatesend/enablecoinjoin/g' /mnt/blockchains/dash/dash.conf`) + } else if (common.es(`grep -x "enablecoinjoin=." /mnt/blockchains/dash/dash.conf`)) { + common.logger.info(`enablecoinjoin already defined, skipping...`) + } else { + common.logger.info(`Enabling CoinJoin in config file...`) + common.es(`echo -e "enablecoinjoin=1" >> /mnt/blockchains/dash/dash.conf`) + } + + if (common.es(`grep -x "privatesendautostart=." /mnt/blockchains/dash/dash.conf`)) { + common.logger.info(`Switching from 'PrivateSend' to 'CoinJoin'...`) + common.es(`sed -i 's/privatesendautostart/coinjoinautostart/g' /mnt/blockchains/dash/dash.conf`) + } else if (common.es(`grep -x "coinjoinautostart=." /mnt/blockchains/dash/dash.conf`)) { + common.logger.info(`coinjoinautostart already defined, skipping...`) + } else { + common.logger.info(`Enabling CoinJoin AutoStart in config file...`) + common.es(`echo -e "coinjoinautostart=1" >> /mnt/blockchains/dash/dash.conf`) + } + + if (common.es(`grep -x "litemode=." /mnt/blockchains/dash/dash.conf`)) { + common.logger.info(`Switching from 'LiteMode' to 'DisableGovernance'...`) + common.es(`sed -i 's/litemode/disablegovernance/g' /mnt/blockchains/dash/dash.conf`) + } else { + common.es(`echo "disablegovernance already defined, skipping..."`) + } + + if (isCurrentlyRunning) { + common.logger.info('Starting wallet...') + common.es(`sudo supervisorctl start dash`) + } + + common.logger.info('Dash Core is updated!') +} + function buildConfig () { return `rpcuser=lamassuserver rpcpassword=${common.randomPass()} diff --git a/lib/blockchain/ethereum.js b/lib/blockchain/ethereum.js index 93eb2abe..dead615e 100644 --- a/lib/blockchain/ethereum.js +++ b/lib/blockchain/ethereum.js @@ -2,7 +2,26 @@ const { utils: coinUtils } = require('lamassu-coins') const common = require('./common') -module.exports = {setup} +module.exports = { setup, updateCore } + +function updateCore (coinRec, isCurrentlyRunning) { + common.logger.info('Updating the Geth Ethereum wallet. This may take a minute...') + if (isCurrentlyRunning) common.es(`sudo supervisorctl stop ethereum`) + common.es(`curl -#o /tmp/ethereum.tar.gz ${coinRec.url}`) + common.es(`tar -xzf /tmp/ethereum.tar.gz -C /tmp/`) + + common.logger.info('Updating wallet...') + common.es(`cp /tmp/${coinRec.dir}/geth /usr/local/bin/geth`) + common.es(`rm -r /tmp/${coinRec.dir}`) + common.es(`rm /tmp/ethereum.tar.gz`) + + if (isCurrentlyRunning) { + common.logger.info('Starting wallet...') + common.es(`sudo supervisorctl start ethereum`) + } + + common.logger.info('Geth is updated!') +} function setup (dataDir) { const coinRec = coinUtils.getCryptoCurrency('ETH') diff --git a/lib/blockchain/litecoin.js b/lib/blockchain/litecoin.js index 48e24e2d..1c721c6f 100644 --- a/lib/blockchain/litecoin.js +++ b/lib/blockchain/litecoin.js @@ -4,7 +4,7 @@ const { utils: coinUtils } = require('lamassu-coins') const common = require('./common') -module.exports = {setup} +module.exports = { setup, updateCore } const coinRec = coinUtils.getCryptoCurrency('LTC') @@ -16,6 +16,25 @@ function setup (dataDir) { common.writeSupervisorConfig(coinRec, cmd) } +function updateCore (coinRec, isCurrentlyRunning) { + common.logger.info('Updating Litecoin Core. This may take a minute...') + if (isCurrentlyRunning) common.es(`sudo supervisorctl stop litecoin`) + common.es(`curl -#o /tmp/litecoin.tar.gz ${coinRec.url}`) + common.es(`tar -xzf /tmp/litecoin.tar.gz -C /tmp/`) + + common.logger.info('Updating wallet...') + common.es(`cp /tmp/${coinRec.dir}/* /usr/local/bin/`) + common.es(`rm -r /tmp/${coinRec.dir.replace('/bin', '')}`) + common.es(`rm /tmp/litecoin.tar.gz`) + + if (isCurrentlyRunning) { + common.logger.info('Starting wallet...') + common.es(`sudo supervisorctl start litecoin`) + } + + common.logger.info('Litecoin Core is updated!') +} + function buildConfig () { return `rpcuser=lamassuserver rpcpassword=${common.randomPass()} diff --git a/lib/blockchain/zcash.js b/lib/blockchain/zcash.js index 0032609a..56364b4f 100644 --- a/lib/blockchain/zcash.js +++ b/lib/blockchain/zcash.js @@ -4,11 +4,30 @@ const { utils: coinUtils } = require('lamassu-coins') const common = require('./common') -module.exports = {setup} +module.exports = { setup, updateCore } const es = common.es const logger = common.logger +function updateCore (coinRec, isCurrentlyRunning) { + common.logger.info('Updating your Zcash wallet. This may take a minute...') + if (isCurrentlyRunning) common.es(`sudo supervisorctl stop zcash`) + common.es(`curl -#Lo /tmp/zcash.tar.gz ${coinRec.url}`) + common.es(`tar -xzf /tmp/zcash.tar.gz -C /tmp/`) + + common.logger.info('Updating wallet...') + common.es(`cp /tmp/${coinRec.dir}/* /usr/local/bin/`) + common.es(`rm -r /tmp/${coinRec.dir.replace('/bin', '')}`) + common.es(`rm /tmp/zcash.tar.gz`) + + if (isCurrentlyRunning) { + common.logger.info('Starting wallet...') + common.es(`sudo supervisorctl start zcash`) + } + + common.logger.info('Zcash is updated!') +} + function setup (dataDir) { es('sudo apt-get update') es('sudo apt-get install libgomp1 -y') diff --git a/package.json b/package.json index b75034b6..9b182a1a 100644 --- a/package.json +++ b/package.json @@ -101,6 +101,7 @@ "lamassu-ofac-update": "./bin/lamassu-ofac-update", "lamassu-send-coins": "./bin/lamassu-send-coins", "lamassu-update-to-mnemonic": "./bin/lamassu-update-to-mnemonic", + "lamassu-update-wallet-nodes": "./bin/lamassu-update-wallet-nodes", "lamassu-configure-frontcamera": "./bin/lamassu-configure-frontcamera", "lamassu-ofac-update-sources": "./bin/lamassu-ofac-update-sources", "lamassu-devices": "./bin/lamassu-devices",