Skip to content

Commit

Permalink
fix(test): docs and integration tests
Browse files Browse the repository at this point in the history
- bump mempool/backend docker container version to v2.4.1
- update api+websocket client to handle genesis blocks without prev_blockhash
- update and fix integration tests to new fns and structure
  • Loading branch information
oleonardolima committed Aug 11, 2022
1 parent fa4775f commit 7bd795f
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 150 deletions.
4 changes: 1 addition & 3 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ impl From<BlockExtended> for BlockHeader {
fn from(extended: BlockExtended) -> Self {
BlockHeader {
version: extended.version,
prev_blockhash: extended
.prev_blockhash
.expect("Given `api::BlockExtended` does not have prev_blockhash field"),
prev_blockhash: extended.prev_blockhash.unwrap_or_default(),
merkle_root: extended.merkle_root,
time: extended.time,
bits: extended.bits,
Expand Down
24 changes: 11 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,35 @@
//! ## Subscribe to all new block events for mempool.space
//! ``` no_run
//! use anyhow::{self, Ok};
//! use futures_util::{pin_mut, StreamExt};
//! use futures::{pin_mut, StreamExt};
//!
//! #[tokio::main]
//! async fn main() -> anyhow::Result<()> {
//! env_logger::init();
//!
//! // for mempool.space regtest network
//! let base_url = "localhost:8999/testnet/api/v1";
//! // for mempool.space testnet network
//! let http_base_url = "http://mempool.space/testnet/api/";
//! let ws_base_url = "wss://mempool.space/testnet";
//!
//! // no checkpoint for this example, check the commented other one if interested.
//! // no checkpoint for this example, but you could use the following one to test it by yourself (in mainnet).
//! // checkpoint for first BDK Taproot transaction on mainnet (base_url update needed)
//! // let checkpoint = (709635, bitcoin::BlockHash::from("00000000000000000001f9ee4f69cbc75ce61db5178175c2ad021fe1df5bad8f"));
//! let checkpoint = None;
//!
//! // async fetch the block-events stream through the lib
//! let block_events = block_events::subscribe_to_block_headers(base_url, checkpoint).await?;
//! let block_events =
//! block_events::subscribe_to_block_headers(http_base_url, ws_base_url, checkpoint).await?;
//!
//! // consume and execute your code (current only matching and printing) in async manner for each new block-event
//! pin_mut!(block_events);
//! while let Some(block_event) = block_events.next().await {
//! match block_event {
//! block_events::api::BlockEvent::Connected(block) => {
//! println!(
//! "[connected block][block_hash {:#?}][block_prev_hash {:#?}]",
//! block.block_hash(),
//! block.prev_blockhash
//! );
//! match block_event? {
//! block_events::api::BlockEvent::Connected(block_header) => {
//! println!("[connected][block_header] {:#?}", block_header);
//! }
//! block_events::api::BlockEvent::Disconnected((height, block_hash)) => {
//! println!(
//! "[disconnected block][height {:#?}][block_hash: {:#?}]",
//! "[disconnected][height: {:#?}][block_hash: {:#?}]",
//! height, block_hash
//! );
//! }
Expand Down
Loading

0 comments on commit 7bd795f

Please sign in to comment.