format for latest standard

This commit is contained in:
Josh Harvey 2018-03-10 18:59:40 +00:00
parent 4108efd9c7
commit c2af183911
77 changed files with 1697 additions and 1693 deletions

View file

@ -43,11 +43,11 @@ function selfPost (tx, pi) {
function post (tx, pi, fromClient = true) {
return db.tx(cashOutAtomic.atomic(tx, pi, fromClient))
.then(txVector => {
const [, newTx] = txVector
return postProcess(txVector, pi)
.then(changes => cashOutLow.update(db, newTx, changes))
})
.then(txVector => {
const [, newTx] = txVector
return postProcess(txVector, pi)
.then(changes => cashOutLow.update(db, newTx, changes))
})
}
function postProcess (txVector, pi) {
@ -55,32 +55,32 @@ function postProcess (txVector, pi) {
if ((newTx.dispense && !oldTx.dispense) || (newTx.redeem && !oldTx.redeem)) {
return pi.buildAvailableCassettes(newTx.id)
.then(cassettes => {
const bills = billMath.makeChange(cassettes.cassettes, newTx.fiat)
.then(cassettes => {
const bills = billMath.makeChange(cassettes.cassettes, newTx.fiat)
if (!bills) throw httpError('Out of bills', INSUFFICIENT_FUNDS_CODE)
return bills
})
.then(bills => {
const provisioned1 = bills[0].provisioned
const provisioned2 = bills[1].provisioned
const denomination1 = bills[0].denomination
const denomination2 = bills[1].denomination
if (!bills) throw httpError('Out of bills', INSUFFICIENT_FUNDS_CODE)
return bills
})
.then(bills => {
const provisioned1 = bills[0].provisioned
const provisioned2 = bills[1].provisioned
const denomination1 = bills[0].denomination
const denomination2 = bills[1].denomination
const rec = {
provisioned_1: provisioned1,
provisioned_2: provisioned2,
denomination_1: denomination1,
denomination_2: denomination2
}
const rec = {
provisioned_1: provisioned1,
provisioned_2: provisioned2,
denomination_1: denomination1,
denomination_2: denomination2
}
return cashOutActions.logAction(db, 'provisionNotes', rec, newTx)
.then(_.constant({bills}))
})
.catch(err => {
return cashOutActions.logError(db, 'provisionNotesError', err, newTx)
.then(() => { throw err })
})
return cashOutActions.logAction(db, 'provisionNotes', rec, newTx)
.then(_.constant({bills}))
})
.catch(err => {
return cashOutActions.logError(db, 'provisionNotesError', err, newTx)
.then(() => { throw err })
})
}
return Promise.resolve({})
@ -95,31 +95,31 @@ function fetchOpenTxs (statuses, age) {
const statusClause = _.map(pgp.as.text, statuses).join(',')
return db.any(sql, [age, statusClause])
.then(rows => rows.map(toObj))
.then(rows => rows.map(toObj))
}
function processTxStatus (tx, settings) {
const pi = plugins(settings, tx.deviceId)
return pi.getStatus(tx)
.then(res => _.assign(tx, {status: res.status}))
.then(_tx => selfPost(_tx, pi))
.then(res => _.assign(tx, {status: res.status}))
.then(_tx => selfPost(_tx, pi))
}
function monitorLiveIncoming (settings) {
const statuses = ['notSeen', 'published', 'insufficientFunds']
return fetchOpenTxs(statuses, STALE_LIVE_INCOMING_TX_AGE)
.then(txs => pEachSeries(txs, tx => processTxStatus(tx, settings)))
.catch(logger.error)
.then(txs => pEachSeries(txs, tx => processTxStatus(tx, settings)))
.catch(logger.error)
}
function monitorStaleIncoming (settings) {
const statuses = ['notSeen', 'published', 'authorized', 'instant', 'rejected', 'insufficientFunds']
return fetchOpenTxs(statuses, STALE_INCOMING_TX_AGE)
.then(txs => pEachSeries(txs, tx => processTxStatus(tx, settings)))
.catch(logger.error)
.then(txs => pEachSeries(txs, tx => processTxStatus(tx, settings)))
.catch(logger.error)
}
function monitorUnnotified (settings) {
@ -133,9 +133,9 @@ function monitorUnnotified (settings) {
const notify = tx => plugins(settings, tx.deviceId).notifyConfirmation(tx)
return db.any(sql, [MAX_NOTIFY_AGE, false, false, true, MIN_NOTIFY_AGE])
.then(rows => _.map(toObj, rows))
.then(txs => Promise.all(txs.map(notify)))
.catch(logger.error)
.then(rows => _.map(toObj, rows))
.then(txs => Promise.all(txs.map(notify)))
.catch(logger.error)
}
function cancel (txId) {
@ -146,13 +146,13 @@ function cancel (txId) {
}
return Promise.resolve()
.then(() => {
return pgp.helpers.update(updateRec, null, 'cash_out_txs') +
.then(() => {
return pgp.helpers.update(updateRec, null, 'cash_out_txs') +
pgp.as.format(' where id=$1', [txId])
})
.then(sql => db.result(sql, false))
.then(res => {
if (res.rowCount !== 1) throw new Error('No such tx-id')
})
.then(() => cashOutActions.logActionById(db, 'operatorCompleted', {}, txId))
})
.then(sql => db.result(sql, false))
.then(res => {
if (res.rowCount !== 1) throw new Error('No such tx-id')
})
.then(() => cashOutActions.logActionById(db, 'operatorCompleted', {}, txId))
}