I am wondering what the best way is to watch several (hundreds or thousands) Ethereum addresses at once for incoming transactions and send out the amount deposited once a transaction is detected. I came across similar questions on this forum where a few solutions have been proposed.
For instance, one answer proposed here: How to monitor all your addresses and send payments out immediately to a main address
setInterval(function(){
var target = web3.eth.accounts[10];
for (var account = 0; account < 10; account++) {
var balance = web3.eth.getBalance(web3.eth.accounts[account]);
if(balance > 0)
web3.eth.sendTransaction({from: web3.eth.accounts[account], to: target, value: balance});
}
}, 10000);
However, this does not seem very scalable, because you'd have to unlock all hundreds or thousands of addresses to keep watch.
Another solution proposed is to watch for all transactions on the blockchain, and check if the address match any of your watched addresses: https://ethereum.stackexchange.com/a/35818/27511
Again, I don't think this is scalable if you have hundreds or even thousands of addresses. Let's say you have 10,000 addresses to watch, and 1,000 incoming transactions, that would be an n^2 operation to check each transaction against each address.
Is there a more efficient way, or are these the only options?