WIP
This commit is contained in:
parent
b62cd590ef
commit
5312086622
3 changed files with 127 additions and 131 deletions
|
|
@ -243,9 +243,7 @@ exports.getConfig = function getConfig () {
|
|||
return cachedConfig
|
||||
}
|
||||
|
||||
exports.logEvent = function event (session, rawEvent) {
|
||||
return db.recordDeviceEvent(session, rawEvent)
|
||||
}
|
||||
exports.logEvent = db.recordDeviceEvent
|
||||
|
||||
function buildCartridges (cartridges, virtualCartridges, rec) {
|
||||
return {
|
||||
|
|
@ -264,12 +262,12 @@ function buildCartridges (cartridges, virtualCartridges, rec) {
|
|||
}
|
||||
}
|
||||
|
||||
exports.pollQueries = function pollQueries (session) {
|
||||
exports.pollQueries = function pollQueries (deviceId) {
|
||||
const cartridges = cachedConfig.exchanges.settings.cartridges
|
||||
if (!cartridges) return Promise.resolve({})
|
||||
const virtualCartridges = cachedConfig.exchanges.settings.virtualCartridges
|
||||
|
||||
return db.cartridgeCounts(session)
|
||||
return db.cartridgeCounts(deviceId)
|
||||
.then(result => ({
|
||||
cartridges: buildCartridges(cartridges, virtualCartridges, result)
|
||||
}))
|
||||
|
|
@ -298,8 +296,8 @@ function _sendCoinsCb (toAddress, cryptoAtoms, cryptoCode, cb) {
|
|||
|
||||
// NOTE: This will fail if we have already sent coins because there will be
|
||||
// a db unique db record in the table already.
|
||||
function executeTx (fingerprint, tx) {
|
||||
return db.addOutgoingTx(fingerprint, tx)
|
||||
function executeTx (deviceId, tx) {
|
||||
return db.addOutgoingTx(deviceId, tx)
|
||||
.then(() => _sendCoins(tx.toAddress, tx.cryptoAtoms, tx.cryptoCode))
|
||||
.then(txHash => {
|
||||
const fee = null // Need to fill this out in plugins
|
||||
|
|
@ -316,7 +314,7 @@ function executeTx (fingerprint, tx) {
|
|||
}
|
||||
|
||||
// TODO: Run these in parallel and return success
|
||||
exports.trade = function trade (session, rawTrade) {
|
||||
exports.trade = function trade (deviceId, rawTrade) {
|
||||
// TODO: move this to DB, too
|
||||
// add bill to trader queue (if trader is enabled)
|
||||
const cryptoCode = rawTrade.cryptoCode || 'BTC'
|
||||
|
|
@ -332,41 +330,41 @@ exports.trade = function trade (session, rawTrade) {
|
|||
})
|
||||
}
|
||||
|
||||
return db.recordBill(session, rawTrade)
|
||||
return db.recordBill(deviceId, rawTrade)
|
||||
}
|
||||
|
||||
exports.stateChange = function stateChange (session, rec, cb) {
|
||||
exports.stateChange = function stateChange (deviceId, deviceTime, rec, cb) {
|
||||
const event = {
|
||||
id: rec.uuid,
|
||||
fingerprint: session.fingerprint,
|
||||
fingerprint: deviceId,
|
||||
eventType: 'stateChange',
|
||||
note: JSON.stringify({state: rec.state, isIdle: rec.isIdle, sessionId: session.id}),
|
||||
deviceTime: session.deviceTime
|
||||
note: JSON.stringify({state: rec.state, isIdle: rec.isIdle, txId: rec.txId}),
|
||||
deviceTime: deviceTime
|
||||
}
|
||||
return db.machineEvent(event)
|
||||
}
|
||||
|
||||
exports.recordPing = function recordPing (session, rec, cb) {
|
||||
exports.recordPing = function recordPing (deviceId, deviceTime, rec, cb) {
|
||||
const event = {
|
||||
id: uuid.v4(),
|
||||
fingerprint: session.fingerprint,
|
||||
fingerprint: deviceId,
|
||||
eventType: 'ping',
|
||||
note: JSON.stringify({state: rec.state, isIdle: rec.idle === 'true', sessionId: session.id}),
|
||||
deviceTime: session.deviceTime
|
||||
note: JSON.stringify({state: rec.state, isIdle: rec.idle === 'true', txId: rec.txId}),
|
||||
deviceTime: deviceTime
|
||||
}
|
||||
return db.machineEvent(event)
|
||||
}
|
||||
|
||||
exports.sendCoins = function sendCoins (session, rawTx) {
|
||||
return executeTx(session.fingerprint, rawTx)
|
||||
exports.sendCoins = function sendCoins (rawTx) {
|
||||
return executeTx(rawTx)
|
||||
}
|
||||
|
||||
exports.cashOut = function cashOut (session, tx) {
|
||||
exports.cashOut = function cashOut (tx) {
|
||||
const cryptoCode = tx.cryptoCode || 'BTC'
|
||||
const walletPlugin = walletPlugins[cryptoCode]
|
||||
|
||||
const serialPromise = walletPlugin.supportsHD
|
||||
? db.nextCashOutSerialHD(tx.sessionId, cryptoCode)
|
||||
? db.nextCashOutSerialHD(tx.id, cryptoCode)
|
||||
: Promise.resolve()
|
||||
|
||||
return serialPromise
|
||||
|
|
@ -381,15 +379,13 @@ exports.cashOut = function cashOut (session, tx) {
|
|||
if (err) return reject(err)
|
||||
|
||||
const newTx = R.assoc('toAddress', address, tx)
|
||||
return db.addInitialIncoming(session, newTx, address)
|
||||
return db.addInitialIncoming(newTx, address)
|
||||
.then(() => resolve(address))
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
exports.dispenseAck = function dispenseAck (session, rec) {
|
||||
return db.addDispense(session, rec.tx, rec.cartridges)
|
||||
}
|
||||
exports.dispenseAck = db.addDispense
|
||||
|
||||
exports.fiatBalance = function fiatBalance (cryptoCode) {
|
||||
const deviceRate = exports.getDeviceRate(cryptoCode)
|
||||
|
|
@ -765,13 +761,8 @@ exports.getPhoneCode = function getPhoneCode (phone) {
|
|||
.then(() => code)
|
||||
}
|
||||
|
||||
exports.updatePhone = function updatePhone (session, tx, notified) {
|
||||
return db.addIncomingPhone(session, tx, notified)
|
||||
}
|
||||
|
||||
exports.registerRedeem = function registerRedeem (session) {
|
||||
return db.updateRedeem(session)
|
||||
}
|
||||
exports.updatePhone = db.addIncomingPhone
|
||||
exports.registerRedeem = db.updateRedeem
|
||||
|
||||
exports.fetchPhoneTx = function fetchPhoneTx (phone) {
|
||||
return db.fetchPhoneTxs(phone, TRANSACTION_EXPIRATION)
|
||||
|
|
@ -798,9 +789,9 @@ exports.requestDispense = function requestDispense (tx) {
|
|||
return db.addDispenseRequest(tx)
|
||||
}
|
||||
|
||||
exports.cachedResponse = (session, path, method) => db.cachedResponse(session, path, method)
|
||||
exports.cachedResponse = db.cachedResponse
|
||||
|
||||
exports.cacheResponse = (session, path, method, body) => db.cacheResponse(session, path, method, body)
|
||||
exports.cacheResponse = db.cacheResponse
|
||||
|
||||
function sweepHD (row) {
|
||||
const cryptoCode = row.crypto_code
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue