Closed decent-dev closed 6 years ago
Nice suggestion. It's time to make a subscription module.
start working on branch subscription
To add onto this supporting IPC too would be great to keep feature parity with Eth. I personally use IPC to record activity on the blockchain and it is the preferred method if you do not need to expose the node.
I reckon a lot of projects that require their own node without exposing it would prefer to use IPC. If they are porting code over from Ethereum it would make it less painful.
Thoughts?
@samvaughton IMO, there's no key differences between loopback and unix-socket(named pipe), except the level of security. loopback allows all processes to access, while unix-socket is protected by file system permissions.
@qianbin Sorry if I'm getting confused, so this subscription module will be for web sockets? Will I need to use a web socket if I am reading the data from a Vechain node on the same system? Or is there already a IPC type implementation that can be used for observing new block headers etc?
@samvaughton
so this subscription module will be for web sockets?
Not for websocket, but using websocket to streaming messages, e.g. new blocks, events, transfers.
Will I need to use a web socket if I am reading the data from a Vechain node on the same system? Or is there already a IPC type implementation that can be used for observing new block headers etc?
The subscription module is still under developing. Polling is the only choice now.
@decent-dev @samvaughton
The subscription module is almost done. You can checkout the master
branch to build (make dep
before build).
OpenAPI doc is available at http://localhost:8669/doc/swagger-ui/#/Subscriptions
Examples to subscribe new blocks:
javascript in web browser
let ws = new WebSocket('ws://localhost:8669/subscriptions/block')
ws.onmessage = console.log
for wscat
# npm i -g wscat
wscat -c ws://localhost:8669/subscriptions/block
or curl
curl -v --header "Connection: Upgrade" --header "Upgrade: websocket" --header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" --header "Sec-WebSocket-Version: 13" http://localhost:8669/subscriptions/block
@qianbin Awesome, will check it out soon! Cheers
At the moment it seems like we're forced to use
getPastEvents()
to retrieve event logs from contracts that we intend to subscribe to.Polling
getPastEvents()
every X seconds is proving to be an inconvenience especially when designing dapps/scripts that depend on tracking events and acting on changes that have been made.Also subscriptions can't seem to be leveraged to track general events like say newBlockHeaders - which would have made certain things easier during development of dapps/scripts etc.
If we could use a web socket provider with Thor/Thorify, similar to how we do it with Geth/Web3 now - it'd aid Thor based development immensely.