Merge pull request #1870 from RafaelTaranto/feat/reject-address-per-customer
LAM-1432 feat: reject address per customer
This commit is contained in:
commit
e8deff7a88
1 changed files with 20 additions and 6 deletions
|
|
@ -9,6 +9,7 @@ const logger = require('../logger')
|
||||||
const settingsLoader = require('../new-settings-loader')
|
const settingsLoader = require('../new-settings-loader')
|
||||||
const configManager = require('../new-config-manager')
|
const configManager = require('../new-config-manager')
|
||||||
const notifier = require('../notifier')
|
const notifier = require('../notifier')
|
||||||
|
const constants = require('../constants')
|
||||||
|
|
||||||
const cashInAtomic = require('./cash-in-atomic')
|
const cashInAtomic = require('./cash-in-atomic')
|
||||||
const cashInLow = require('./cash-in-low')
|
const cashInLow = require('./cash-in-low')
|
||||||
|
|
@ -194,14 +195,27 @@ function postProcess(r, pi, isBlacklisted, addressReuse, walletScore) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This feels like it can be simplified,
|
||||||
|
// but it's the most concise query to express the requirement and its edge cases.
|
||||||
|
// At most only one authenticated customer can use an address.
|
||||||
|
// If the current customer is anon, we can still allow one other customer to use the address,
|
||||||
|
// So we count distinct customers plus the current customer if they are not anonymous.
|
||||||
|
// To prevent malicious blocking of address, we only check for txs with actual fiat
|
||||||
function doesTxReuseAddress(tx) {
|
function doesTxReuseAddress(tx) {
|
||||||
const sql = `
|
const sql = `
|
||||||
SELECT EXISTS (
|
SELECT COUNT(*) > 1 as exists
|
||||||
SELECT DISTINCT to_address FROM (
|
FROM (SELECT DISTINCT customer_id
|
||||||
SELECT to_address FROM cash_in_txs WHERE id != $1
|
FROM cash_in_txs
|
||||||
) AS x WHERE to_address = $2
|
WHERE to_address = $1
|
||||||
)`
|
AND customer_id != $3
|
||||||
return db.one(sql, [tx.id, tx.toAddress]).then(({ exists }) => exists)
|
AND fiat > 0
|
||||||
|
UNION
|
||||||
|
SELECT $2
|
||||||
|
WHERE $2 != $3) t;
|
||||||
|
`
|
||||||
|
return db
|
||||||
|
.one(sql, [tx.toAddress, tx.customerId, constants.anonymousCustomer.uuid])
|
||||||
|
.then(({ exists }) => exists)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWalletScore(tx, pi) {
|
function getWalletScore(tx, pi) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue