feat: add migration to clean blacklist table

fix: address reuse and blacklist check
This commit is contained in:
Sérgio Salgado 2021-06-23 18:03:51 +01:00 committed by Josh Harvey
parent f682a77eb5
commit d7519d477e
4 changed files with 23 additions and 20 deletions

View file

@ -34,14 +34,14 @@ function post (machineTx, pi) {
let blacklisted = false
let addressReuse = false
return Promise.all([settingsLoader.loadLatest(), checkForBlacklisted(updatedTx)])
.then(([{ config }, blacklistItems]) => {
const rejectAddressReuseActive = configManager.getCompliance(config).rejectAddressReuse
return Promise.all([settingsLoader.loadLatest(), checkForBlacklisted(updatedTx), getAddresses()])
.then(([{ config }, blacklistItems, addresses]) => {
const rejectAddressReuse = configManager.getCompliance(config).rejectAddressReuse
if (_.some(it => it.created_by_operator)(blacklistItems)) {
if (_.some(it => it.address === updatedTx.toAddress)(blacklistItems)) {
blacklisted = true
notifier.notifyIfActive('compliance', 'blacklistNotify', r.tx, false)
} else if (_.some(it => !it.created_by_operator)(blacklistItems) && rejectAddressReuseActive) {
} else if (_.some(it => it === updatedTx.toAddress)(addresses) && rejectAddressReuse) {
notifier.notifyIfActive('compliance', 'blacklistNotify', r.tx, true)
addressReuse = true
}
@ -133,17 +133,18 @@ function postProcess (r, pi, isBlacklisted, addressReuse) {
}
})
.then(sendRec => {
settingsLoader.loadLatest().then(it => {
blacklist.addToUsedAddresses(r.tx.toAddress, r.tx.cryptoCode)
.catch(err => logger.error('Failure adding to addressReuse', err))
})
pi.notifyOperator(r.tx, sendRec)
.catch((err) => logger.error('Failure sending transaction notification', err))
return logAction(sendRec, r.tx)
})
}
function getAddresses () {
const sql = `SELECT DISTINCT to_address FROM cash_in_txs`
return db.any(sql).then(res => res.map(it => it.to_address))
}
function monitorPending (settings) {
const sql = `select * from cash_in_txs
where created > now() - interval $1