-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix web3j#152. Filters create requests based on type #154
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import java.util.concurrent.TimeUnit; | ||
|
||
import org.web3j.protocol.Web3j; | ||
import org.web3j.protocol.core.Request; | ||
import org.web3j.protocol.core.Response; | ||
import org.web3j.protocol.core.methods.response.EthFilter; | ||
import org.web3j.protocol.core.methods.response.EthLog; | ||
|
@@ -39,7 +40,7 @@ public void run(ScheduledExecutorService scheduledExecutorService, long blockTim | |
} | ||
|
||
filterId = ethFilter.getFilterId(); | ||
EthLog ethLogInit = web3j.ethGetFilterLogs(filterId).send(); | ||
EthLog ethLogInit = this.createFilterRequest(this.filterId).send(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it makes sense for this initial request to take place asynchronously too once we have the filter id. Appreciate the current implementation is down to me, but it would be great if you could update this too. E.g.: scheduledExecutorService.submit(() -> {
EthLog ethLog = null;
try {
ethLog = this.createFilterRequest(this.filterId).send();
} catch (IOException e) {
throwException(e);
}
process(ethLog.getLogs());
}); |
||
process(ethLogInit.getLogs()); | ||
|
||
schedule = scheduledExecutorService.scheduleAtFixedRate(() -> { | ||
|
@@ -85,6 +86,8 @@ public void cancel() { | |
} | ||
} | ||
|
||
protected abstract Request<?, EthLog> createFilterRequest(BigInteger filterId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please can we rename this to |
||
|
||
void throwException(Response.Error error) { | ||
throw new FilterException("Invalid request: " + error.getMessage()); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
package org.web3j.protocol.core.filters; | ||
|
||
import java.io.IOException; | ||
import java.math.BigInteger; | ||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
import org.web3j.protocol.Web3j; | ||
import org.web3j.protocol.core.Request; | ||
import org.web3j.protocol.core.methods.response.EthFilter; | ||
import org.web3j.protocol.core.methods.response.EthLog; | ||
|
||
|
@@ -34,5 +36,10 @@ void process(List<EthLog.LogResult> logResults) { | |
} | ||
} | ||
} | ||
|
||
@Override | ||
protected Request<?, EthLog> createFilterRequest(BigInteger filterId) { | ||
return this.web3j.ethGetFilterChanges(filterId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice if this could be a no-op, with a comment that getFilterChanges is not supported for PendingTransactionFilters. |
||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if this could be a no-op, with a comment that getFilterChanges is not supported for BlockFilters.