From f250698da9c2edac40f62981a634b7b988323a10 Mon Sep 17 00:00:00 2001 From: kexkey Date: Tue, 11 Aug 2020 14:57:55 -0400 Subject: [PATCH] Check for duplicated addresses in batch outputs --- proxy_docker/app/script/batching.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/proxy_docker/app/script/batching.sh b/proxy_docker/app/script/batching.sh index 16553c8..d99b77b 100644 --- a/proxy_docker/app/script/batching.sh +++ b/proxy_docker/app/script/batching.sh @@ -190,6 +190,20 @@ addtobatch() { # batcherLabel not found response='{"result":null,"error":{"code":-32700,"message":"batcher not found","data":'${request}'}}' else + # Check if address already pending for this batcher... + inserted_id=$(sql "SELECT id FROM recipient WHERE address=\"${address}\" AND tx_id IS NULL AND batcher_id=${batcher_id}") + if [ -n "${inserted_id}" ]; then + response='{"result":null,"error":{"code":-32700,"message":"Duplicated address","data":'${request}'}}' + + trace "[addtobatch] Duplicated address" + trace "[addtobatch] responding=${response}" + + echo "${response}" + + return 1 + fi + + # Insert the new destination inserted_id=$(sql "INSERT INTO recipient (address, amount, webhook_url, batcher_id, label) VALUES (\"${address}\", ${amount}, ${webhook_url}, ${batcher_id}, ${label}); SELECT LAST_INSERT_ROWID();") returncode=$? trace_rc ${returncode}