From fb70a00f77864e7c3aab48bde14f46b36f211c11 Mon Sep 17 00:00:00 2001 From: Taranto Date: Thu, 15 Dec 2022 19:55:17 +0000 Subject: [PATCH] fix: scripts using old options --- bin/lamassu-eth-sweep-to-new-wallet | 16 +++---- bin/lamassu-migrate-config | 15 ------ lib/migrate-options.js | 67 --------------------------- lib/options.js | 9 ---- lib/plugins/wallet/monerod/monerod.js | 1 - package.json | 1 - test/unit/migrate-options.js | 64 ------------------------- 7 files changed, 8 insertions(+), 165 deletions(-) delete mode 100755 bin/lamassu-migrate-config delete mode 100644 lib/migrate-options.js delete mode 100644 lib/options.js delete mode 100644 test/unit/migrate-options.js diff --git a/bin/lamassu-eth-sweep-to-new-wallet b/bin/lamassu-eth-sweep-to-new-wallet index facc2e2f..4c773ce1 100644 --- a/bin/lamassu-eth-sweep-to-new-wallet +++ b/bin/lamassu-eth-sweep-to-new-wallet @@ -16,7 +16,6 @@ const web3 = new Web3() const Tx = require('ethereumjs-tx') const mnemonicHelpers = require('../lib/mnemonic-helpers') -const options = require('../lib/options') const settingsLoader = require('../lib/new-settings-loader') const BN = require('../lib/bn') const ph = require('../lib/plugin-helper') @@ -28,21 +27,22 @@ const defaultPrefixPath = "m/44'/60'/1'/0'" let lastUsedNonces = {} const hex = bigNum => '0x' + bigNum.integerValue(BN.ROUND_DOWN).toString(16) +const MNEMONIC_PATH = process.env.MNEMONIC_PATH function writeNewMnemonic (mnemonic) { - return fs.writeFile(`${options.mnemonicPath}-new-temp`, mnemonic) - .then(() => `${options.mnemonicPath}-new-temp`) + return fs.writeFile(`${MNEMONIC_PATH}-new-temp`, mnemonic) + .then(() => `${MNEMONIC_PATH}-new-temp`) } function renameNewMnemonic () { - return fs.rename(`${options.mnemonicPath}-new-temp`, `${options.mnemonicPath}`) - .then(() => options.mnemonicPath) + return fs.rename(`${MNEMONIC_PATH}-new-temp`, `${MNEMONIC_PATH}`) + .then(() => MNEMONIC_PATH) } function backupMnemonic () { - const folderPath = path.dirname(options.mnemonicPath) + const folderPath = path.dirname(MNEMONIC_PATH) const fileName = path.resolve(folderPath, `mnemonic-${Date.now()}.txt`) - return fs.copyFile(options.mnemonicPath, fileName) + return fs.copyFile(MNEMONIC_PATH, fileName) .then(() => fileName) } @@ -198,7 +198,7 @@ function generateTx (_toAddress, wallet, amount, cryptoCode, opts) { } function fetchWallet (settings, cryptoCode) { - return fs.readFile(options.mnemonicPath, 'utf8') + return fs.readFile(MNEMONIC_PATH, 'utf8') .then(mnemonic => { const computeSeed = masterSeed => hkdf(masterSeed, 32, { salt: 'lamassu-server-salt', info: 'wallet-seed' }) diff --git a/bin/lamassu-migrate-config b/bin/lamassu-migrate-config deleted file mode 100755 index de8b90a5..00000000 --- a/bin/lamassu-migrate-config +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env node - -require('../lib/environment-helper') - -const migrate = require('../lib/migrate-options') - -migrate.run() - .then(() => { - console.log('lamassu.json Migration succeeded.') - process.exit(0) - }) - .catch(err => { - console.error('lamassu.json Migration failed: %s', err) - process.exit(1) - }) diff --git a/lib/migrate-options.js b/lib/migrate-options.js deleted file mode 100644 index 07ba83fb..00000000 --- a/lib/migrate-options.js +++ /dev/null @@ -1,67 +0,0 @@ -const _ = require('lodash/fp') -const fs = require('fs') -const os = require('os') -const makeDir = require('make-dir') -const path = require('path') -const cp = require('child_process') - -const load = require('./options-loader') -const logger = require('./logger') - -// current path of lamassu-server project -const currentBasePath = path.dirname(__dirname) -// get path as array of path components -const paths = _.wrap(_.split, path.sep) -// find the index of the lamassu-server directory -// /usr/lib/node_modules/lamassu-server/certs/Lamassu_OP.pem => 3 -const indexOfLs = _.flow(paths, _.wrap(_.indexOf, 'lamassu-server')) - -module.exports = {run, mapKeyValuesDeep, updateOptionBasepath} - -function mapKeyValuesDeep (cb, obj, key) { - if (_.isArray(obj)) { - return _.mapValues((val, key) => mapKeyValuesDeep(cb, val, key), obj) - } else if (_.isObject(obj)) { - return _.pickBy((val, key) => mapKeyValuesDeep(cb, val, key), obj) - } else { - return cb(obj, key) - } -} - -function updateOptionBasepath (result, optionName) { - const currentPath = _.get(optionName, result) - - // process only keys that contains - // lamassu-server dir in its path - const i = indexOfLs(currentPath) - if (i === -1) { - return - } - - // workout the relative path - // /usr/lib/node_modules/lamassu-server/certs/Lamassu_OP.pem => certs/Lamassu_OP.pem - const rPath = _.drop(i + 1, paths(currentPath)) - - // prepend the current lamassu-server path - // certs/Lamassu_OP.pem => /usr/local/lib/node_modules/lamassu-server/certs/Lamassu_OP.pem - const newPath = _.join(path.sep, _.concat([currentBasePath], rPath)) - - // update this option - // if the value has changed - if (!_.isEqual(currentPath, newPath)) { - logger.info(`Migrating option ${optionName} to new path ${newPath}`) - result[optionName] = newPath - } -} - -async function run () { - // load current opts - const options = load().opts - const shouldMigrate = !fs.existsSync(path.resolve(__dirname, '../.env')) - - // write the resulting .env - if (shouldMigrate) { - const postgresPw = new RegExp(':(\\w*)@').exec(options.postgresql)[1] - cp.spawnSync('node', ['tools/build-prod-env.js', '--db-password', postgresPw, '--hostname', options.hostname], { cwd: currentBasePath, encoding: 'utf-8' }) - } -} diff --git a/lib/options.js b/lib/options.js deleted file mode 100644 index 9f777234..00000000 --- a/lib/options.js +++ /dev/null @@ -1,9 +0,0 @@ -const _ = require('lodash/fp') -const argv = require('minimist')(process.argv.slice(2)) -const load = require('./options-loader') - -const serverConfig = load().opts -const defaults = {logLevel: 'info'} -const commandLine = {logLevel: argv.logLevel} - -module.exports = _.mergeAll([defaults, serverConfig, commandLine]) diff --git a/lib/plugins/wallet/monerod/monerod.js b/lib/plugins/wallet/monerod/monerod.js index 86c198d7..d5aa5098 100644 --- a/lib/plugins/wallet/monerod/monerod.js +++ b/lib/plugins/wallet/monerod/monerod.js @@ -7,7 +7,6 @@ const { default: PQueue } = require('p-queue') const BN = require('../../../bn') const E = require('../../../error') const logger = require('../../../logger') -const options = require('../../../options') const jsonRpc = require('../../common/json-rpc') const BLOCKCHAIN_DIR = process.env.BLOCKCHAIN_DIR diff --git a/package.json b/package.json index accc46bb..407c7299 100644 --- a/package.json +++ b/package.json @@ -96,7 +96,6 @@ "bin": { "lamassu-server": "./bin/lamassu-server", "lamassu-migrate": "./bin/lamassu-migrate", - "lamassu-migrate-config": "./bin/lamassu-migrate-config", "lamassu-register": "./bin/lamassu-register", "lamassu-admin-server": "./bin/lamassu-admin-server", "hkdf": "./bin/hkdf", diff --git a/test/unit/migrate-options.js b/test/unit/migrate-options.js deleted file mode 100644 index 10ae126e..00000000 --- a/test/unit/migrate-options.js +++ /dev/null @@ -1,64 +0,0 @@ -import test from 'ava' -import _ from 'lodash/fp' -import path from 'path' - -import {mapKeyValuesDeep, updateOptionBasepath} from '../../lib/migrate-options' - -const currentBasePath = path.dirname(path.dirname(__dirname)) - -test('mapKeyValuesDeep', t => { - const test = { - a: { - b: 1 - }, - c: [ - { - d: 2, - e: 3 - } - ], - f: { - g: { - h: [ - { - i: 4 - } - ] - } - } - } - const expected = [{b: 1}, {d: 2}, {e: 3}, {i: 4}] - - const result = [] - mapKeyValuesDeep((v, k) => { - result.push(_.fromPairs([[k, v]])) - }, test) - - t.deepEqual(result, expected) -}) - -test('updateOptionBasepath', t => { - const test = { - someBooleanOption: true, - someStringOption: 'my-custom-option', - customExternalPath: '/usr/lib/node_modules/ava', - seedPath: '/etc/lamassu/seeds/seed.txt', - caPath: '/usr/lib/node_modules/lamassu-server/certs/Lamassu_OP_Root_CA.pem' - } - const expected = { - someBooleanOption: true, - someStringOption: 'my-custom-option', - customExternalPath: '/usr/lib/node_modules/ava', - seedPath: '/etc/lamassu/seeds/seed.txt', - caPath: path.join(currentBasePath, 'certs/Lamassu_OP_Root_CA.pem') - } - - let result = _.clone(test) - - _.each( - _.wrap(updateOptionBasepath, result), - _.keys(test) - ) - - t.deepEqual(result, expected) -})