From 11e3793e6ecf5180382beb1b18cfe4016719b361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Wed, 29 Jun 2022 15:01:20 +0100 Subject: [PATCH 1/3] chore: replace console.log with logger --- .../wallet-scoring/ciphertrace/ciphertrace.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js b/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js index b6416b82..22ded9de 100644 --- a/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js +++ b/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js @@ -28,18 +28,18 @@ 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}`) + logger.info(`** 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 }) .then(res => ({ address, score: res.data.risk, isValid: res.data.risk < threshold })) .then(result => { - console.log(`** DEBUG ** rateWallet RETURN: ${result}`) + logger.info(`** DEBUG ** rateWallet RETURN: ${result}`) return result }) .catch(err => { - console.log(`** DEBUG ** rateWallet ERROR: ${err.message}`) + logger.error(`** DEBUG ** rateWallet ERROR: ${err.message}`) throw err }) } @@ -58,7 +58,7 @@ 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`) + logger.info(`** 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 @@ -68,11 +68,11 @@ 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))}`) + logger.info(`** 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}`) + logger.error(`** DEBUG ** getTransactionHash ERROR: ${err}`) throw err }) } @@ -83,7 +83,7 @@ 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}`) + logger.info(`** 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 @@ -97,12 +97,12 @@ 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}`) + logger.info(`** DEBUG ** getInputAddresses RETURN: ${inputAddresses}`) return inputAddresses }) .catch(err => { - console.log(`** DEBUG ** getInputAddresses ERROR: ${err.message}`) + logger.error(`** DEBUG ** getInputAddresses ERROR: ${err.message}`) throw err }) } From c6741bf33fd3d6a5b6037dd131365dc0f922be07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Fri, 1 Jul 2022 17:50:56 +0100 Subject: [PATCH 2/3] chore: add delay before fetching tx hash --- lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js b/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js index 22ded9de..22c8e726 100644 --- a/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js +++ b/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js @@ -59,10 +59,12 @@ function getTransactionHash (account, cryptoCode, receivingAddress) { const { apiVersion, authHeader } = client logger.info(`** 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 + return new Promise(resolve => { + setTimeout(resolve, 5) }) + .then(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 => { const data = res.data if (_.size(data.txHistory) > 1) { From 7aa3bfebbfa73d56e87c9ed5c074e4586e539908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Fri, 1 Jul 2022 17:55:58 +0100 Subject: [PATCH 3/3] chore: set timeout to 2s --- lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js b/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js index 22c8e726..dc381d2d 100644 --- a/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js +++ b/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js @@ -60,7 +60,7 @@ function getTransactionHash (account, cryptoCode, receivingAddress) { logger.info(`** DEBUG ** getTransactionHash ENDPOINT: https://rest.ciphertrace.com/api/${apiVersion}/${_.toLower(cryptoCode) !== 'btc' ? `${_.toLower(cryptoCode)}_` : ``}address/search?features=tx&address=${receivingAddress}&mempool=true`) return new Promise(resolve => { - setTimeout(resolve, 5) + setTimeout(resolve, 2000) }) .then(axios.get(`https://rest.ciphertrace.com/api/${apiVersion}/${_.toLower(cryptoCode) !== 'btc' ? `${_.toLower(cryptoCode)}_` : ``}address/search?features=tx&address=${receivingAddress}&mempool=true`, { headers: authHeader