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
Websockets support in web3j #261
Comments
If nobody is working on this issue, I would like to implement this. |
Infura ws info: |
Sorry for a long delay. Since this issue is tagged with As a result of this issue we should be able to subscribe to updates from the Ethereum network using the WebSocket protocol (example from the go-ethereum doc):
Essentially we need to call the Subscriptions can be canceled by calling the
This API allows to subscribe to following updates:
Since WebSockets interface is just an alternative transport for JSON RPC, I propose to add another implementation of the public interface Web3jService {
<T extends Response> T send(
Request request, Class<T> responseType) throws IOException;
<T extends Response> CompletableFuture<T> sendAsync(
Request request, Class<T> responseType);
/**
* Subscribe to a sream of events
*/
default Observable<Event<T>> subscribe(SubsribtionRequest request, Class<T> eventType) {
throw new UnsupportedOperationException();
}
/**
* Returns true if an implementation supports subscription, returns false otherwise
*/
default boolean supportsSubscription() {
return false;
}
} We need two separate methods because subsciptions are not supported by HTTP transport and we need to distinguish what methods are supported by a particular implementation: $ curl --data '{"method":"eth_subscribe","params":["newHeads"],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST localhost:8545
{"jsonrpc":"2.0","id":1,"error":{"code":-32000,"message":"notifications not supported"}} By default implementations of the
Currently
To create a proper instance of the this.web3jRx = new JsonRpc2_0Rx(this, scheduledExecutorService); will be replaced with something like: this.web3jRx = JsonRpc2_0RxFactory.instance()
.withWeb3j(this)
.withPollingInterval(pollingInterval)
.withExecutorService(scheduledExecutorService)
.build() What do you think about this? Does it make sense? Did you have other design ideas in mind? |
@mushketyk I really like your suggestions here, it's well thought out. The fluent interface is a nice idea too. The only additional considerations I have are:
|
What do you think about this one: https://github.com/TooTallNate/Java-WebSocket ? It has no dependencies, and it seems to be quite popular (judging by the number of GitHub stars :) )
Do you mean code like this (generated code from public rx.Observable<TransferEventResponse> transferEventObservable(org.web3j.protocol.core.methods.request.EthFilter filter) {
return web3j.ethLogObservable(filter).map(new rx.functions.Func1<org.web3j.protocol.core.methods.response.Log, TransferEventResponse>() {
...
};
} It should support existing filters since WebSockets transport supports all RPC methods that are available via HTTP. I don't think we can use WebSockets subscriptions to implement all methods that that |
How's this implementation going @mushketyk? :) |
@mushketyk Thank you for your improvement! I am interested in helping to get this working on Android. However, there is no documentation describing the process of making an release ready for Android. What makes a release ready for Android? |
@mushketyk Thanks. Also, I thought your changes made it into 3.4.0 according to the notes. They mention "Support for WebSocket to listen Log Events #392", where #392 points right here, #261. However, I went to try the latest release and didn't find WebSocketService within the core protocols. Did I miss something? @conor10 Is there a published process to make a release Android-ready? |
Could someone publish the new web3j with websocket support? Thanks! |
What's the timeline for this getting published in a release? |
@conor10 Could you please let me know how I can help this get released? There are a few features I want to develop that are blocked by it. |
Noting here that we need to add basic auth support for websockets as aligned with other web3 implementations |
@mushketyk @dbryan0516 Is there anything in the scope of this issue we would like to add? |
@iikirilov Nothing on my end |
web3j doesn't currently support web socket connections to Geth and Parity. It would be useful to include this functionality.
The text was updated successfully, but these errors were encountered: