feat: improve debug logs

This commit is contained in:
José Oliveira 2022-05-16 18:30:15 +01:00
parent dc10537044
commit 5633f50c96
2 changed files with 19 additions and 9 deletions

View file

@ -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)

View file

@ -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 = {