fix: reuse last and reject reuse interaction
This commit is contained in:
parent
22938ab594
commit
240d4d6f93
2 changed files with 16 additions and 2 deletions
|
|
@ -30,6 +30,7 @@ module.exports = {
|
||||||
post,
|
post,
|
||||||
monitorPending,
|
monitorPending,
|
||||||
cancel,
|
cancel,
|
||||||
|
doesTxReuseAddress,
|
||||||
PENDING_INTERVAL,
|
PENDING_INTERVAL,
|
||||||
TRANSACTION_STATES,
|
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,
|
// 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.
|
// 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
|
// To prevent malicious blocking of address, we only check for txs with actual fiat
|
||||||
function doesTxReuseAddress(tx) {
|
function doesTxReuseAddress({ toAddress, customerId }) {
|
||||||
const sql = `
|
const sql = `
|
||||||
SELECT COUNT(*) > 1 as exists
|
SELECT COUNT(*) > 1 as exists
|
||||||
FROM (SELECT DISTINCT customer_id
|
FROM (SELECT DISTINCT customer_id
|
||||||
|
|
@ -214,7 +215,7 @@ function doesTxReuseAddress(tx) {
|
||||||
WHERE $2 != $3) t;
|
WHERE $2 != $3) t;
|
||||||
`
|
`
|
||||||
return db
|
return db
|
||||||
.one(sql, [tx.toAddress, tx.customerId, constants.anonymousCustomer.uuid])
|
.one(sql, [toAddress, customerId, constants.anonymousCustomer.uuid])
|
||||||
.then(({ exists }) => exists)
|
.then(({ exists }) => exists)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ const Tx = require('../tx')
|
||||||
const loyalty = require('../loyalty')
|
const loyalty = require('../loyalty')
|
||||||
const logger = require('../logger')
|
const logger = require('../logger')
|
||||||
const externalCompliance = require('../compliance-external')
|
const externalCompliance = require('../compliance-external')
|
||||||
|
const { doesTxReuseAddress } = require('../cash-in/cash-in-tx')
|
||||||
|
|
||||||
function updateCustomerCustomInfoRequest(customerId, patch) {
|
function updateCustomerCustomInfoRequest(customerId, patch) {
|
||||||
const promise = _.isNil(patch.data)
|
const promise = _.isNil(patch.data)
|
||||||
|
|
@ -364,6 +365,18 @@ function addOrUpdateCustomer(
|
||||||
return { ...customer, lastUsedAddress }
|
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) {
|
function getOrAddCustomerPhone(req, res, next) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue