feat: add blacklist message to machine communication

This commit is contained in:
Sérgio Salgado 2022-10-06 19:03:00 +01:00 committed by Rafael
parent 8af7c97c16
commit 677cb39f0c
4 changed files with 7 additions and 8 deletions

View file

@ -26,7 +26,7 @@ const insertIntoBlacklist = address => {
} }
function blocked (address) { function blocked (address) {
const sql = `SELECT * FROM blacklist WHERE address = $1` const sql = `SELECT address, content FROM blacklist b LEFT OUTER JOIN blacklist_messages bm ON bm.id = b.blacklist_message_id WHERE address = $1`
return db.any(sql, [address]) return db.any(sql, [address])
} }

View file

@ -8,7 +8,7 @@ const E = require('../error')
const PENDING_INTERVAL_MS = 60 * T.minutes const PENDING_INTERVAL_MS = 60 * T.minutes
const massageFields = ['direction', 'cryptoNetwork', 'bills', 'blacklisted', 'addressReuse', 'promoCodeApplied', 'validWalletScore', 'cashInFeeCrypto'] const massageFields = ['direction', 'cryptoNetwork', 'bills', 'blacklisted', 'blacklistMessage', 'addressReuse', 'promoCodeApplied', 'validWalletScore', 'cashInFeeCrypto']
const massageUpdateFields = _.concat(massageFields, 'cryptoAtoms') const massageUpdateFields = _.concat(massageFields, 'cryptoAtoms')
const massage = _.flow(_.omit(massageFields), const massage = _.flow(_.omit(massageFields),

View file

@ -32,7 +32,7 @@ function post (machineTx, pi) {
return cashInAtomic.atomic(machineTx, pi) return cashInAtomic.atomic(machineTx, pi)
.then(r => { .then(r => {
const updatedTx = r.tx const updatedTx = r.tx
let blacklisted = false let blacklisted = null
let addressReuse = false let addressReuse = false
let walletScore = {} let walletScore = {}
@ -50,7 +50,7 @@ function post (machineTx, pi) {
walletScore = fetchedWalletScore walletScore = fetchedWalletScore
if (_.some(it => it.address === updatedTx.toAddress)(blacklistItems)) { if (_.some(it => it.address === updatedTx.toAddress)(blacklistItems)) {
blacklisted = true blacklisted = _.find(it => it.address === updatedTx.toAddress)(blacklistItems)
notifier.notifyIfActive('compliance', 'blacklistNotify', r.tx, false) notifier.notifyIfActive('compliance', 'blacklistNotify', r.tx, false)
} else if (isReusedAddress && rejectAddressReuse) { } else if (isReusedAddress && rejectAddressReuse) {
notifier.notifyIfActive('compliance', 'blacklistNotify', r.tx, true) notifier.notifyIfActive('compliance', 'blacklistNotify', r.tx, true)
@ -61,7 +61,8 @@ function post (machineTx, pi) {
.then(changes => _.set('walletScore', _.isNil(walletScore) ? null : walletScore.score, changes)) .then(changes => _.set('walletScore', _.isNil(walletScore) ? null : walletScore.score, changes))
.then(changes => cashInLow.update(db, updatedTx, changes)) .then(changes => cashInLow.update(db, updatedTx, changes))
.then(tx => _.set('bills', machineTx.bills, tx)) .then(tx => _.set('bills', machineTx.bills, tx))
.then(tx => _.set('blacklisted', blacklisted, tx)) .then(tx => _.set('blacklisted', Boolean(blacklisted), tx))
.then(tx => _.set('blacklistMessage', blacklisted?.content, tx))
.then(tx => _.set('addressReuse', addressReuse, tx)) .then(tx => _.set('addressReuse', addressReuse, tx))
.then(tx => _.set('validWalletScore', _.isNil(walletScore) ? true : walletScore.isValid, tx)) .then(tx => _.set('validWalletScore', _.isNil(walletScore) ? true : walletScore.isValid, tx))
}) })

View file

@ -13,9 +13,7 @@ exports.up = function (next) {
allow_toggle BOOLEAN NOT NULL DEFAULT true allow_toggle BOOLEAN NOT NULL DEFAULT true
)`, )`,
`INSERT INTO blacklist_messages (id, label, content, allow_toggle) VALUES ('${defaultMessageId}', 'Suspicious address', 'This address may be associated with a deceptive offer or a prohibited group. Please make sure you''re using an address from your own wallet.', false)`, `INSERT INTO blacklist_messages (id, label, content, allow_toggle) VALUES ('${defaultMessageId}', 'Suspicious address', 'This address may be associated with a deceptive offer or a prohibited group. Please make sure you''re using an address from your own wallet.', false)`,
`ALTER TABLE blacklist ADD COLUMN blacklist_message_id UUID REFERENCES blacklist_messages(id)`, `ALTER TABLE blacklist ADD COLUMN blacklist_message_id UUID REFERENCES blacklist_messages(id) NOT NULL DEFAULT '${defaultMessageId}'`
`UPDATE blacklist SET blacklist_message_id = '${defaultMessageId}'`,
`ALTER TABLE blacklist ALTER COLUMN blacklist_message_id SET NOT NULL`
] ]
db.multi(sql, next) db.multi(sql, next)