refactor: reject empty/nil results
This commit is contained in:
parent
bcbde40a52
commit
9784f21d64
1 changed files with 4 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue