From 16554951a1c9d107aa1cad4806e9123ae36acecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Fri, 14 Apr 2023 17:03:59 +0100 Subject: [PATCH] fix: cash-out skips wallet rating in most status --- lib/cash-in/cash-in-tx.js | 6 +++--- lib/cash-out/cash-out-tx.js | 15 ++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/cash-in/cash-in-tx.js b/lib/cash-in/cash-in-tx.js index 6e3c0ae2..562fbffb 100644 --- a/lib/cash-in/cash-in-tx.js +++ b/lib/cash-in/cash-in-tx.js @@ -25,8 +25,8 @@ case else 'Pending' end` -module.exports = {post, monitorPending, cancel, PENDING_INTERVAL, TRANSACTION_STATES} - +module.exports = { post, monitorPending, cancel, PENDING_INTERVAL, TRANSACTION_STATES } +// TODO: cash-in wallet score is not recorded in db function post (machineTx, pi) { logger.silly('Updating cashin tx:', machineTx) return cashInAtomic.atomic(machineTx, pi) @@ -51,12 +51,12 @@ function post (machineTx, pi) { } return postProcess(r, pi, blacklisted, addressReuse, walletScore) }) + .then(changes => _.set('walletScore', _.isNil(walletScore) ? null : walletScore.score, changes)) .then(changes => cashInLow.update(db, updatedTx, changes)) .then(tx => _.set('bills', machineTx.bills, tx)) .then(tx => _.set('blacklisted', blacklisted, tx)) .then(tx => _.set('addressReuse', addressReuse, tx)) .then(tx => _.set('validWalletScore', _.isNil(walletScore) ? true : walletScore.isValid, tx)) - .then(tx => _.set('walletScore', _.isNil(walletScore) ? null : walletScore.score, tx)) }) } diff --git a/lib/cash-out/cash-out-tx.js b/lib/cash-out/cash-out-tx.js index b36135db..dd56aed4 100644 --- a/lib/cash-out/cash-out-tx.js +++ b/lib/cash-out/cash-out-tx.js @@ -115,22 +115,23 @@ 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'] + const rejectEmpty = message => x => _.isNil(x) || _.isEmpty(x) ? Promise.reject(new Error(message)) : x + const statuses = ['published', 'authorized', 'confirmed', 'insufficientFunds'] - if (_.includes(tx.status, statuses) && _.isNil(tx.walletScore)) + if (!_.includes(tx.status, statuses) || !_.isNil(tx.walletScore)) { return tx + } - // Transaction shows up on the blockchain, we can request the sender address + // Transaction shows up on the blockchain, we can request the sender address return pi.isWalletScoringEnabled(tx) .then(isEnabled => { if (!isEnabled) return tx return pi.getTransactionHash(tx) - .then(rejectEmpty("No transaction hashes")) + .then(rejectEmpty('No transaction hashes')) .then(txHashes => pi.getInputAddresses(tx, txHashes)) - .then(rejectEmpty("No input addresses")) + .then(rejectEmpty('No input addresses')) .then(addresses => Promise.all(_.map(it => pi.rateWallet(tx.cryptoCode, it), addresses))) - .then(rejectEmpty("No score ratings")) + .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