From 28abcd78517bb4aeaf14ee6c1319b62ae67696e2 Mon Sep 17 00:00:00 2001 From: Nikola Ubavic <53820106+ubavic@users.noreply.github.com> Date: Mon, 31 Oct 2022 18:10:35 +0100 Subject: [PATCH] fix: address reuse query --- lib/cash-in/cash-in-tx.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/cash-in/cash-in-tx.js b/lib/cash-in/cash-in-tx.js index 728c4b86..2c13723e 100644 --- a/lib/cash-in/cash-in-tx.js +++ b/lib/cash-in/cash-in-tx.js @@ -45,7 +45,7 @@ function post (machineTx, pi) { if (_.some(it => it.address === updatedTx.toAddress)(blacklistItems)) { blacklisted = true notifier.notifyIfActive('compliance', 'blacklistNotify', r.tx, false) - } else if (isReusedAddress && rejectAddressReuse) { + } else if (isReusedAddress[0].exists && rejectAddressReuse) { notifier.notifyIfActive('compliance', 'blacklistNotify', r.tx, true) addressReuse = true } @@ -167,8 +167,13 @@ function postProcess (r, pi, isBlacklisted, addressReuse, walletScore) { function doesTxReuseAddress (tx) { if (!tx.fiat || tx.fiat.isZero()) { - const sql = `SELECT EXISTS (SELECT DISTINCT to_address FROM cash_in_txs WHERE to_address = $1)` - return db.any(sql, [tx.toAddress]) + const sql = ` + SELECT EXISTS ( + SELECT DISTINCT to_address FROM ( + SELECT to_address FROM cash_in_txs WHERE id != $1 + ) AS x WHERE to_address = $2 + )` + return db.any(sql, [tx.id, tx.toAddress]) } return Promise.resolve(false) }