Add blacklist functionality
This commit is contained in:
parent
a638524249
commit
4640b4a774
6 changed files with 57 additions and 7 deletions
|
|
@ -2,6 +2,7 @@ const _ = require('lodash/fp')
|
|||
const pgp = require('pg-promise')()
|
||||
const pEachSeries = require('p-each-series')
|
||||
|
||||
const blacklist = require('../blacklist')
|
||||
const db = require('../db')
|
||||
const plugins = require('../plugins')
|
||||
const logger = require('../logger')
|
||||
|
|
@ -18,10 +19,16 @@ function post (machineTx, pi) {
|
|||
return db.tx(cashInAtomic.atomic(machineTx, pi))
|
||||
.then(r => {
|
||||
const updatedTx = r.tx
|
||||
let blacklisted = false
|
||||
|
||||
return postProcess(r, pi)
|
||||
return checkForBlacklisted(updatedTx)
|
||||
.then(isBlacklisted => {
|
||||
blacklisted = !!isBlacklisted
|
||||
return postProcess(r, pi, blacklisted)
|
||||
})
|
||||
.then(changes => cashInLow.update(db, updatedTx, changes))
|
||||
.then(tx => _.set('bills', machineTx.bills, tx))
|
||||
.then(tx => _.set('blacklisted', blacklisted, tx))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -51,7 +58,22 @@ function logActionById (action, _rec, txId) {
|
|||
return db.none(sql)
|
||||
}
|
||||
|
||||
function postProcess (r, pi) {
|
||||
function checkForBlacklisted (tx) {
|
||||
// Check only on addressScan and avoid testing for blacklist on every bill inserted
|
||||
if (!tx.fiat || tx.fiat.isZero()) {
|
||||
return blacklist.blocked(tx.toAddress, tx.cryptoCode)
|
||||
}
|
||||
return Promise.resolve(false)
|
||||
}
|
||||
|
||||
function postProcess (r, pi, isBlacklisted) {
|
||||
if (isBlacklisted) {
|
||||
return Promise.resolve({
|
||||
operatorCompleted: true,
|
||||
error: 'Blacklisted Address'
|
||||
})
|
||||
}
|
||||
|
||||
registerTrades(pi, r.newBills)
|
||||
|
||||
if (!cashInLow.isClearToSend(r.dbTx, r.tx)) return Promise.resolve({})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue