WIPP
This commit is contained in:
parent
c3261bc61a
commit
e24da06a1b
3 changed files with 64 additions and 38 deletions
35
lib/route-helpers.js
Normal file
35
lib/route-helpers.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
const R = require('ramda')
|
||||
|
||||
const dbm = require('./postgresql_interface')
|
||||
const T = require('./time')
|
||||
const TRANSACTION_EXPIRATION = 2 * T.days
|
||||
|
||||
function stateChange (deviceId, deviceTime, rec) {
|
||||
const event = {
|
||||
id: rec.uuid,
|
||||
deviceId: deviceId,
|
||||
eventType: 'stateChange',
|
||||
note: JSON.stringify({state: rec.state, isIdle: rec.isIdle, txId: rec.txId}),
|
||||
deviceTime: deviceTime
|
||||
}
|
||||
return dbm.machineEvent(event)
|
||||
}
|
||||
|
||||
function fetchPhoneTx (phone) {
|
||||
return dbm.fetchPhoneTxs(phone, TRANSACTION_EXPIRATION)
|
||||
.then(txs => {
|
||||
const confirmedTxs = txs.filter(tx => R.contains(tx.status, ['instant', 'confirmed']))
|
||||
if (confirmedTxs.length > 0) {
|
||||
const maxTx = R.reduce((acc, val) => {
|
||||
return !acc || val.cryptoAtoms.gt(acc.cryptoAtoms) ? val : acc
|
||||
}, null, confirmedTxs)
|
||||
|
||||
return {tx: maxTx}
|
||||
}
|
||||
|
||||
if (txs.length > 0) return {pending: true}
|
||||
return {}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {stateChange, fetchPhoneTx}
|
||||
Loading…
Add table
Add a link
Reference in a new issue