fix zero-conf stuff

This commit is contained in:
Josh Harvey 2017-08-09 19:09:24 +03:00
parent ee3fc3a8f0
commit 0bf4a14383
3 changed files with 29 additions and 16 deletions

View file

@ -99,8 +99,11 @@ function authorizeZeroConf (settings, tx, machineId) {
const plugin = cryptoConfig.zeroConf
const zeroConfLimit = machineConfig.zeroConfLimit
if (tx.fiat.gt(zeroConfLimit)) return Promise.resolve(false)
if (tx.cryptoCode !== 'BTC' || plugin === 'all-zero-conf') return Promise.resolve(true)
if (plugin === 'no-zero-conf' || tx.fiat.gt(zeroConfLimit)) {
return Promise.resolve(false)
}
if (plugin === 'all-zero-conf') return Promise.resolve(true)
const zeroConf = ph.load(ph.ZERO_CONF, plugin)
const account = settings.accounts[plugin]
@ -119,20 +122,24 @@ function getPublishAge (txId) {
}
function getStatus (settings, tx, machineId) {
const promises = [
getWalletStatus(settings, tx),
authorizeZeroConf(settings, tx, machineId),
getPublishAge(tx.id)
]
return Promise.all(promises)
.then(([statusRec, isAuthorized, publishAge]) => {
return getWalletStatus(settings, tx)
.then((statusRec) => {
if (statusRec.status === 'authorized') {
const unauthorizedStatus = publishAge < ZERO_CONF_EXPIRATION
? 'published'
: 'rejected'
const promises = [
getPublishAge(tx.id),
authorizeZeroConf(settings, tx, machineId)
]
return {status: (isAuthorized ? 'authorized' : unauthorizedStatus)}
return Promise.all(promises)
.then(([publishAge, isAuthorized]) => {
const unauthorizedStatus = publishAge < ZERO_CONF_EXPIRATION
? 'published'
: 'rejected'
const status = isAuthorized ? 'authorized' : unauthorizedStatus
return {status}
})
}
return statusRec