feat: backport remote BTC node support
This commit is contained in:
parent
24473de6d5
commit
1b6ba5e6dc
15 changed files with 272 additions and 55 deletions
|
|
@ -7,6 +7,8 @@ const request = require('request-promise')
|
|||
const { utils: coinUtils } = require('@lamassu/coins')
|
||||
|
||||
const logger = require('../../logger')
|
||||
const { isRemoteNode, isRemoteWallet } = require('../../environment-helper')
|
||||
const { isEnvironmentValid } = require('../../blockchain/install')
|
||||
|
||||
const BLOCKCHAIN_DIR = process.env.BLOCKCHAIN_DIR
|
||||
|
||||
|
|
@ -28,7 +30,7 @@ function fetch (account = {}, method, params) {
|
|||
|
||||
if (_.isNil(account.port)) throw new Error('port attribute required for jsonRpc')
|
||||
|
||||
const url = _.defaultTo(`http://localhost:${account.port}`, account.url)
|
||||
const url = _.defaultTo(`http://${account.host}:${account.port}`, account.url)
|
||||
|
||||
return axios({
|
||||
method: 'post',
|
||||
|
|
@ -109,15 +111,30 @@ function parseConf (confPath) {
|
|||
|
||||
function rpcConfig (cryptoRec) {
|
||||
try {
|
||||
if (isRemoteWallet(cryptoRec) && isEnvironmentValid(cryptoRec)) {
|
||||
return {
|
||||
username: process.env[`${cryptoRec.cryptoCode}_NODE_USER`],
|
||||
password: process.env[`${cryptoRec.cryptoCode}_NODE_PASSWORD`],
|
||||
host: process.env[`${cryptoRec.cryptoCode}_NODE_RPC_HOST`],
|
||||
port: process.env[`${cryptoRec.cryptoCode}_NODE_RPC_PORT`]
|
||||
}
|
||||
}
|
||||
|
||||
const configPath = coinUtils.configPath(cryptoRec, BLOCKCHAIN_DIR)
|
||||
const config = parseConf(configPath)
|
||||
|
||||
return {
|
||||
username: config.rpcuser,
|
||||
password: config.rpcpassword,
|
||||
host: 'localhost',
|
||||
port: config.rpcport || cryptoRec.defaultPort
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error('Wallet is currently not installed!')
|
||||
if (!isEnvironmentValid(cryptoRec)) {
|
||||
logger.error('Environment is not correctly setup for remote wallet usage!')
|
||||
} else {
|
||||
logger.error('Wallet is currently not installed!')
|
||||
}
|
||||
return {
|
||||
port: cryptoRec.defaultPort
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue