-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: simplify cli usage and output
- Loading branch information
1 parent
a0106af
commit 3f8bd14
Showing
1 changed file
with
6 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]>, LLFourn <[email protected]>")] | ||
#[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(()) | ||
} |