From 3f8bd142e2d9ffd32025aad41aa2773b515be85d Mon Sep 17 00:00:00 2001 From: Leonardo Lima Date: Wed, 6 Jul 2022 18:03:32 -0300 Subject: [PATCH] chore: simplify cli usage and output --- src/bin.rs | 45 ++++++--------------------------------------- 1 file changed, 6 insertions(+), 39 deletions(-) diff --git a/src/bin.rs b/src/bin.rs index 569f3c3..187e596 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -1,7 +1,5 @@ -use std::str::FromStr; - use anyhow::Ok; -use bitcoin::{Address, BlockHash, Network}; +use block_events::api::BlockEvent; use clap::{ArgGroup, Parser, Subcommand}; use futures_util::{pin_mut, StreamExt}; use serde::{Deserialize, Serialize}; @@ -11,16 +9,15 @@ use serde::{Deserialize, Serialize}; #[clap(author = "Leonardo Souza , LLFourn ")] #[clap(version = "0.1.0")] #[clap( - long_about = "A CLI interface and tool to use with the block-events library.\n -This a work in progress project for Summer of Bitcoin 2022." + long_about = "A CLI interface and tool to use with the block-events library. A work in progress project for Summer of Bitcoin 2022." )] struct Cli { #[clap(subcommand)] command: Commands, - #[clap(short, long, default_value = "testnet")] - network: Network, + #[clap(short, long, default_value = "mempool.space/testnet/api/v1")] + base_url: String, } #[derive(Debug, Subcommand)] @@ -66,43 +63,13 @@ async fn main() -> anyhow::Result<()> { let cli = Cli::parse(); - // build the url by the network argument - let base_url = &match cli.network { - Network::Bitcoin => "mempool.space/api/v1".to_string(), - Network::Regtest => "127.0.0.1:8999/api/v1".to_string(), - network => format!("mempool.space/{}/api/v1", network), - }; - // async fetch the data stream through the lib - let block_events = block_events::subscribe_to_blocks( - base_url.as_str(), - // Some(( - // 102, - // BlockHash::from_str("3d3ab0efd0f8f0eb047d9e77f7ad7c6b6791c896bd8a21437da555670f799e08") - // .unwrap(), - // )), - None, - ) - .await?; + let block_events = block_events::subscribe_to_blocks(cli.base_url.as_str(), None).await?; // consume and execute the code (current matching and printing) in async manner for each new block-event pin_mut!(block_events); while let Some(block_event) = block_events.next().await { - println!("BlockExtended: {:#?}", block_event) - // match block_event { - // BlockEvent::Connected(block) => { - // println!("Connected BlockEvent: {:#?}", block); - // } - // BlockEvent::Disconnected((height, block_hash)) => { - // println!( - // "Disconnected BlockEvent: [height {:#?}] [block_hash: {:#?}]", - // height, block_hash - // ); - // } - // BlockEvent::Error() => { - // eprint!("ERROR BlockEvent: received an error from the block-events stream"); - // } - // } + println!("{:#?}", block_event); } Ok(()) }