-
-
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
Websockets support #458
Websockets support #458
Conversation
Codecov Report
@@ Coverage Diff @@
## master #458 +/- ##
===========================================
+ Coverage 76.87% 77.1% +0.23%
- Complexity 1686 1770 +84
===========================================
Files 222 236 +14
Lines 6295 6581 +286
Branches 972 984 +12
===========================================
+ Hits 4839 5074 +235
- Misses 1215 1262 +47
- Partials 241 245 +4
Continue to review full report at Codecov.
|
@conor10 I've made few more additional modifications to my PR, but now everything is ready for review. |
Awesome work @mushketyk 💯 - I'll get to it shortly. |
Thank you @conor10! I look forward to your review. |
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.
Great work so far, apologies for the delay in reviewing.
core/build.gradle
Outdated
testCompile project(path: ':crypto', configuration: 'archives'), | ||
"nl.jqno.equalsverifier:equalsverifier:$equalsverifierVersion" | ||
"nl.jqno.equalsverifier:equalsverifier:$equalsverifierVersion", | ||
group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3' |
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.
Please can this dependency be included using the same style as the others?
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.
Done.
* @param <T> type of a data item returned by the request | ||
* @return deserialized JSON-RPC response | ||
* @throws IOException thrown if failed to perform a request | ||
*/ |
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.
👍
* | ||
* @return Observable that emits a notification for every new header | ||
*/ | ||
Observable<NewHeadsNotification> newHeadsNotifications(); |
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.
This is Geth specific right? And some of the other calls?
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.
newHeads
and logs
are not specific to Geth. Parity supports it as well: https://wiki.parity.io/JSONRPC-Eth-Pub-Sub-Module.html
I'll move other two to the Geth related class
try { | ||
log.debug("Received message {} from server {}", s, uri); | ||
listener.onMessage(s); | ||
log.debug("Processed message {} from server {}", s, uri); |
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.
I don't think we need both debug statements
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.
Removed second message.
|
||
@Override | ||
public void onError(Exception e) { | ||
|
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.
Please can we have a log statement here?
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.
Do we need it here?
We have a log in the WebSocketClient
class:
@Override
public void onError(Exception e) {
log.error(String.format("WebSocket connection to {} failed with error", uri), e);
listener.onError(e);
}
this.responseType = responseType; | ||
} | ||
|
||
public CompletableFuture<T> getCompletableFuture() { |
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.
Please can you use something more specific for this method name & instance variable?
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.
Done. What do you think about onReply
?
|
||
import rx.subjects.BehaviorSubject; | ||
|
||
public class WebSocketSubscription<T> { |
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.
Please can you ensure all classes have a brief Javadoc description - a single sentence is fine.
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.
Done.
|
||
import java.util.List; | ||
|
||
public class Log { |
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.
I presume this Log differs from the other Log objects already defined?
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.
Yes, existing Log
class contains the following fields:
private boolean removed;
private String logIndex;
private String transactionIndex;
private String transactionHash;
private String blockHash;
private String blockNumber;
private String address;
private String data;
private String type;
private List<String> topics;
while this Log
class contains the following fields:
private String address;
private String blockHash;
private String blockNumber;
private String data;
private String logIndex;
private List<String> topics;
private String transactionHash;
private String transactionIndex;
private Web3j web3j = Web3j.build(service, 10, scheduledExecutorService); | ||
|
||
@Test | ||
public void testStopExecutorOnShutdown() throws Exception { |
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.
How come this test was moved to the websocket test class?
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.
Probably renamed this class accidentally in IDEA. Will revert this change.
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.
Undone :)
requestSent.await(2, TimeUnit.SECONDS); | ||
sendGethVersionReply(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); |
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.
Please can this be rethrown instead of discarded.
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.
Done.
Hi @conor10, Thank you for your review! I am a bit busy at the moment, but I'll try to update the PR next week. |
@conor10 Sorry for the long delay. I've updated the PR and replied to your comments. Could you please review the PR again? |
Awesome work 🥇 If you can get those docs written next it would be fantastic. |
Websockets support
@conor10 Sorry, I somehow missed your message. I'll write docs during the next week. |
Implements
WebSocketService
that allows calling JSON-RPC methods via WebSocket protocol and allows to subscribe to real-time notifications.Also adds new methods to the
Web3jRx
that allows subscribing to JSON-RPC notifications.The PR is already too big for a review, so I had to stop, but there are few things that are still missing: