This commit is contained in:
Josh Harvey 2016-11-27 20:14:36 +02:00
parent 00d986376e
commit 7bb071fc95
3 changed files with 29 additions and 28 deletions

View file

@ -45,8 +45,6 @@ const coins = {
let alertFingerprint = null
let lastAlertTime = null
exports.logEvent = db.recordDeviceEvent
function buildRates (deviceId, tickers) {
const settings = settingsLoader.settings
const config = configManager.machineScoped(deviceId, settings.config)
@ -104,7 +102,7 @@ function buildCartridges (cartridges, virtualCartridges, rec) {
}
}
exports.pollQueries = function pollQueries (deviceTime, deviceId, deviceRec) {
function pollQueries (deviceTime, deviceId, deviceRec) {
const settings = settingsLoader.settings
const config = configManager.machineScoped(deviceId, settings.config)
const fiatCode = config.currencies.fiatCurrency
@ -151,8 +149,7 @@ function executeTx (deviceId, tx) {
})
}
// TODO: Run these in parallel and return success
exports.trade = function trade (deviceId, rawTrade) {
function trade (deviceId, rawTrade) {
// TODO: move this to DB, too
// add bill to trader queue (if trader is enabled)
const cryptoCode = rawTrade.cryptoCode
@ -176,7 +173,7 @@ exports.trade = function trade (deviceId, rawTrade) {
})
}
exports.stateChange = function stateChange (deviceId, deviceTime, rec, cb) {
function stateChange (deviceId, deviceTime, rec, cb) {
const event = {
id: rec.uuid,
deviceId: deviceId,
@ -198,11 +195,11 @@ function recordPing (deviceId, deviceTime, rec) {
return db.machineEvent(event)
}
exports.sendCoins = function sendCoins (deviceId, rawTx) {
function sendCoins (deviceId, rawTx) {
return executeTx(deviceId, rawTx)
}
exports.cashOut = function cashOut (deviceId, tx) {
function cashOut (deviceId, tx) {
const cryptoCode = tx.cryptoCode
const serialPromise = wallet.supportsHD
@ -227,7 +224,7 @@ exports.cashOut = function cashOut (deviceId, tx) {
})
}
exports.dispenseAck = function (deviceId, tx) {
function dispenseAck (deviceId, tx) {
const settings = settingsLoader.settings
const config = configManager.machineScoped(deviceId, settings.config)
const cartridges = [ config.currencies.topCashOutDenomination,
@ -307,7 +304,7 @@ function monitorUnnotified () {
/*
* Polling livecycle
*/
exports.startPolling = function startPolling () {
function startPolling () {
executeTrades()
setInterval(executeTrades, TRADE_INTERVAL)
@ -413,7 +410,6 @@ function executeTradesForMarket (settings, fiatCode, cryptoCode) {
function sendMessage (rec) {
return Promise.all([sms.sendMessage(rec), email.sendMessage(rec)])
}
exports.sendMessage = sendMessage
function sendNoAlerts () {
const subject = '[Lamassu] All clear'
@ -500,13 +496,13 @@ function checkBalances () {
})
}
exports.startCheckingNotification = function startCheckingNotification (config) {
function startCheckingNotification (config) {
notifier.init(checkBalances)
checkNotification()
setInterval(checkNotification, CHECK_NOTIFICATION_INTERVAL)
}
exports.getPhoneCode = function getPhoneCode (phone) {
function getPhoneCode (phone) {
return sms.name()
.then(name => {
const code = name === 'MockSMS'
@ -525,10 +521,7 @@ exports.getPhoneCode = function getPhoneCode (phone) {
})
}
exports.updatePhone = db.addIncomingPhone
exports.registerRedeem = db.updateRedeem
exports.fetchPhoneTx = function fetchPhoneTx (phone) {
function fetchPhoneTx (phone) {
return db.fetchPhoneTxs(phone, TRANSACTION_EXPIRATION)
.then(txs => {
const confirmedTxs = txs.filter(tx => R.contains(tx.status, ['instant', 'confirmed']))
@ -545,12 +538,6 @@ exports.fetchPhoneTx = function fetchPhoneTx (phone) {
})
}
exports.requestDispense = function requestDispense (tx) {
return db.addDispenseRequest(tx)
}
exports.fetchTx = db.fetchTx
function sweepHD (row) {
const cryptoCode = row.crypto_code
@ -575,3 +562,16 @@ function sweepOldHD () {
.then(rows => Promise.all(rows.map(sweepHD)))
.catch(err => logger.error(err))
}
module.exports = {
pollQueries,
trade,
stateChange,
sendCoins,
cashOut,
dispenseAck,
startPolling,
startCheckingNotification,
getPhoneCode,
fetchPhoneTx
}