Merge pull request #1035 from chaotixkilla/feat-add-ciphertrace-cashout-flow

Ciphertrace cash-out flow
This commit is contained in:
Rafael Taranto 2022-01-27 11:13:05 +00:00 committed by GitHub
commit 4450e19f1f
7 changed files with 159 additions and 7 deletions

View file

@ -1,6 +1,8 @@
const axios = require('axios')
const _ = require('lodash/fp')
const logger = require('../../../logger')
const NAME = 'CipherTrace'
const SUPPORTED_COINS = ['BTC', 'ETH', 'BCH', 'LTC', 'BNB', 'RSK']
@ -37,11 +39,53 @@ function isValidWalletScore(account, score) {
if (_.isNil(client)) return Promise.resolve(true)
const threshold = account.scoreThreshold
return Promise.resolve(score < threshold)
return _.isNil(account) ? Promise.resolve(true) : Promise.resolve(score < threshold)
}
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}`, {
headers: authHeader
})
.then(res => {
const data = res.data
if (_.size(data.txHistory) > 1) {
logger.warn('An address generated by this wallet was used in more than one transaction')
}
return _.join(', ', _.map(it => it.txHash, data.txHistory))
})
}
function getInputAddresses(account, cryptoCode, txHashes) {
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)}_` : ``}tx?txhashes=${txHashes}`, {
headers: authHeader
})
.then(res => {
const data = res.data
if (_.size(data.transactions) > 1) {
logger.warn('An address generated by this wallet was used in more than one transaction')
}
const transactionInputs = _.flatMap(it => it.inputs, data.transactions)
const inputAddresses = _.map(it => it.address, transactionInputs)
return inputAddresses
})
}
module.exports = {
NAME,
rateWallet,
isValidWalletScore
isValidWalletScore,
getTransactionHash,
getInputAddresses
}

View file

@ -6,7 +6,7 @@ function rateWallet (account, cryptoCode, address) {
return new Promise((resolve, _) => {
setTimeout(() => {
console.log('[WALLET-SCORING] DEBUG: Mock scoring rating wallet address %s', address)
return Promise.resolve(7)
return Promise.resolve(2)
.then(score => resolve({ address, score, isValid: score < WALLET_SCORE_THRESHOLD }))
}, 100)
})
@ -20,8 +20,26 @@ function isValidWalletScore (account, score) {
})
}
function getTransactionHash (account, cryptoCode, receivingAddress) {
return new Promise((resolve, _) => {
setTimeout(() => {
return resolve('<Fake transaction hash>')
}, 100)
})
}
function getInputAddresses (account, cryptoCode, txHashes) {
return new Promise((resolve, _) => {
setTimeout(() => {
return resolve(['<Fake input address hash>'])
}, 100)
})
}
module.exports = {
NAME,
rateWallet,
isValidWalletScore
isValidWalletScore,
getTransactionHash,
getInputAddresses
}