chore: server code formatting
This commit is contained in:
parent
aedabcbdee
commit
68517170e2
234 changed files with 9824 additions and 6195 deletions
|
|
@ -7,7 +7,7 @@ const makeDir = require('make-dir')
|
|||
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
const logger = require('console-log-level')({level: 'info'})
|
||||
const logger = require('console-log-level')({ level: 'info' })
|
||||
|
||||
const { isDevMode } = require('../environment-helper')
|
||||
|
||||
|
|
@ -23,13 +23,15 @@ module.exports = {
|
|||
isInstalledSoftware,
|
||||
writeFile,
|
||||
getBinaries,
|
||||
isUpdateDependent
|
||||
isUpdateDependent,
|
||||
}
|
||||
|
||||
const BINARIES = {
|
||||
BTC: {
|
||||
defaultUrl: 'https://bitcoincore.org/bin/bitcoin-core-0.20.1/bitcoin-0.20.1-x86_64-linux-gnu.tar.gz',
|
||||
defaultUrlHash: '376194f06596ecfa40331167c39bc70c355f960280bd2a645fdbf18f66527397',
|
||||
defaultUrl:
|
||||
'https://bitcoincore.org/bin/bitcoin-core-0.20.1/bitcoin-0.20.1-x86_64-linux-gnu.tar.gz',
|
||||
defaultUrlHash:
|
||||
'376194f06596ecfa40331167c39bc70c355f960280bd2a645fdbf18f66527397',
|
||||
defaultDir: 'bitcoin-0.20.1/bin',
|
||||
url: 'https://bitcoincore.org/bin/bitcoin-core-28.0/bitcoin-28.0-x86_64-linux-gnu.tar.gz',
|
||||
dir: 'bitcoin-28.0/bin',
|
||||
|
|
@ -46,16 +48,20 @@ const BINARIES = {
|
|||
urlHash: '3cb82f490e9c8e88007a0216b5261b33ef0fda962b9258441b2def59cb272a4d',
|
||||
},
|
||||
DASH: {
|
||||
defaultUrl: 'https://github.com/dashpay/dash/releases/download/v18.1.0/dashcore-18.1.0-x86_64-linux-gnu.tar.gz',
|
||||
defaultUrlHash: 'd89c2afd78183f3ee815adcccdff02098be0c982633889e7b1e9c9656fbef219',
|
||||
defaultUrl:
|
||||
'https://github.com/dashpay/dash/releases/download/v18.1.0/dashcore-18.1.0-x86_64-linux-gnu.tar.gz',
|
||||
defaultUrlHash:
|
||||
'd89c2afd78183f3ee815adcccdff02098be0c982633889e7b1e9c9656fbef219',
|
||||
defaultDir: 'dashcore-18.1.0/bin',
|
||||
url: 'https://github.com/dashpay/dash/releases/download/v21.1.1/dashcore-21.1.1-x86_64-linux-gnu.tar.gz',
|
||||
dir: 'dashcore-21.1.1/bin',
|
||||
urlHash: 'c3157d4a82a3cb7c904a68e827bd1e629854fefcc0dcaf1de4343a810a190bf5',
|
||||
},
|
||||
LTC: {
|
||||
defaultUrl: 'https://download.litecoin.org/litecoin-0.18.1/linux/litecoin-0.18.1-x86_64-linux-gnu.tar.gz',
|
||||
defaultUrlHash: 'ca50936299e2c5a66b954c266dcaaeef9e91b2f5307069b9894048acf3eb5751',
|
||||
defaultUrl:
|
||||
'https://download.litecoin.org/litecoin-0.18.1/linux/litecoin-0.18.1-x86_64-linux-gnu.tar.gz',
|
||||
defaultUrlHash:
|
||||
'ca50936299e2c5a66b954c266dcaaeef9e91b2f5307069b9894048acf3eb5751',
|
||||
defaultDir: 'litecoin-0.18.1/bin',
|
||||
url: 'https://download.litecoin.org/litecoin-0.21.4/linux/litecoin-0.21.4-x86_64-linux-gnu.tar.gz',
|
||||
dir: 'litecoin-0.21.4/bin',
|
||||
|
|
@ -64,38 +70,44 @@ const BINARIES = {
|
|||
BCH: {
|
||||
url: 'https://github.com/bitcoin-cash-node/bitcoin-cash-node/releases/download/v28.0.0/bitcoin-cash-node-28.0.0-x86_64-linux-gnu.tar.gz',
|
||||
dir: 'bitcoin-cash-node-28.0.0/bin',
|
||||
files: [['bitcoind', 'bitcoincashd'], ['bitcoin-cli', 'bitcoincash-cli']],
|
||||
files: [
|
||||
['bitcoind', 'bitcoincashd'],
|
||||
['bitcoin-cli', 'bitcoincash-cli'],
|
||||
],
|
||||
urlHash: 'ba735cd3b70fab35ac1496e38596cec1f8d34989924376de001d4a86198f7158',
|
||||
},
|
||||
XMR: {
|
||||
url: 'https://downloads.getmonero.org/cli/monero-linux-x64-v0.18.3.4.tar.bz2',
|
||||
dir: 'monero-x86_64-linux-gnu-v0.18.3.4',
|
||||
files: [['monerod', 'monerod'], ['monero-wallet-rpc', 'monero-wallet-rpc']],
|
||||
files: [
|
||||
['monerod', 'monerod'],
|
||||
['monero-wallet-rpc', 'monero-wallet-rpc'],
|
||||
],
|
||||
urlHash: '51ba03928d189c1c11b5379cab17dd9ae8d2230056dc05c872d0f8dba4a87f1d',
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
const coinsUpdateDependent = ['BTC', 'LTC', 'DASH']
|
||||
|
||||
function firewall (ports) {
|
||||
function firewall(ports) {
|
||||
if (!ports || ports.length === 0) throw new Error('No ports supplied')
|
||||
const portsString = ports.join(',')
|
||||
es(`sudo ufw allow ${portsString}`)
|
||||
}
|
||||
|
||||
function randomPass () {
|
||||
function randomPass() {
|
||||
return crypto.randomBytes(32).toString('hex')
|
||||
}
|
||||
|
||||
function es (cmd) {
|
||||
const env = {HOME: os.userInfo().homedir}
|
||||
const options = {encoding: 'utf8', env}
|
||||
function es(cmd) {
|
||||
const env = { HOME: os.userInfo().homedir }
|
||||
const options = { encoding: 'utf8', env }
|
||||
const res = cp.execSync(cmd, options)
|
||||
logger.debug(res)
|
||||
return res.toString()
|
||||
}
|
||||
|
||||
function generateSupervisorConfig (cryptoCode, command, isWallet = false) {
|
||||
function generateSupervisorConfig(cryptoCode, command, isWallet = false) {
|
||||
return `[program:${cryptoCode}${isWallet ? `-wallet` : ``}]
|
||||
command=nice ${command}
|
||||
autostart=true
|
||||
|
|
@ -108,34 +120,46 @@ environment=HOME="/root"
|
|||
`
|
||||
}
|
||||
|
||||
function writeSupervisorConfig (coinRec, cmd, walletCmd = '') {
|
||||
function writeSupervisorConfig(coinRec, cmd, walletCmd = '') {
|
||||
if (isInstalledSoftware(coinRec)) return
|
||||
|
||||
const blockchain = coinRec.code
|
||||
|
||||
if (!_.isNil(coinRec.wallet)) {
|
||||
const supervisorConfigWallet = generateSupervisorConfig(blockchain, walletCmd, true)
|
||||
writeFile(`/etc/supervisor/conf.d/${coinRec.code}-wallet.conf`, supervisorConfigWallet)
|
||||
const supervisorConfigWallet = generateSupervisorConfig(
|
||||
blockchain,
|
||||
walletCmd,
|
||||
true,
|
||||
)
|
||||
writeFile(
|
||||
`/etc/supervisor/conf.d/${coinRec.code}-wallet.conf`,
|
||||
supervisorConfigWallet,
|
||||
)
|
||||
}
|
||||
|
||||
const supervisorConfig = generateSupervisorConfig(blockchain, cmd)
|
||||
writeFile(`/etc/supervisor/conf.d/${coinRec.code}.conf`, supervisorConfig)
|
||||
}
|
||||
|
||||
function isInstalledSoftware (coinRec) {
|
||||
function isInstalledSoftware(coinRec) {
|
||||
if (isDevMode()) {
|
||||
return fs.existsSync(`${BLOCKCHAIN_DIR}/${coinRec.code}/${coinRec.configFile}`)
|
||||
&& fs.existsSync(`${BLOCKCHAIN_DIR}/bin/${coinRec.daemon}`)
|
||||
return (
|
||||
fs.existsSync(
|
||||
`${BLOCKCHAIN_DIR}/${coinRec.code}/${coinRec.configFile}`,
|
||||
) && fs.existsSync(`${BLOCKCHAIN_DIR}/bin/${coinRec.daemon}`)
|
||||
)
|
||||
}
|
||||
|
||||
const nodeInstalled = fs.existsSync(`/etc/supervisor/conf.d/${coinRec.code}.conf`)
|
||||
const nodeInstalled = fs.existsSync(
|
||||
`/etc/supervisor/conf.d/${coinRec.code}.conf`,
|
||||
)
|
||||
const walletInstalled = _.isNil(coinRec.wallet)
|
||||
? true
|
||||
: fs.existsSync(`/etc/supervisor/conf.d/${coinRec.code}.wallet.conf`)
|
||||
return nodeInstalled && walletInstalled
|
||||
}
|
||||
|
||||
function fetchAndInstall (coinRec) {
|
||||
function fetchAndInstall(coinRec) {
|
||||
const requiresUpdate = isUpdateDependent(coinRec.cryptoCode)
|
||||
if (isInstalledSoftware(coinRec)) return
|
||||
|
||||
|
|
@ -149,12 +173,16 @@ function fetchAndInstall (coinRec) {
|
|||
|
||||
es(`wget -q ${url}`)
|
||||
if (es(`sha256sum ${downloadFile} | awk '{print $1}'`).trim() !== hash) {
|
||||
logger.info(`Failed to install ${coinRec.code}: Package signature do not match!`)
|
||||
logger.info(
|
||||
`Failed to install ${coinRec.code}: Package signature do not match!`,
|
||||
)
|
||||
return
|
||||
}
|
||||
es(`tar -xf ${downloadFile}`)
|
||||
|
||||
const usrBinDir = isDevMode() ? path.resolve(BLOCKCHAIN_DIR, 'bin') : '/usr/local/bin'
|
||||
const usrBinDir = isDevMode()
|
||||
? path.resolve(BLOCKCHAIN_DIR, 'bin')
|
||||
: '/usr/local/bin'
|
||||
|
||||
if (isDevMode()) {
|
||||
makeDir.sync(usrBinDir)
|
||||
|
|
@ -170,7 +198,7 @@ function fetchAndInstall (coinRec) {
|
|||
}, binaries.files)
|
||||
}
|
||||
|
||||
function writeFile (path, content) {
|
||||
function writeFile(path, content) {
|
||||
try {
|
||||
fs.writeFileSync(path, content)
|
||||
} catch (err) {
|
||||
|
|
@ -183,12 +211,12 @@ function writeFile (path, content) {
|
|||
}
|
||||
}
|
||||
|
||||
function getBinaries (coinCode) {
|
||||
function getBinaries(coinCode) {
|
||||
const binaries = BINARIES[coinCode]
|
||||
if (!binaries) throw new Error(`No such coin: ${coinCode}`)
|
||||
return binaries
|
||||
}
|
||||
|
||||
function isUpdateDependent (coinCode) {
|
||||
function isUpdateDependent(coinCode) {
|
||||
return _.includes(coinCode, coinsUpdateDependent)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue