Merge pull request #1206 from josepfo/fix/ciphertrace-blocking-cash-out-txs

fix: mempool flag and error handling
This commit is contained in:
Rafael Taranto 2022-05-04 19:17:12 +01:00 committed by GitHub
commit 7e2155b3d4
5 changed files with 15 additions and 16 deletions

View file

@ -140,23 +140,23 @@ function getWalletScore (tx, pi) {
: _.assign(tx, { : _.assign(tx, {
walletScore: highestScore.score, walletScore: highestScore.score,
error: 'Address score is above defined threshold', error: 'Address score is above defined threshold',
errorCode: 'operatorCancel', errorCode: 'scoreThresholdReached',
dispense: true dispense: true
}) })
}) })
.catch(error => _.assign(tx, { .catch(error => _.assign(tx, {
walletScore: 10, walletScore: 10,
error: `Failure getting address score: ${error?.message}`, error: `Failure getting address score: ${error.message}`,
errorCode: 'operatorCancel', errorCode: 'ciphertraceError',
dispense: true 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) return pi.isValidWalletScore(tx.walletScore)
.then(isValid => isValid ? tx : _.assign(tx, { .then(isValid => isValid ? tx : _.assign(tx, {
error: 'Address score is above defined threshold', error: 'Address score is above defined threshold',
errorCode: 'operatorCancel', errorCode: 'scoreThresholdReached',
dispense: true dispense: true
})) }))
} }

View file

@ -25,7 +25,7 @@ const sms = require('./sms')
const settingsLoader = require('./new-settings-loader') const settingsLoader = require('./new-settings-loader')
const logger = require('./logger') const logger = require('./logger')
const TX_PASSTHROUGH_ERROR_CODES = ['operatorCancel'] const TX_PASSTHROUGH_ERROR_CODES = ['operatorCancel', 'scoreThresholdReached', 'ciphertraceError']
/** /**
* Add new customer * Add new customer

View file

@ -6,7 +6,7 @@ const logger = require('../../../logger')
const NAME = 'CipherTrace' const NAME = 'CipherTrace'
const SUPPORTED_COINS = ['BTC', 'ETH', 'BCH', 'LTC', 'BNB', 'RSK'] const SUPPORTED_COINS = ['BTC', 'ETH', 'BCH', 'LTC', 'BNB', 'RSK']
function getClient(account) { function getClient (account) {
if (_.isNil(account) || !account.enabled) return null if (_.isNil(account) || !account.enabled) return null
const [ctv1, username, secretKey] = account.authorizationValue.split(':') const [ctv1, username, secretKey] = account.authorizationValue.split(':')
@ -16,12 +16,12 @@ function getClient(account) {
const apiVersion = ctv1.slice(-2) const apiVersion = ctv1.slice(-2)
const authHeader = { const authHeader = {
"Authorization": account.authorizationValue 'Authorization': account.authorizationValue
} }
return { apiVersion, authHeader } return { apiVersion, authHeader }
} }
function rateWallet(account, cryptoCode, address) { function rateWallet (account, cryptoCode, address) {
const client = getClient(account) const client = getClient(account)
if (!_.includes(_.toUpper(cryptoCode), SUPPORTED_COINS) || _.isNil(client)) return Promise.resolve(null) 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 })) .then(res => ({ address, score: res.data.risk, isValid: res.data.risk < threshold }))
} }
function isValidWalletScore(account, score) { function isValidWalletScore (account, score) {
const client = getClient(account) const client = getClient(account)
if (_.isNil(client)) return Promise.resolve(true) 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) return _.isNil(account) ? Promise.resolve(true) : Promise.resolve(score < threshold)
} }
function getTransactionHash(account, cryptoCode, receivingAddress) { function getTransactionHash (account, cryptoCode, receivingAddress) {
const client = getClient(account) const client = getClient(account)
if (!_.includes(_.toUpper(cryptoCode), SUPPORTED_COINS) || _.isNil(client)) return Promise.resolve(null) if (!_.includes(_.toUpper(cryptoCode), SUPPORTED_COINS) || _.isNil(client)) return Promise.resolve(null)
const { apiVersion, authHeader } = client 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 headers: authHeader
}) })
.then(res => { .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) const client = getClient(account)
if (!_.includes(_.toUpper(cryptoCode), SUPPORTED_COINS) || _.isNil(client)) return Promise.resolve(null) if (!_.includes(_.toUpper(cryptoCode), SUPPORTED_COINS) || _.isNil(client)) return Promise.resolve(null)

View file

@ -69,7 +69,6 @@ function cancel (txId) {
}) })
} }
function customerHistory (customerId, thresholdDays) { function customerHistory (customerId, thresholdDays) {
const sql = `SELECT * FROM ( const sql = `SELECT * FROM (
SELECT txIn.id, txIn.created, txIn.fiat, 'cashIn' AS direction, SELECT txIn.id, txIn.created, txIn.fiat, 'cashIn' AS direction,
@ -84,7 +83,7 @@ function customerHistory (customerId, thresholdDays) {
FROM cash_out_txs txOut FROM cash_out_txs txOut
WHERE txOut.customer_id = $1 WHERE txOut.customer_id = $1
AND txOut.created > now() - interval $2 AND txOut.created > now() - interval $2
AND error_code IS DISTINCT FROM 'operatorCancel' AND error_code NOT IN ('operatorCancel', 'scoreThresholdReached', 'ciphertraceError')
AND fiat > 0 AND fiat > 0
) ch WHERE NOT ch.expired ORDER BY ch.created` ) ch WHERE NOT ch.expired ORDER BY ch.created`

View file

@ -4,7 +4,7 @@ const _ = require('lodash/fp')
const cashInTx = require('../../lib/cash-in/cash-in-tx') const cashInTx = require('../../lib/cash-in/cash-in-tx')
const { CASH_OUT_TRANSACTION_STATES, REDEEMABLE_AGE } = require('../../lib/cash-out/cash-out-helper') const { CASH_OUT_TRANSACTION_STATES, REDEEMABLE_AGE } = require('../../lib/cash-out/cash-out-helper')
const TX_PASSTHROUGH_ERROR_CODES = ['operatorCancel'] const TX_PASSTHROUGH_ERROR_CODES = ['operatorCancel', 'scoreThresholdReached', 'ciphertraceError']
function filterTransaction () { function filterTransaction () {
const sql = `EXPLAIN ANALYZE const sql = `EXPLAIN ANALYZE