feat: add mock wallet scoring
This commit is contained in:
parent
b0fa62a9f3
commit
584492cb55
6 changed files with 76 additions and 6 deletions
|
|
@ -8,7 +8,7 @@ const E = require('../error')
|
|||
|
||||
const PENDING_INTERVAL_MS = 60 * T.minutes
|
||||
|
||||
const massageFields = ['direction', 'cryptoNetwork', 'bills', 'blacklisted', 'addressReuse', 'promoCodeApplied']
|
||||
const massageFields = ['direction', 'cryptoNetwork', 'bills', 'blacklisted', 'addressReuse', 'promoCodeApplied', 'failedWalletScore']
|
||||
const massageUpdateFields = _.concat(massageFields, 'cryptoAtoms')
|
||||
|
||||
const massage = _.flow(_.omit(massageFields),
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ const cashInLow = require('./cash-in-low')
|
|||
|
||||
const PENDING_INTERVAL = '60 minutes'
|
||||
const MAX_PENDING = 10
|
||||
const WALLET_SCORE_THRESHOLD = 10
|
||||
|
||||
const TRANSACTION_STATES = `
|
||||
case
|
||||
|
|
@ -33,11 +34,14 @@ function post (machineTx, pi) {
|
|||
const updatedTx = r.tx
|
||||
let blacklisted = false
|
||||
let addressReuse = false
|
||||
let failedWalletScore = false
|
||||
|
||||
return Promise.all([settingsLoader.loadLatest(), checkForBlacklisted(updatedTx), doesTxReuseAddress(updatedTx)])
|
||||
.then(([{ config }, blacklistItems, isReusedAddress]) => {
|
||||
return Promise.all([settingsLoader.loadLatest(), checkForBlacklisted(updatedTx), doesTxReuseAddress(updatedTx), doesWalletScoreFail(updatedTx, pi)])
|
||||
.then(([{ config }, blacklistItems, isReusedAddress, walletScoreFailed]) => {
|
||||
const rejectAddressReuse = configManager.getCompliance(config).rejectAddressReuse
|
||||
|
||||
failedWalletScore = walletScoreFailed
|
||||
|
||||
if (_.some(it => it.address === updatedTx.toAddress)(blacklistItems)) {
|
||||
blacklisted = true
|
||||
notifier.notifyIfActive('compliance', 'blacklistNotify', r.tx, false)
|
||||
|
|
@ -45,12 +49,13 @@ function post (machineTx, pi) {
|
|||
notifier.notifyIfActive('compliance', 'blacklistNotify', r.tx, true)
|
||||
addressReuse = true
|
||||
}
|
||||
return postProcess(r, pi, blacklisted, addressReuse)
|
||||
return postProcess(r, pi, blacklisted, addressReuse, failedWalletScore)
|
||||
})
|
||||
.then(changes => cashInLow.update(db, updatedTx, changes))
|
||||
.then(tx => _.set('bills', machineTx.bills, tx))
|
||||
.then(tx => _.set('blacklisted', blacklisted, tx))
|
||||
.then(tx => _.set('addressReuse', addressReuse, tx))
|
||||
.then(tx => _.set('failedWalletScore', failedWalletScore, tx))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +93,7 @@ function checkForBlacklisted (tx) {
|
|||
return Promise.resolve(false)
|
||||
}
|
||||
|
||||
function postProcess (r, pi, isBlacklisted, addressReuse) {
|
||||
function postProcess (r, pi, isBlacklisted, addressReuse, failedWalletScore) {
|
||||
if (addressReuse) {
|
||||
return Promise.resolve({
|
||||
operatorCompleted: true,
|
||||
|
|
@ -103,6 +108,13 @@ function postProcess (r, pi, isBlacklisted, addressReuse) {
|
|||
})
|
||||
}
|
||||
|
||||
if (failedWalletScore) {
|
||||
return Promise.resolve({
|
||||
operatorCompleted: true,
|
||||
error: 'Failed wallet score'
|
||||
})
|
||||
}
|
||||
|
||||
registerTrades(pi, r)
|
||||
|
||||
if (!cashInLow.isClearToSend(r.dbTx, r.tx)) return Promise.resolve({})
|
||||
|
|
@ -147,6 +159,14 @@ function doesTxReuseAddress (tx) {
|
|||
return Promise.resolve(false)
|
||||
}
|
||||
|
||||
function doesWalletScoreFail (tx, pi) {
|
||||
if (!tx.fiat || tx.fiat.isZero()) {
|
||||
return pi.rateWallet(tx.toAddress)
|
||||
.then(res => res >= WALLET_SCORE_THRESHOLD)
|
||||
}
|
||||
return Promise.resolve(false)
|
||||
}
|
||||
|
||||
function monitorPending (settings) {
|
||||
const sql = `select * from cash_in_txs
|
||||
where created > now() - interval $1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue