Skip to content
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

hs-client: move all websocket calls under .ws namespace. #886

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nodech
Copy link
Contributor

@nodech nodech commented Feb 27, 2024

This makes it easier to reason about the calls. It becomes more explicit - what's going on, whether you need to call .open for a method call to work or not etc.

bindings and etc, other than methods themselves, could also work on the client as they were. But it's recommended to use .ws, makes it easier to read.

@nodech nodech added wallet part of the codebase breaking-major Backwards incompatible - Release version hs-client labels Feb 27, 2024
@coveralls
Copy link

Coverage Status

coverage: 68.619% (-0.007%) from 68.626%
when pulling ca10c0a on nodech:hs-client-ws
into 5f94317 on handshake-org:master.

@@ -420,20 +420,20 @@ describe('Node Rescan Interactive API', function() {
beforeEach(async () => {
client = nodeCtx.nodeClient();

await client.open();
await client.ws.open();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, consumers should not know about this.
When I'm using client, I want it to "open" and start doing whatever it needs to do. I don't need to know its internal structure. I don't want to know about ws. client is the interface I'm dealing with.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you can't be sure if call to getHashes is ws call or not, can't figure out whether you need open at all or not.

Currently, there are no conflicting calls, that have both HTTP and WS calls. But there are several use cases for example getHeader - It can be requested as an HTTP, but wallet client or anything that needs stateful synchronized communication will rather use WS variation.

open/close are both on client and WSClient, as WSClient is basically a namespace, not a separation (All methods like hook, call, bind, fire are both on WSClient as wall as on Client. But moving out methods to me makes client side code more readable and easier to make judgment if you should call .open and whether it depends on an OPEN connection.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to .open for majority of calls, RPC, HTTP. So there's no reason for any of those to have additional WS connection.

@nodech nodech removed the wallet part of the codebase label Feb 27, 2024
@nodech nodech requested a review from rithvikvibhu June 5, 2024 13:22
@nodech nodech added this to the hsd 7.0.0 milestone Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-major Backwards incompatible - Release version hs-client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants