fix: scripts using old options
This commit is contained in:
parent
008f3c9049
commit
fb70a00f77
7 changed files with 8 additions and 165 deletions
|
|
@ -16,7 +16,6 @@ const web3 = new Web3()
|
||||||
const Tx = require('ethereumjs-tx')
|
const Tx = require('ethereumjs-tx')
|
||||||
|
|
||||||
const mnemonicHelpers = require('../lib/mnemonic-helpers')
|
const mnemonicHelpers = require('../lib/mnemonic-helpers')
|
||||||
const options = require('../lib/options')
|
|
||||||
const settingsLoader = require('../lib/new-settings-loader')
|
const settingsLoader = require('../lib/new-settings-loader')
|
||||||
const BN = require('../lib/bn')
|
const BN = require('../lib/bn')
|
||||||
const ph = require('../lib/plugin-helper')
|
const ph = require('../lib/plugin-helper')
|
||||||
|
|
@ -28,21 +27,22 @@ const defaultPrefixPath = "m/44'/60'/1'/0'"
|
||||||
let lastUsedNonces = {}
|
let lastUsedNonces = {}
|
||||||
|
|
||||||
const hex = bigNum => '0x' + bigNum.integerValue(BN.ROUND_DOWN).toString(16)
|
const hex = bigNum => '0x' + bigNum.integerValue(BN.ROUND_DOWN).toString(16)
|
||||||
|
const MNEMONIC_PATH = process.env.MNEMONIC_PATH
|
||||||
|
|
||||||
function writeNewMnemonic (mnemonic) {
|
function writeNewMnemonic (mnemonic) {
|
||||||
return fs.writeFile(`${options.mnemonicPath}-new-temp`, mnemonic)
|
return fs.writeFile(`${MNEMONIC_PATH}-new-temp`, mnemonic)
|
||||||
.then(() => `${options.mnemonicPath}-new-temp`)
|
.then(() => `${MNEMONIC_PATH}-new-temp`)
|
||||||
}
|
}
|
||||||
|
|
||||||
function renameNewMnemonic () {
|
function renameNewMnemonic () {
|
||||||
return fs.rename(`${options.mnemonicPath}-new-temp`, `${options.mnemonicPath}`)
|
return fs.rename(`${MNEMONIC_PATH}-new-temp`, `${MNEMONIC_PATH}`)
|
||||||
.then(() => options.mnemonicPath)
|
.then(() => MNEMONIC_PATH)
|
||||||
}
|
}
|
||||||
|
|
||||||
function backupMnemonic () {
|
function backupMnemonic () {
|
||||||
const folderPath = path.dirname(options.mnemonicPath)
|
const folderPath = path.dirname(MNEMONIC_PATH)
|
||||||
const fileName = path.resolve(folderPath, `mnemonic-${Date.now()}.txt`)
|
const fileName = path.resolve(folderPath, `mnemonic-${Date.now()}.txt`)
|
||||||
return fs.copyFile(options.mnemonicPath, fileName)
|
return fs.copyFile(MNEMONIC_PATH, fileName)
|
||||||
.then(() => fileName)
|
.then(() => fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -198,7 +198,7 @@ function generateTx (_toAddress, wallet, amount, cryptoCode, opts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchWallet (settings, cryptoCode) {
|
function fetchWallet (settings, cryptoCode) {
|
||||||
return fs.readFile(options.mnemonicPath, 'utf8')
|
return fs.readFile(MNEMONIC_PATH, 'utf8')
|
||||||
.then(mnemonic => {
|
.then(mnemonic => {
|
||||||
const computeSeed = masterSeed =>
|
const computeSeed = masterSeed =>
|
||||||
hkdf(masterSeed, 32, { salt: 'lamassu-server-salt', info: 'wallet-seed' })
|
hkdf(masterSeed, 32, { salt: 'lamassu-server-salt', info: 'wallet-seed' })
|
||||||
|
|
|
||||||
|
|
@ -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)
|
|
||||||
})
|
|
||||||
|
|
@ -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' })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -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])
|
|
||||||
|
|
@ -7,7 +7,6 @@ const { default: PQueue } = require('p-queue')
|
||||||
const BN = require('../../../bn')
|
const BN = require('../../../bn')
|
||||||
const E = require('../../../error')
|
const E = require('../../../error')
|
||||||
const logger = require('../../../logger')
|
const logger = require('../../../logger')
|
||||||
const options = require('../../../options')
|
|
||||||
const jsonRpc = require('../../common/json-rpc')
|
const jsonRpc = require('../../common/json-rpc')
|
||||||
|
|
||||||
const BLOCKCHAIN_DIR = process.env.BLOCKCHAIN_DIR
|
const BLOCKCHAIN_DIR = process.env.BLOCKCHAIN_DIR
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,6 @@
|
||||||
"bin": {
|
"bin": {
|
||||||
"lamassu-server": "./bin/lamassu-server",
|
"lamassu-server": "./bin/lamassu-server",
|
||||||
"lamassu-migrate": "./bin/lamassu-migrate",
|
"lamassu-migrate": "./bin/lamassu-migrate",
|
||||||
"lamassu-migrate-config": "./bin/lamassu-migrate-config",
|
|
||||||
"lamassu-register": "./bin/lamassu-register",
|
"lamassu-register": "./bin/lamassu-register",
|
||||||
"lamassu-admin-server": "./bin/lamassu-admin-server",
|
"lamassu-admin-server": "./bin/lamassu-admin-server",
|
||||||
"hkdf": "./bin/hkdf",
|
"hkdf": "./bin/hkdf",
|
||||||
|
|
|
||||||
|
|
@ -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)
|
|
||||||
})
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue