I am using the following code to listen/watch contract events(web3j):
Event TRANSFER_EVENT = new Event("Transfer", Arrays.<TypeReference<?>>asList(new TypeReference<Address>(true){}, new TypeReference<Address>(true){}, new TypeReference<Uint256>(false){}));
String TRANSFER_EVENT_HASH = EventEncoder.encode(TRANSFER_EVENT);
EthFilter filterProxy = new EthFilter(DefaultBlockParameterName.EARLIEST, DefaultBlockParameterName.LATEST, contractAddress);
filterProxy.addSingleTopic(TRANSFER_EVENT_HASH);
Disposable subscription = web3j.ethLogFlowable(filterProxy).subscribe(log -> {
// address indexed _arg1
Address arg1 = (Address) FunctionReturnDecoder.decodeIndexedValue(log.getTopics().get(1), new TypeReference<Address>() {});
// bytes32 indexed _arg2
Address arg2 = (Address) FunctionReturnDecoder.decodeIndexedValue(log.getTopics().get(2), new TypeReference<Address>() {});
// uint8 _arg3
Uint256 arg3 = (Uint256) FunctionReturnDecoder.decodeIndexedValue(log.getData(), new TypeReference<Uint256>() {});
},Throwable::printStackTrace);
It's working fine and can capture all the events.
But how to stop the subscription? Tried subscription.dispose() and CountDownLatch, both doesn't work.