Take machineid into account for coinatmradar rates (#301)
* Take machineid into account for coinatmradar rates * Remove test leftovers
This commit is contained in:
parent
98cc3b18b7
commit
1a53ce5fa1
4 changed files with 21 additions and 14 deletions
|
|
@ -6,9 +6,9 @@ require('../lib/settings-loader').loadLatest()
|
||||||
const pi = plugins(settings)
|
const pi = plugins(settings)
|
||||||
const config = settings.config
|
const config = settings.config
|
||||||
|
|
||||||
return pi.getRates()
|
return pi.getRawRates()
|
||||||
.then(rates => {
|
.then(rates => {
|
||||||
return car.update({rates, config})
|
return car.update({rates, config}, settings)
|
||||||
.then(require('../lib/pp')('DEBUG100'))
|
.then(require('../lib/pp')('DEBUG100'))
|
||||||
.catch(console.log)
|
.catch(console.log)
|
||||||
.then(() => process.exit())
|
.then(() => process.exit())
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ const mnemonicHelpers = require('../mnemonic-helpers')
|
||||||
const configManager = require('../config-manager')
|
const configManager = require('../config-manager')
|
||||||
const options = require('../options')
|
const options = require('../options')
|
||||||
const logger = require('../logger')
|
const logger = require('../logger')
|
||||||
|
const plugins = require('../plugins')
|
||||||
|
|
||||||
const TIMEOUT = 10000
|
const TIMEOUT = 10000
|
||||||
const MAX_CONTENT_LENGTH = 2000
|
const MAX_CONTENT_LENGTH = 2000
|
||||||
|
|
@ -19,9 +20,9 @@ const STALE_INTERVAL = '2 minutes'
|
||||||
|
|
||||||
module.exports = { update, mapRecord }
|
module.exports = { update, mapRecord }
|
||||||
|
|
||||||
function mapCoin (info, deviceId, cryptoCode) {
|
function mapCoin (info, deviceId, settings, cryptoCode) {
|
||||||
const config = info.config
|
const config = info.config
|
||||||
const rates = info.rates[cryptoCode] || { cashIn: null, cashOut: null }
|
const rates = plugins(settings, deviceId).buildRates(info.rates)[cryptoCode] || { cashIn: null, cashOut: null }
|
||||||
const cryptoConfig = configManager.scoped(cryptoCode, deviceId, config)
|
const cryptoConfig = configManager.scoped(cryptoCode, deviceId, config)
|
||||||
const unscoped = configManager.unscoped(config)
|
const unscoped = configManager.unscoped(config)
|
||||||
const showRates = unscoped.coinAtmRadarShowRates
|
const showRates = unscoped.coinAtmRadarShowRates
|
||||||
|
|
@ -52,7 +53,7 @@ function mapIdentification (info, deviceId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapMachine (info, machineRow) {
|
function mapMachine (info, settings, machineRow) {
|
||||||
const deviceId = machineRow.device_id
|
const deviceId = machineRow.device_id
|
||||||
const config = info.config
|
const config = info.config
|
||||||
const machineConfig = configManager.machineScoped(deviceId, config)
|
const machineConfig = configManager.machineScoped(deviceId, config)
|
||||||
|
|
@ -66,7 +67,7 @@ function mapMachine (info, machineRow) {
|
||||||
|
|
||||||
const cryptoCurrencies = machineConfig.cryptoCurrencies
|
const cryptoCurrencies = machineConfig.cryptoCurrencies
|
||||||
const identification = mapIdentification(info, deviceId)
|
const identification = mapIdentification(info, deviceId)
|
||||||
const coins = _.map(_.partial(mapCoin, [info, deviceId]), cryptoCurrencies)
|
const coins = _.map(_.partial(mapCoin, [info, deviceId, settings]), cryptoCurrencies)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
machineId: deviceId,
|
machineId: deviceId,
|
||||||
|
|
@ -97,14 +98,14 @@ function mapMachine (info, machineRow) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMachines (info) {
|
function getMachines (info, settings) {
|
||||||
const sql = `select device_id, last_online, now() - last_online < $1 as stale from devices
|
const sql = `select device_id, last_online, now() - last_online < $1 as stale from devices
|
||||||
where display=TRUE and
|
where display=TRUE and
|
||||||
paired=TRUE
|
paired=TRUE
|
||||||
order by created`
|
order by created`
|
||||||
|
|
||||||
return db.any(sql, [STALE_INTERVAL])
|
return db.any(sql, [STALE_INTERVAL])
|
||||||
.then(_.map(_.partial(mapMachine, [info])))
|
.then(_.map(_.partial(mapMachine, [info, settings])))
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendRadar (data) {
|
function sendRadar (data) {
|
||||||
|
|
@ -128,9 +129,9 @@ function sendRadar (data) {
|
||||||
.then(r => console.log(r.status))
|
.then(r => console.log(r.status))
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapRecord (info) {
|
function mapRecord (info, settings) {
|
||||||
const timestamp = new Date().toISOString()
|
const timestamp = new Date().toISOString()
|
||||||
return Promise.all([getMachines(info), fs.readFile(options.mnemonicPath, 'utf8')])
|
return Promise.all([getMachines(info, settings), fs.readFile(options.mnemonicPath, 'utf8')])
|
||||||
.then(([machines, mnemonic]) => {
|
.then(([machines, mnemonic]) => {
|
||||||
return {
|
return {
|
||||||
operatorId: computeOperatorId(mnemonicHelpers.toEntropyBuffer(mnemonic)),
|
operatorId: computeOperatorId(mnemonicHelpers.toEntropyBuffer(mnemonic)),
|
||||||
|
|
@ -145,12 +146,12 @@ function mapRecord (info) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function update (info) {
|
function update (info, settings) {
|
||||||
const config = configManager.unscoped(info.config)
|
const config = configManager.unscoped(info.config)
|
||||||
|
|
||||||
if (!config.coinAtmRadarActive) return Promise.resolve()
|
if (!config.coinAtmRadarActive) return Promise.resolve()
|
||||||
|
|
||||||
return mapRecord(info)
|
return mapRecord(info, settings)
|
||||||
.then(sendRadar)
|
.then(sendRadar)
|
||||||
.catch(err => logger.error(`Failure to update CoinATMRadar`, err))
|
.catch(err => logger.error(`Failure to update CoinATMRadar`, err))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -755,18 +755,24 @@ function plugins (settings, deviceId) {
|
||||||
return machineLoader.getMachineNames(settings.config)
|
return machineLoader.getMachineNames(settings.config)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRates () {
|
function getRawRates () {
|
||||||
const config = configManager.unscoped(settings.config)
|
const config = configManager.unscoped(settings.config)
|
||||||
const cryptoCodes = _.flatten(configManager.all('cryptoCurrencies', settings.config))
|
const cryptoCodes = _.flatten(configManager.all('cryptoCurrencies', settings.config))
|
||||||
const fiatCode = config.fiatCurrency
|
const fiatCode = config.fiatCurrency
|
||||||
const tickerPromises = cryptoCodes.map(c => ticker.getRates(settings, fiatCode, c))
|
const tickerPromises = cryptoCodes.map(c => ticker.getRates(settings, fiatCode, c))
|
||||||
|
|
||||||
return Promise.all(tickerPromises)
|
return Promise.all(tickerPromises)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRates () {
|
||||||
|
return getRawRates()
|
||||||
.then(buildRates)
|
.then(buildRates)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getRates,
|
getRates,
|
||||||
|
buildRates,
|
||||||
|
getRawRates,
|
||||||
pollQueries,
|
pollQueries,
|
||||||
sendCoins,
|
sendCoins,
|
||||||
newAddress,
|
newAddress,
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ function updateAndLoadSanctions () {
|
||||||
function updateCoinAtmRadar () {
|
function updateCoinAtmRadar () {
|
||||||
const config = settings().config
|
const config = settings().config
|
||||||
|
|
||||||
return pi().getRates()
|
return pi().getRawRates()
|
||||||
.then(rates => coinAtmRadar.update({ rates, config }))
|
.then(rates => coinAtmRadar.update({ rates, config }))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue