From 84256bce6c8042349e025e1a430da711f93edfab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Tue, 7 Sep 2021 23:21:25 +0100 Subject: [PATCH 1/5] feat: add script to update nodes --- bin/lamassu-update-nodes.js | 35 +++++++++++++++++++++++++ lib/blockchain/bitcoin.js | 12 +++++---- lib/blockchain/bitcoincash.js | 22 +++++++++++++++- lib/blockchain/dash.js | 48 ++++++++++++++++++++++++++++++++++- lib/blockchain/ethereum.js | 21 ++++++++++++++- lib/blockchain/litecoin.js | 21 ++++++++++++++- lib/blockchain/zcash.js | 21 ++++++++++++++- package.json | 1 + 8 files changed, 171 insertions(+), 10 deletions(-) create mode 100644 bin/lamassu-update-nodes.js diff --git a/bin/lamassu-update-nodes.js b/bin/lamassu-update-nodes.js new file mode 100644 index 00000000..719d4197 --- /dev/null +++ b/bin/lamassu-update-nodes.js @@ -0,0 +1,35 @@ +#!/usr/bin/env node + +const _ = require('lodash/fp') + +const { utils: coinUtils } = require('lamassu-coins') +const cryptos = coinUtils.cryptoCurrencies() + +const common = require('../lib/blockchain/common') + +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) => { + const cryptoPlugin = plugin(crypto) + + const status = common.es(`sudo supervisorctl status ${crypto.code} | awk '{ print $2 }'`) + 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..66030e1b 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}/bin/* /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..e08abfda 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}/bin/* /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 dafdfd7a..de215164 100644 --- a/package.json +++ b/package.json @@ -99,6 +99,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-nodes": "./bin/lamassu-update-nodes", "lamassu-configure-frontcamera": "./bin/lamassu-configure-frontcamera", "lamassu-ofac-update-sources": "./bin/lamassu-ofac-update-sources", "lamassu-devices": "./bin/lamassu-devices", From b53090db0550fd2e034612966b8d0406c1f5a832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Wed, 8 Sep 2021 14:48:50 +0100 Subject: [PATCH 2/5] fix: rename script name --- bin/{lamassu-update-nodes.js => lamassu-update-nodes} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename bin/{lamassu-update-nodes.js => lamassu-update-nodes} (100%) diff --git a/bin/lamassu-update-nodes.js b/bin/lamassu-update-nodes similarity index 100% rename from bin/lamassu-update-nodes.js rename to bin/lamassu-update-nodes From 9152c48e14d68a430a2bf934e9278c2a813e43fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Wed, 8 Sep 2021 17:07:15 +0100 Subject: [PATCH 3/5] fix: trim cmd output and binaries paths --- bin/{lamassu-update-nodes => lamassu-update-wallet-nodes} | 6 ++++-- lib/blockchain/dash.js | 2 +- lib/blockchain/litecoin.js | 2 +- package.json | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) rename bin/{lamassu-update-nodes => lamassu-update-wallet-nodes} (91%) diff --git a/bin/lamassu-update-nodes b/bin/lamassu-update-wallet-nodes similarity index 91% rename from bin/lamassu-update-nodes rename to bin/lamassu-update-wallet-nodes index 719d4197..ef0cca23 100644 --- a/bin/lamassu-update-nodes +++ b/bin/lamassu-update-wallet-nodes @@ -24,9 +24,11 @@ function plugin (crypto) { function run () { _.forEach((crypto) => { - const cryptoPlugin = plugin(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() - const status = common.es(`sudo supervisorctl status ${crypto.code} | awk '{ print $2 }'`) if (status === 'RUNNING') cryptoPlugin.updateCore(common.getBinaries(crypto.cryptoCode), true) if (status === 'STOPPED') cryptoPlugin.updateCore(common.getBinaries(crypto.cryptoCode), false) }, cryptos) diff --git a/lib/blockchain/dash.js b/lib/blockchain/dash.js index 66030e1b..85fa82c6 100644 --- a/lib/blockchain/dash.js +++ b/lib/blockchain/dash.js @@ -23,7 +23,7 @@ function updateCore (coinRec, isCurrentlyRunning) { common.es(`tar -xzf /tmp/dash.tar.gz -C /tmp/`) common.logger.info('Updating wallet...') - common.es(`cp /tmp/${coinRec.dir}/bin/* /usr/local/bin/`) + 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`) diff --git a/lib/blockchain/litecoin.js b/lib/blockchain/litecoin.js index e08abfda..1c721c6f 100644 --- a/lib/blockchain/litecoin.js +++ b/lib/blockchain/litecoin.js @@ -23,7 +23,7 @@ function updateCore (coinRec, isCurrentlyRunning) { common.es(`tar -xzf /tmp/litecoin.tar.gz -C /tmp/`) common.logger.info('Updating wallet...') - common.es(`cp /tmp/${coinRec.dir}/bin/* /usr/local/bin/`) + 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`) diff --git a/package.json b/package.json index de215164..e50760ab 100644 --- a/package.json +++ b/package.json @@ -99,7 +99,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-nodes": "./bin/lamassu-update-nodes", + "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", From 358d6195e8afb794e1b4382fd8f06f8285b79eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Thu, 9 Sep 2021 14:39:17 +0100 Subject: [PATCH 4/5] fix: remove extra line --- bin/lamassu-update-wallet-nodes | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/lamassu-update-wallet-nodes b/bin/lamassu-update-wallet-nodes index ef0cca23..8b772a25 100644 --- a/bin/lamassu-update-wallet-nodes +++ b/bin/lamassu-update-wallet-nodes @@ -4,7 +4,6 @@ const _ = require('lodash/fp') const { utils: coinUtils } = require('lamassu-coins') const cryptos = coinUtils.cryptoCurrencies() - const common = require('../lib/blockchain/common') const PLUGINS = { From ff43930847fc76dae0264459cf36fbef9463e7c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Thu, 9 Sep 2021 14:40:53 +0100 Subject: [PATCH 5/5] fix: organize imports --- bin/lamassu-update-wallet-nodes | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/lamassu-update-wallet-nodes b/bin/lamassu-update-wallet-nodes index 8b772a25..701bf411 100644 --- a/bin/lamassu-update-wallet-nodes +++ b/bin/lamassu-update-wallet-nodes @@ -1,10 +1,10 @@ #!/usr/bin/env node const _ = require('lodash/fp') - -const { utils: coinUtils } = require('lamassu-coins') -const cryptos = coinUtils.cryptoCurrencies() const common = require('../lib/blockchain/common') +const { utils: coinUtils } = require('lamassu-coins') + +const cryptos = coinUtils.cryptoCurrencies() const PLUGINS = { BTC: require('../lib/blockchain/bitcoin.js'),