refactor: fetch rbf status of unconfirmed txs
This commit is contained in:
parent
0e39aa78c9
commit
e6b1446616
1 changed files with 6 additions and 9 deletions
|
|
@ -13,7 +13,6 @@ function highConfidence (confidence, txref, txRBF) {
|
|||
}
|
||||
|
||||
function authorize (account, toAddress, cryptoAtoms, cryptoCode, isBitcoindAvailable) {
|
||||
let promise = []
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
if (cryptoCode !== 'BTC') throw new Error('Unsupported crypto: ' + cryptoCode)
|
||||
|
|
@ -31,21 +30,19 @@ function authorize (account, toAddress, cryptoAtoms, cryptoCode, isBitcoindAvail
|
|||
.then(r => {
|
||||
const data = r.data
|
||||
if (isBitcoindAvailable && isRBFEnabled && data.unconfirmed_txrefs) {
|
||||
_.map(unconfirmedTxref => {
|
||||
promise.push(new Promise((resolve, reject) => { resolve(fetchRBF(unconfirmedTxref.tx_hash)) }))
|
||||
}, data.unconfirmed_txrefs)
|
||||
return Promise.all(promise)
|
||||
const promises = _.map(unconfirmedTxref => fetchRBF(unconfirmedTxref.tx_hash), data.unconfirmed_txrefs)
|
||||
return Promise.all(promises)
|
||||
.then(values => {
|
||||
const unconfirmedTxsRBF = _.fromPairs(values)
|
||||
const sumTxRefs = txrefs => _.sumBy(txref => highConfidence(confidence, txref, unconfirmedTxsRBF[txref.tx_hash]), txrefs)
|
||||
const authorizedValue = sumTxRefs(data.txrefs) + sumTxRefs(data.unconfirmed_txrefs)
|
||||
return cryptoAtoms.lte(authorizedValue)
|
||||
})
|
||||
} else {
|
||||
const sumTxRefs = txrefs => _.sumBy(txref => highConfidence(confidence, txref), txrefs)
|
||||
const authorizedValue = sumTxRefs(data.txrefs) + sumTxRefs(data.unconfirmed_txrefs)
|
||||
return cryptoAtoms.lte(authorizedValue)
|
||||
}
|
||||
|
||||
const sumTxRefs = txrefs => _.sumBy(txref => highConfidence(confidence, txref), txrefs)
|
||||
const authorizedValue = sumTxRefs(data.txrefs) + sumTxRefs(data.unconfirmed_txrefs)
|
||||
return cryptoAtoms.lte(authorizedValue)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue