Page MenuHomePhabricator

[Apps][Examples] Create a websocket to listen for a new block
AbandonedPublic

Authored by emack on Aug 9 2023, 01:40.

Details

Reviewers
bytesofman
Group Reviewers
Restricted Project
Summary

T3203

This is useful for app devs looking to build network visualizers which need to listen for new incoming blocks, without having to make direct RPC calls to the node.

The example uses a chronik websocket to listen for BlockConnected events and then unsubscribes and closes upon detection.

Test Plan

npm test
npm run listenForNewBlock <address>

Diff Detail

Repository
rABC Bitcoin ABC
Branch
wsNewBlock
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 24713
Build 49018: Build Diffapp-dev-examples
Build 49017: arc lint + arc unit

Event Timeline

emack requested review of this revision.Aug 9 2023, 01:40
Fabien added inline comments.
apps/examples/scripts/listenForNewBlock.js
45

why do you need the address to subscribe to new blocks ?

apps/examples/scripts/listenForNewBlock.js
45

I haven't checked this out in chronik or chronik-client, but I have tried to subscribe to a websocket without an address and it doesn't work

fix tho should be to allow this in chronik-client

emack marked 2 inline comments as done.Aug 10 2023, 07:08
emack added inline comments.
apps/examples/scripts/listenForNewBlock.js
45

why do you need the address to subscribe to new blocks ?

I just tested it using only ws.waitForOpen() to listen for over 2 consecutive blocks without an address subscription and it didn't pick up the BlockConnected (or any other) events. I can put in a diff on this once we're done with the big url cycling refactor in D14269.

apps/examples/scripts/listenForNewBlock.js
45

Is that on chronik-client or on chronik side ?

emack marked an inline comment as done.Aug 10 2023, 09:02
emack added inline comments.
apps/examples/scripts/listenForNewBlock.js
45

Is that on chronik-client or on chronik side ?

Tobias said the ability to subscribe to block updates is already in the chronik-embedded node software, so the client just needs to be updated to use it

apps/examples/scripts/listenForNewBlock.js
45

Sure but then your example won't work with the nng version (actual prod version) anymore

emack planned changes to this revision.Aug 10 2023, 09:21
emack marked an inline comment as done.
emack added inline comments.
apps/examples/scripts/listenForNewBlock.js
45

yea ok, will put this on ice until chronik-client is updated with this API.