chore: integrate new admin with l-s
This commit is contained in:
parent
6b3db134e7
commit
bf8f1d991c
72 changed files with 1493 additions and 1611 deletions
|
|
@ -7,7 +7,8 @@ const fs = pify(require('fs'))
|
|||
|
||||
const db = require('../db')
|
||||
const mnemonicHelpers = require('../mnemonic-helpers')
|
||||
const configManager = require('../config-manager')
|
||||
const configManager = require('../new-config-manager')
|
||||
const complianceTriggers = require('../compliance-triggers')
|
||||
const options = require('../options')
|
||||
const logger = require('../logger')
|
||||
const plugins = require('../plugins')
|
||||
|
|
@ -18,19 +19,21 @@ const MAX_CONTENT_LENGTH = 2000
|
|||
// How long a machine can be down before it's considered offline
|
||||
const STALE_INTERVAL = '2 minutes'
|
||||
|
||||
module.exports = { update, mapRecord }
|
||||
module.exports = { update }
|
||||
|
||||
function mapCoin (info, deviceId, settings, cryptoCode) {
|
||||
const config = info.config
|
||||
const rates = plugins(settings, deviceId).buildRates(info.rates)[cryptoCode] || { cashIn: null, cashOut: null }
|
||||
const cryptoConfig = configManager.scoped(cryptoCode, deviceId, config)
|
||||
const unscoped = configManager.unscoped(config)
|
||||
const showRates = unscoped.coinAtmRadarShowRates
|
||||
function mapCoin (rates, deviceId, settings, cryptoCode) {
|
||||
const config = settings.config
|
||||
const buildedRates = plugins(settings, deviceId).buildRates(rates)[cryptoCode] || { cashIn: null, cashOut: null }
|
||||
|
||||
const cashInFee = showRates ? cryptoConfig.cashInCommission / 100 : null
|
||||
const cashOutFee = showRates ? cryptoConfig.cashOutCommission / 100 : null
|
||||
const cashInRate = showRates ? _.invoke('cashIn.toNumber', rates) : null
|
||||
const cashOutRate = showRates ? _.invoke('cashOut.toNumber', rates) : null
|
||||
const commissions = configManager.getCommissions(cryptoCode, deviceId, config)
|
||||
const coinAtmRadar = configManager.getCoinAtmRadar(config)
|
||||
|
||||
const showCommissions = coinAtmRadar.commissions
|
||||
|
||||
const cashInFee = showCommissions ? commissions.cashIn / 100 : null
|
||||
const cashOutFee = showCommissions ? commissions.cashOut / 100 : null
|
||||
const cashInRate = showCommissions ? _.invoke('cashIn.toNumber', buildedRates) : null
|
||||
const cashOutRate = showCommissions ? _.invoke('cashOut.toNumber', buildedRates) : null
|
||||
|
||||
return {
|
||||
cryptoCode,
|
||||
|
|
@ -41,33 +44,51 @@ function mapCoin (info, deviceId, settings, cryptoCode) {
|
|||
}
|
||||
}
|
||||
|
||||
function mapIdentification (info, deviceId) {
|
||||
const machineConfig = configManager.machineScoped(deviceId, info.config)
|
||||
function mapIdentification (config, deviceId) {
|
||||
const triggers = configManager.getTriggers(deviceId, config)
|
||||
const compatTriggers = complianceTriggers.getBackwardsCompatibleTriggers(triggers)
|
||||
|
||||
return {
|
||||
isPhone: machineConfig.smsVerificationActive,
|
||||
isPhone: !!compatTriggers.sms,
|
||||
isPalmVein: false,
|
||||
isPhoto: false,
|
||||
isIdDocScan: machineConfig.idCardDataVerificationActive,
|
||||
isPhoto: !!compatTriggers.facephoto,
|
||||
isIdDocScan: !!compatTriggers.idData,
|
||||
isFingerprint: false
|
||||
}
|
||||
}
|
||||
|
||||
function mapMachine (info, settings, machineRow) {
|
||||
function mapMachine (rates, settings, machineRow) {
|
||||
const deviceId = machineRow.device_id
|
||||
const config = info.config
|
||||
const machineConfig = configManager.machineScoped(deviceId, config)
|
||||
const config = settings.config
|
||||
|
||||
const coinAtmRadar = configManager.getCoinAtmRadar(config)
|
||||
const triggers = configManager.getTriggers(deviceId, config)
|
||||
const compatTriggers = complianceTriggers.getBackwardsCompatibleTriggers(triggers)
|
||||
const locale = configManager.getLocale(deviceId, config)
|
||||
const cashOutConfig = configManager.getCashOut(deviceId, config)
|
||||
|
||||
const lastOnline = machineRow.last_online.toISOString()
|
||||
const status = machineRow.stale ? 'online' : 'offline'
|
||||
const showSupportedCryptocurrencies = coinAtmRadar.supportedCryptocurrencies
|
||||
const showSupportedFiat = coinAtmRadar.supportedFiat
|
||||
const showSupportedBuySellDirection = coinAtmRadar.supportedBuySellDirection
|
||||
const showLimitsAndVerification = coinAtmRadar.limitsAndVerification
|
||||
|
||||
const cashLimit = machineConfig.hardLimitVerificationActive
|
||||
? machineConfig.hardLimitVerificationThreshold
|
||||
: Infinity
|
||||
// TODO new-admin: this is relaying info with backwards compatible triggers
|
||||
// need to get in touch with coinatmradar before updating this
|
||||
const cashLimit = showLimitsAndVerification ? (
|
||||
!!compatTriggers.block
|
||||
? compatTriggers.block
|
||||
: Infinity ) : null
|
||||
|
||||
const cryptoCurrencies = machineConfig.cryptoCurrencies
|
||||
const identification = mapIdentification(info, deviceId)
|
||||
const coins = _.map(_.partial(mapCoin, [info, deviceId, settings]), cryptoCurrencies)
|
||||
const cryptoCurrencies = locale.cryptoCurrencies
|
||||
const cashInEnabled = showSupportedBuySellDirection ? true : null
|
||||
const cashOutEnabled = showSupportedBuySellDirection ? cashOutConfig.active : null
|
||||
const fiat = showSupportedFiat ? locale.fiatCurrency : null
|
||||
const identification = mapIdentification(config, deviceId)
|
||||
const coins = showSupportedCryptocurrencies ?
|
||||
_.map(_.partial(mapCoin, [rates, deviceId, settings]), cryptoCurrencies)
|
||||
: null
|
||||
|
||||
return {
|
||||
machineId: deviceId,
|
||||
|
|
@ -85,27 +106,27 @@ function mapMachine (info, settings, machineRow) {
|
|||
},
|
||||
status,
|
||||
lastOnline,
|
||||
cashIn: true,
|
||||
cashOut: machineConfig.cashOutEnabled,
|
||||
cashIn: cashInEnabled,
|
||||
cashOut: cashOutEnabled,
|
||||
manufacturer: 'lamassu',
|
||||
cashInTxLimit: cashLimit,
|
||||
cashOutTxLimit: cashLimit,
|
||||
cashInDailyLimit: cashLimit,
|
||||
cashOutDailyLimit: cashLimit,
|
||||
fiatCurrency: machineConfig.fiatCurrency,
|
||||
fiatCurrency: fiat,
|
||||
identification,
|
||||
coins
|
||||
}
|
||||
}
|
||||
|
||||
function getMachines (info, settings) {
|
||||
function getMachines (rates, settings) {
|
||||
const sql = `select device_id, last_online, now() - last_online < $1 as stale from devices
|
||||
where display=TRUE and
|
||||
paired=TRUE
|
||||
order by created`
|
||||
|
||||
return db.any(sql, [STALE_INTERVAL])
|
||||
.then(_.map(_.partial(mapMachine, [info, settings])))
|
||||
.then(_.map(_.partial(mapMachine, [rates, settings])))
|
||||
}
|
||||
|
||||
function sendRadar (data) {
|
||||
|
|
@ -129,9 +150,9 @@ function sendRadar (data) {
|
|||
.then(r => console.log(r.status))
|
||||
}
|
||||
|
||||
function mapRecord (info, settings) {
|
||||
function mapRecord (rates, settings) {
|
||||
const timestamp = new Date().toISOString()
|
||||
return Promise.all([getMachines(info, settings), fs.readFile(options.mnemonicPath, 'utf8')])
|
||||
return Promise.all([getMachines(rates, settings), fs.readFile(options.mnemonicPath, 'utf8')])
|
||||
.then(([machines, mnemonic]) => {
|
||||
return {
|
||||
operatorId: computeOperatorId(mnemonicHelpers.toEntropyBuffer(mnemonic)),
|
||||
|
|
@ -146,12 +167,12 @@ function mapRecord (info, settings) {
|
|||
})
|
||||
}
|
||||
|
||||
function update (info, settings) {
|
||||
const config = configManager.unscoped(info.config)
|
||||
function update (rates, settings) {
|
||||
const coinAtmRadar = configManager.getCoinAtmRadar(settings.config)
|
||||
|
||||
if (!config.coinAtmRadarActive) return Promise.resolve()
|
||||
if (!coinAtmRadar.active) return Promise.resolve()
|
||||
|
||||
return mapRecord(info, settings)
|
||||
return mapRecord(rates, settings)
|
||||
.then(sendRadar)
|
||||
.catch(err => logger.error(`Failure to update CoinATMRadar`, err))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,178 +0,0 @@
|
|||
const axios = require('axios')
|
||||
const _ = require('lodash/fp')
|
||||
const hkdf = require('futoin-hkdf')
|
||||
|
||||
const pify = require('pify')
|
||||
const fs = pify(require('fs'))
|
||||
|
||||
const db = require('../db')
|
||||
const mnemonicHelpers = require('../mnemonic-helpers')
|
||||
const configManager = require('../config-manager')
|
||||
const options = require('../options')
|
||||
const logger = require('../logger')
|
||||
const plugins = require('../plugins')
|
||||
|
||||
const TIMEOUT = 10000
|
||||
const MAX_CONTENT_LENGTH = 2000
|
||||
|
||||
// How long a machine can be down before it's considered offline
|
||||
const STALE_INTERVAL = '2 minutes'
|
||||
|
||||
module.exports = { update, mapRecord }
|
||||
|
||||
function mapCoin (info, deviceId, settings, cryptoCode) {
|
||||
const config = info.config
|
||||
const rates = plugins(settings, deviceId).buildRates(info.rates)[cryptoCode] || { cashIn: null, cashOut: null }
|
||||
const cryptoConfig = configManager.scoped(cryptoCode, deviceId, config)
|
||||
const unscoped = configManager.unscoped(config)
|
||||
const showCommissions = unscoped.coinAtmRadar.sendCommissions
|
||||
|
||||
const cashInFee = showCommissions ? cryptoConfig.cashInCommission / 100 : null
|
||||
const cashOutFee = showCommissions ? cryptoConfig.cashOutCommission / 100 : null
|
||||
const cashInRate = showCommissions ? _.invoke('cashIn.toNumber', rates) : null
|
||||
const cashOutRate = showCommissions ? _.invoke('cashOut.toNumber', rates) : null
|
||||
|
||||
return {
|
||||
cryptoCode,
|
||||
cashInFee,
|
||||
cashOutFee,
|
||||
cashInRate,
|
||||
cashOutRate
|
||||
}
|
||||
}
|
||||
|
||||
function mapIdentification (info, deviceId) {
|
||||
const machineConfig = configManager.machineScoped(deviceId, info.config)
|
||||
|
||||
return {
|
||||
isPhone: machineConfig.smsVerificationActive,
|
||||
isPalmVein: false,
|
||||
isPhoto: false,
|
||||
isIdDocScan: machineConfig.idCardDataVerificationActive,
|
||||
isFingerprint: false
|
||||
}
|
||||
}
|
||||
|
||||
function mapMachine (info, settings, machineRow) {
|
||||
const deviceId = machineRow.device_id
|
||||
const config = info.config
|
||||
const unscoped = configManager.unscoped(config)
|
||||
const machineConfig = configManager.machineScoped(deviceId, config)
|
||||
|
||||
const lastOnline = machineRow.last_online.toISOString()
|
||||
const status = machineRow.stale ? 'online' : 'offline'
|
||||
const showSupportedCryptocurrencies =
|
||||
unscoped.coinAtmRadar.sendSupportedCryptocurrencies
|
||||
const showSupportedFiat =
|
||||
unscoped.coinAtmRadar.sendSupportedFiat
|
||||
const showSupportedBuySellDirection =
|
||||
unscoped.coinAtmRadar.sendSupportedBuySellDirection
|
||||
const showLimitsAndVerification =
|
||||
unscoped.coinAtmRadar.sendLimitsAndVerification
|
||||
|
||||
const cashLimit = showLimitsAndVerification ? (
|
||||
machineConfig.hardLimitVerificationActive
|
||||
? machineConfig.hardLimitVerificationThreshold
|
||||
: Infinity ) : null
|
||||
|
||||
const cryptoCurrencies = machineConfig.cryptoCurrencies
|
||||
const cashInEnabled = showSupportedBuySellDirection ? true : null
|
||||
const cashOutEnabled = showSupportedBuySellDirection
|
||||
? machineConfig.cashOutEnabled
|
||||
: null
|
||||
const fiat = showSupportedFiat ? machineConfig.fiatCurrency : null
|
||||
const identification = mapIdentification(info, deviceId)
|
||||
const coins = showSupportedCryptocurrencies ?
|
||||
_.map(_.partial(mapCoin, [info, deviceId, settings]), cryptoCurrencies)
|
||||
: null
|
||||
|
||||
return {
|
||||
machineId: deviceId,
|
||||
address: {
|
||||
streetAddress: null,
|
||||
city: null,
|
||||
region: null,
|
||||
postalCode: null,
|
||||
country: null
|
||||
},
|
||||
location: {
|
||||
name: null,
|
||||
url: null,
|
||||
phone: null
|
||||
},
|
||||
status,
|
||||
lastOnline,
|
||||
cashIn: cashInEnabled,
|
||||
cashOut: cashOutEnabled,
|
||||
manufacturer: 'lamassu',
|
||||
cashInTxLimit: cashLimit,
|
||||
cashOutTxLimit: cashLimit,
|
||||
cashInDailyLimit: cashLimit,
|
||||
cashOutDailyLimit: cashLimit,
|
||||
fiatCurrency: fiat,
|
||||
identification,
|
||||
coins
|
||||
}
|
||||
}
|
||||
|
||||
function getMachines (info, settings) {
|
||||
const sql = `select device_id, last_online, now() - last_online < $1 as stale from devices
|
||||
where display=TRUE and
|
||||
paired=TRUE
|
||||
order by created`
|
||||
|
||||
return db.any(sql, [STALE_INTERVAL])
|
||||
.then(_.map(_.partial(mapMachine, [info, settings])))
|
||||
}
|
||||
|
||||
function sendRadar (data) {
|
||||
const url = _.get(['coinAtmRadar', 'url'], options)
|
||||
|
||||
if (_.isEmpty(url)) {
|
||||
return Promise.reject(new Error('Missing coinAtmRadar url!'))
|
||||
}
|
||||
|
||||
const config = {
|
||||
url,
|
||||
method: 'post',
|
||||
data,
|
||||
timeout: TIMEOUT,
|
||||
maxContentLength: MAX_CONTENT_LENGTH
|
||||
}
|
||||
|
||||
console.log('%j', data)
|
||||
|
||||
return axios(config)
|
||||
.then(r => console.log(r.status))
|
||||
}
|
||||
|
||||
function mapRecord (info, settings) {
|
||||
const timestamp = new Date().toISOString()
|
||||
return Promise.all([getMachines(info, settings), fs.readFile(options.mnemonicPath, 'utf8')])
|
||||
.then(([machines, mnemonic]) => {
|
||||
return {
|
||||
operatorId: computeOperatorId(mnemonicHelpers.toEntropyBuffer(mnemonic)),
|
||||
operator: {
|
||||
name: null,
|
||||
phone: null,
|
||||
email: null
|
||||
},
|
||||
timestamp,
|
||||
machines
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function update (info, settings) {
|
||||
const config = configManager.unscoped(info.config)
|
||||
|
||||
if (!config.coinAtmRadar.active) return Promise.resolve()
|
||||
|
||||
return mapRecord(info, settings)
|
||||
.then(sendRadar)
|
||||
.catch(err => logger.error(`Failure to update CoinATMRadar`, err))
|
||||
}
|
||||
|
||||
function computeOperatorId (masterSeed) {
|
||||
return hkdf(masterSeed, 16, { salt: 'lamassu-server-salt', info: 'operator-id' }).toString('hex')
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue