fix: reuse last and reject reuse interaction

This commit is contained in:
Rafael Taranto 2025-06-09 17:11:49 +01:00
parent 22938ab594
commit 240d4d6f93
2 changed files with 16 additions and 2 deletions

View file

@ -30,6 +30,7 @@ module.exports = {
post,
monitorPending,
cancel,
doesTxReuseAddress,
PENDING_INTERVAL,
TRANSACTION_STATES,
}
@ -201,7 +202,7 @@ function postProcess(r, pi, isBlacklisted, addressReuse, walletScore) {
// 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({ toAddress, customerId }) {
const sql = `
SELECT COUNT(*) > 1 as exists
FROM (SELECT DISTINCT customer_id
@ -214,7 +215,7 @@ function doesTxReuseAddress(tx) {
WHERE $2 != $3) t;
`
return db
.one(sql, [tx.toAddress, tx.customerId, constants.anonymousCustomer.uuid])
.one(sql, [toAddress, customerId, constants.anonymousCustomer.uuid])
.then(({ exists }) => exists)
}

View file

@ -25,6 +25,7 @@ const Tx = require('../tx')
const loyalty = require('../loyalty')
const logger = require('../logger')
const externalCompliance = require('../compliance-external')
const { doesTxReuseAddress } = require('../cash-in/cash-in-tx')
function updateCustomerCustomInfoRequest(customerId, patch) {
const promise = _.isNil(patch.data)
@ -364,6 +365,18 @@ function addOrUpdateCustomer(
return { ...customer, lastUsedAddress }
})
})
.then(customer => {
const { rejectAddressReuse } = configManager.getCompliance(config)
if (!rejectAddressReuse || !customer.lastUsedAddress) return customer
return doesTxReuseAddress({
toAddress: customer.lastUsedAddress,
customerId: customer.id,
}).then(isReused => {
const newAddress = isReused ? null : customer.lastUsedAddress
return { ...customer, lastUsedAddress: newAddress }
})
})
}
function getOrAddCustomerPhone(req, res, next) {