From 9784f21d64d7b586fdcb9785c1fcfcc60365bbc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20S=C3=A1?= Date: Tue, 23 Aug 2022 16:08:23 +0100 Subject: [PATCH] refactor: reject empty/nil results --- lib/cash-out/cash-out-tx.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/cash-out/cash-out-tx.js b/lib/cash-out/cash-out-tx.js index bcf3e822..a89646a0 100644 --- a/lib/cash-out/cash-out-tx.js +++ b/lib/cash-out/cash-out-tx.js @@ -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