Real-Time Stream of Blocks API
Description
Many Bitcoin applications need to react in real-time to things happening on the blockchain. A core way of covering all those situations is being able to subscribe to a feed of all new blocks (and perhaps old ones too!). We do not currently have real-time APIs in BDK so your task is to create the first one (in a seperate crate for now).
Expected Outcomes
- Design an API for subscribing to new Bitcoin blocks
- The API should allow you to stream all new blocks.
- The data should be returned as a
Stream - Decide whether the API should be a Stream of
BlockorBlockHeader(or both!). - If
BlockHeaderthen provide a way to get the fullBlock - See if you can make the API take a block height so the stream returns all blocks after that one by going back and fetching old ones if needed.
- Implement the API for some block source:
- bitcoin core rpc + zeroMQ
- bitcoin p2p (hard)
- mempool.space's websocket API (easy)
- (optional) extend the API to allow users to monitor for:
- When a transaction is seen
- When a transaction is confirmed
- When an output is spent (and confirmed spent)
- transactions related to a certain address Note this can be done just by scanning through each block you get in your stream.
- Provide the API in an external crate with a name like
bdk_notifyor whatever you choose!
Resources
You'll need to get understanding the basics of Bitcoin, Blocks, transactions and UTXOs etc. The next best resource would be to poke around https://mempool.space and https://mempool.space/api to see what data is available about the blockchain and in what form.
Skills Required
- Need to know the rust language to the extent that you can use the API of
rust-bitcoin. - Be comfortable with using (or learning how to use)
reqwest - Be comfortable with using (or learning how to use) async/await and futures in rust
- Be comfortable with using (or learning how to use)
serde(for JSON deserialisation) - BDK specific knowledge is not required.
Mentor(s)
- Lloyd Fournier (@LLFourn)
Difficulty
Medium
Competency Test (optional)
- Write a rust program to subscribe to the websocket API of mempool.space and print out any new blocks in real time.
So after thinking about it. I recall that @johncantrell97 mentioned that LDK made use of this API which also notified you of which blocks have been disconnected as well as connected.
So instead of a stream of block headers you'd have two types of events:
pub enum Event {
Connected(BlockHeader),
Disconnected((u32, BlockHash)) // height and hash
}
This would fit in well also with what I am doing with bdk_core. Does this make sense @johncantrell97?
Closing this issue since we don't have anyone to mentor it this year, can reopen next year if we have more folks who can mentor.