refactor: reject empty/nil results

This commit is contained in:
André Sá 2022-08-23 16:08:23 +01:00
parent bcbde40a52
commit 9784f21d64

View file

@ -114,6 +114,7 @@ function processTxStatus (tx, settings) {
}
function getWalletScore (tx, pi) {
const rejectEmpty = message => x => _.isNil(x) || _.isEmpty(x) ? Promise.reject({ message }) : x
const statuses = ['published', 'authorized', 'confirmed']
if (_.includes(tx.status, statuses) && _.isNil(tx.walletScore))
@ -121,12 +122,11 @@ function getWalletScore (tx, pi) {
// Transaction shows up on the blockchain, we can request the sender address
return pi.getTransactionHash(tx)
.then(txHashes => _.isNil(txHashes) || _.isEmpty(txHashes) ?
Promise.reject({ message: "No transaction hashes" }) :
txHashes
)
.then(rejectEmpty("No transaction hashes"))
.then(txHashes => pi.getInputAddresses(tx, txHashes))
.then(rejectEmpty("No input addresses"))
.then(addresses => Promise.all(_.map(it => pi.rateWallet(tx.cryptoCode, it), addresses)))
.then(rejectEmpty("No score ratings"))
.then(_.maxBy(_.get(['score'])))
.then(highestScore =>
// Conservatively assign the highest risk of all input addresses to the risk of this transaction