From 4d520f2c24bd5137d4e2a335599d66c3bd019a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Wed, 4 May 2022 13:50:11 +0100 Subject: [PATCH] fix: mempool flag and error handling --- lib/cash-out/cash-out-tx.js | 10 +++++----- .../wallet-scoring/ciphertrace/ciphertrace.js | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/cash-out/cash-out-tx.js b/lib/cash-out/cash-out-tx.js index 3dd3632f..4abf18ea 100644 --- a/lib/cash-out/cash-out-tx.js +++ b/lib/cash-out/cash-out-tx.js @@ -140,23 +140,23 @@ function getWalletScore (tx, pi) { : _.assign(tx, { walletScore: highestScore.score, error: 'Address score is above defined threshold', - errorCode: 'operatorCancel', + errorCode: 'scoreThresholdReached', dispense: true }) }) .catch(error => _.assign(tx, { walletScore: 10, - error: `Failure getting address score: ${error?.message}`, - errorCode: 'operatorCancel', + error: `Failure getting address score: ${error.message}`, + errorCode: 'ciphertraceError', dispense: true })) } - if (_.includes(tx.status, statuses) && !_.isNil(tx.walletScore)) { + if (_.includes(tx.status, statuses) && !_.isNil(tx.walletScore) && _.get('errorCode', tx) !== 'ciphertraceError') { return pi.isValidWalletScore(tx.walletScore) .then(isValid => isValid ? tx : _.assign(tx, { error: 'Address score is above defined threshold', - errorCode: 'operatorCancel', + errorCode: 'scoreThresholdReached', dispense: true })) } diff --git a/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js b/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js index a35ca213..d38598ab 100644 --- a/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js +++ b/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js @@ -6,7 +6,7 @@ const logger = require('../../../logger') const NAME = 'CipherTrace' const SUPPORTED_COINS = ['BTC', 'ETH', 'BCH', 'LTC', 'BNB', 'RSK'] -function getClient(account) { +function getClient (account) { if (_.isNil(account) || !account.enabled) return null const [ctv1, username, secretKey] = account.authorizationValue.split(':') @@ -16,12 +16,12 @@ function getClient(account) { const apiVersion = ctv1.slice(-2) const authHeader = { - "Authorization": account.authorizationValue + 'Authorization': account.authorizationValue } return { apiVersion, authHeader } } -function rateWallet(account, cryptoCode, address) { +function rateWallet (account, cryptoCode, address) { const client = getClient(account) if (!_.includes(_.toUpper(cryptoCode), SUPPORTED_COINS) || _.isNil(client)) return Promise.resolve(null) @@ -34,7 +34,7 @@ function rateWallet(account, cryptoCode, address) { .then(res => ({ address, score: res.data.risk, isValid: res.data.risk < threshold })) } -function isValidWalletScore(account, score) { +function isValidWalletScore (account, score) { const client = getClient(account) if (_.isNil(client)) return Promise.resolve(true) @@ -42,13 +42,13 @@ function isValidWalletScore(account, score) { return _.isNil(account) ? Promise.resolve(true) : Promise.resolve(score < threshold) } -function getTransactionHash(account, cryptoCode, receivingAddress) { +function getTransactionHash (account, cryptoCode, receivingAddress) { const client = getClient(account) if (!_.includes(_.toUpper(cryptoCode), SUPPORTED_COINS) || _.isNil(client)) return Promise.resolve(null) const { apiVersion, authHeader } = client - return axios.get(`https://rest.ciphertrace.com/api/${apiVersion}/${_.toLower(cryptoCode) !== 'btc' ? `${_.toLower(cryptoCode)}_` : ``}address/search?features=tx&address=${receivingAddress}`, { + return axios.get(`https://rest.ciphertrace.com/api/${apiVersion}/${_.toLower(cryptoCode) !== 'btc' ? `${_.toLower(cryptoCode)}_` : ``}address/search?features=tx&address=${receivingAddress}&mempool=true`, { headers: authHeader }) .then(res => { @@ -60,7 +60,7 @@ function getTransactionHash(account, cryptoCode, receivingAddress) { }) } -function getInputAddresses(account, cryptoCode, txHashes) { +function getInputAddresses (account, cryptoCode, txHashes) { const client = getClient(account) if (!_.includes(_.toUpper(cryptoCode), SUPPORTED_COINS) || _.isNil(client)) return Promise.resolve(null)