From dc105370440c53e32db844e458db9e85061cb9ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Mon, 16 May 2022 18:12:52 +0100 Subject: [PATCH 1/2] feat: ciphertrace debug logs --- lib/cash-out/cash-out-tx.js | 9 +++++++++ lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/lib/cash-out/cash-out-tx.js b/lib/cash-out/cash-out-tx.js index 4abf18ea..cf52bac9 100644 --- a/lib/cash-out/cash-out-tx.js +++ b/lib/cash-out/cash-out-tx.js @@ -124,12 +124,21 @@ function getWalletScore (tx, pi) { if (_.includes(tx.status, statuses) && _.isNil(tx.walletScore)) { // Transaction shows up on the blockchain, we can request the sender address return pi.getTransactionHash(tx) + .catch(err => { + console.log(`** DEBUG ** getTransactionHash ERROR: ${err}`) + }) .then(txHashes => pi.getInputAddresses(tx, txHashes)) + .catch(err => { + console.log(`** DEBUG ** getInputAddresses ERROR: ${err.message}`) + }) .then(addresses => { const addressesPromise = [] _.forEach(it => addressesPromise.push(pi.rateWallet(tx.cryptoCode, it)), addresses) return Promise.all(addressesPromise) }) + .catch(err => { + console.log(`** DEBUG ** rateWallet ERROR: ${err.message}`) + }) .then(scores => { if (_.isNil(scores) || _.isEmpty(scores)) return tx const highestScore = _.maxBy(it => it.score, scores) diff --git a/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js b/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js index d38598ab..6fae11a1 100644 --- a/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js +++ b/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js @@ -28,6 +28,8 @@ function rateWallet (account, cryptoCode, address) { const { apiVersion, authHeader } = client const threshold = account.scoreThreshold + console.log(`** DEBUG ** rateWallet ENDPOINT: https://rest.ciphertrace.com/aml/${apiVersion}/${_.toLower(cryptoCode)}/risk?address=${address}`) + return axios.get(`https://rest.ciphertrace.com/aml/${apiVersion}/${_.toLower(cryptoCode)}/risk?address=${address}`, { headers: authHeader }) @@ -48,6 +50,8 @@ function getTransactionHash (account, cryptoCode, receivingAddress) { const { apiVersion, authHeader } = client + console.log(`** DEBUG ** getTransactionHash ENDPOINT: https://rest.ciphertrace.com/api/${apiVersion}/${_.toLower(cryptoCode) !== 'btc' ? `${_.toLower(cryptoCode)}_` : ``}address/search?features=tx&address=${receivingAddress}&mempool=true`) + return axios.get(`https://rest.ciphertrace.com/api/${apiVersion}/${_.toLower(cryptoCode) !== 'btc' ? `${_.toLower(cryptoCode)}_` : ``}address/search?features=tx&address=${receivingAddress}&mempool=true`, { headers: authHeader }) @@ -66,6 +70,8 @@ function getInputAddresses (account, cryptoCode, txHashes) { const { apiVersion, authHeader } = client + console.log(`** DEBUG ** getInputAddresses ENDPOINT: https://rest.ciphertrace.com/api/${apiVersion}/${_.toLower(cryptoCode) !== 'btc' ? `${_.toLower(cryptoCode)}_` : ``}tx?txhashes=${txHashes}`) + return axios.get(`https://rest.ciphertrace.com/api/${apiVersion}/${_.toLower(cryptoCode) !== 'btc' ? `${_.toLower(cryptoCode)}_` : ``}tx?txhashes=${txHashes}`, { headers: authHeader }) From 5633f50c961eaff9969420d1136a4d0244cc7cb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Mon, 16 May 2022 18:30:15 +0100 Subject: [PATCH 2/2] feat: improve debug logs --- lib/cash-out/cash-out-tx.js | 9 --------- .../wallet-scoring/ciphertrace/ciphertrace.js | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/cash-out/cash-out-tx.js b/lib/cash-out/cash-out-tx.js index cf52bac9..4abf18ea 100644 --- a/lib/cash-out/cash-out-tx.js +++ b/lib/cash-out/cash-out-tx.js @@ -124,21 +124,12 @@ function getWalletScore (tx, pi) { if (_.includes(tx.status, statuses) && _.isNil(tx.walletScore)) { // Transaction shows up on the blockchain, we can request the sender address return pi.getTransactionHash(tx) - .catch(err => { - console.log(`** DEBUG ** getTransactionHash ERROR: ${err}`) - }) .then(txHashes => pi.getInputAddresses(tx, txHashes)) - .catch(err => { - console.log(`** DEBUG ** getInputAddresses ERROR: ${err.message}`) - }) .then(addresses => { const addressesPromise = [] _.forEach(it => addressesPromise.push(pi.rateWallet(tx.cryptoCode, it)), addresses) return Promise.all(addressesPromise) }) - .catch(err => { - console.log(`** DEBUG ** rateWallet ERROR: ${err.message}`) - }) .then(scores => { if (_.isNil(scores) || _.isEmpty(scores)) return tx const highestScore = _.maxBy(it => it.score, scores) diff --git a/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js b/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js index 6fae11a1..b6416b82 100644 --- a/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js +++ b/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js @@ -34,6 +34,14 @@ function rateWallet (account, cryptoCode, address) { headers: authHeader }) .then(res => ({ address, score: res.data.risk, isValid: res.data.risk < threshold })) + .then(result => { + console.log(`** DEBUG ** rateWallet RETURN: ${result}`) + return result + }) + .catch(err => { + console.log(`** DEBUG ** rateWallet ERROR: ${err.message}`) + throw err + }) } function isValidWalletScore (account, score) { @@ -60,8 +68,13 @@ function getTransactionHash (account, cryptoCode, receivingAddress) { if (_.size(data.txHistory) > 1) { logger.warn('An address generated by this wallet was used in more than one transaction') } + console.log(`** DEBUG ** getTransactionHash RETURN: ${_.join(', ', _.map(it => it.txHash, data.txHistory))}`) return _.join(', ', _.map(it => it.txHash, data.txHistory)) }) + .catch(err => { + console.log(`** DEBUG ** getTransactionHash ERROR: ${err}`) + throw err + }) } function getInputAddresses (account, cryptoCode, txHashes) { @@ -84,8 +97,14 @@ function getInputAddresses (account, cryptoCode, txHashes) { const transactionInputs = _.flatMap(it => it.inputs, data.transactions) const inputAddresses = _.map(it => it.address, transactionInputs) + console.log(`** DEBUG ** getInputAddresses RETURN: ${inputAddresses}`) + return inputAddresses }) + .catch(err => { + console.log(`** DEBUG ** getInputAddresses ERROR: ${err.message}`) + throw err + }) } module.exports = {