-
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: update README, remove trailing spaces, fix deps usage
Signed-off-by: Leonardo Lima <[email protected]>
- Loading branch information
1 parent
a227856
commit 21ff758
Showing
5 changed files
with
80 additions
and
55 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 |
---|---|---|
|
@@ -2,10 +2,10 @@ | |
name = "block-events" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["Leonardo Souza <leonardo.lima@gmail.com>", "LLFourn <[email protected]>"] | ||
repository = "https://github.com/oleonardolima/block-explorer-cli" | ||
description = "A real-time stream block events library, covering connected and disconnected blocks." | ||
keywords = ["bitcoin", "blockchain", "blocks", "mempool-space", "stream", "events"] | ||
authors = ["Leonardo Souza <leonardolimasza@gmail.com>", "LLFourn <[email protected]>"] | ||
repository = "https://github.com/oleonardolima/block-events" | ||
description = "A real-time stream block events library, covering connected and disconnected blocks.\nThis a work in progress project for Summer of Bitcoin 2022." | ||
keywords = ["bitcoin", "blockchain", "blocks", "mempool-space", "stream", "events", "summer-of-bitcoin"] | ||
readme = "README.md" | ||
license = "MIT OR Apache-2.0" | ||
|
||
|
@@ -25,9 +25,9 @@ tokio-tungstenite = { version = "0.17.1", features = ["connect", "native-tls"]} | |
url = { version = "2.0.0" } | ||
|
||
[lib] | ||
name = "block_explorer_cli" | ||
name = "block_events" | ||
path = "src/lib.rs" | ||
|
||
[[bin]] | ||
name = "block-explorer-cli" | ||
name = "block-events-cli" | ||
path = "src/bin.rs" |
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,52 +1,79 @@ | ||
# A terminal block explorer for mempool.space websocket | ||
|
||
A terminal block explorer exposing the features available on [mempool.space websocket API](https://mempool.space/docs/api/websocket). | ||
|
||
Currently available features are: | ||
- All data feed from mempool.space for: blocks, mempool-blocks, live-2h-chart, and stats. | ||
- Subscription for address related data: track-address. | ||
# Real-time stream of block events library | ||
|
||
A library for consuming and subscribing to new block events in real-time from different sources: | ||
- [ ] mempool.space - [WebSocket](https://mempool.space/docs/api/websocket) and [REST](https://mempool.space/docs/api/rest) APIs (under development) | ||
- [ ] bitcoin core RPC `#TODO` | ||
- [ ] bitcoin P2P `#TODO` | ||
|
||
It's useful for projects to get notified for connected and disconnected new blocks, currently using the following as output in async manner: | ||
``` rust | ||
pub enum BlockEvent { | ||
Connected(BlockExtended), | ||
Disconnected((u32, BlockHash)), | ||
Error(), | ||
} | ||
``` | ||
|
||
<br> | ||
Can be also used through command-line interface (CLI), as `block-explorer-cli` and just passing the network: Regtest, Signet, Testnet and Mainnet. | ||
|
||
> **NOTE**: The previous implemented track-address feature and other data, such as: mempool-blocks, stats... has been deprecated and it's not refactored yet. | ||
## Requirements: | ||
|
||
To use this CLI you must have rust and cargo installed in your computer, you can check it with: | ||
To use the library as CLI or to contribute you must have rust and cargo installed in your computer, you can check it with: | ||
|
||
``` sh | ||
# check rust version, it should return its version if installed | ||
rustc --version | ||
# check cargo version, it should return its version if installed | ||
cargo --version | ||
``` | ||
|
||
If you do not have it installed, you can follow this tutorial from [The Rust Programming Language book](https://doc.rust-lang.org/book/ch01-01-installation.html) | ||
|
||
|
||
<br> | ||
|
||
## How to use: | ||
|
||
If you have cargo and rust installed, you can run the following commands: | ||
|
||
## Compiling and using the CLI: | ||
To compile and use it as a command in terminal with no need of cargo, you can use the following command: | ||
``` sh | ||
# mainnet connection is default | ||
cargo run -- track-address -a <your-btc-address> | ||
|
||
# to use testnet | ||
cargo run -- --endpoint mempool.space/testnet/api track-address -a <your-btc-address> | ||
# from inside this repo | ||
cargo install --path . | ||
``` | ||
|
||
## Examples: | ||
### Consuming new block events through the CLI: | ||
``` sh | ||
# all feed [blocks, mempool-blocks, live-2h-chart, and stats] for mainnet: | ||
cargo run -- blocks-data | ||
|
||
# or all feed [blocks, mempool-blocks, live-2h-chart, and stats] for testnet: | ||
cargo run -- --endpoint mempool.space/testnet/api blocks-data | ||
``` | ||
# testnet connection is set by default | ||
cargo run -- data-stream --blocks | ||
|
||
## Compiling and using: | ||
To compile and use it as a command in terminal with no need of cargo, you can use the following command: | ||
|
||
``` sh | ||
cargo install --path . | ||
# to use regtest, you need to pass it as a parameter | ||
cargo run -- --network testnet data-stream --blocks | ||
``` | ||
### Subscribing and consuming new block events through the lib: | ||
``` rust | ||
use anyhow::{self, Ok}; | ||
use bitcoin::Network; | ||
use block_events::{fetch_data_stream, BlockEvent, MempoolSpaceWebSocketRequestData}; | ||
use futures_util::{ pin_mut, StreamExt}; | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
// for regtest network | ||
let network = Network::Regtest; | ||
// for new blocks events | ||
let blocks_data = MempoolSpaceWebSocketRequestData::Blocks; | ||
// async fetch the data stream through the lib | ||
let block_events_stream = fetch_data_stream(&network, &blocks_data).await?; | ||
|
||
// consume and execute the code (current matching and printing) in async manner for each new block-event | ||
pin_mut!(block_events_stream); | ||
while let Some(block_event) = block_events_stream.next().await { | ||
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"); | ||
} | ||
} | ||
}; | ||
Ok(()) | ||
} | ||
``` |
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,19 +1,16 @@ | ||
use bitcoin::{Address, Network}; | ||
use block_explorer_cli::BlockEvent; | ||
use block_explorer_cli::{fetch_data_stream, MempoolSpaceWebSocketRequestData}; | ||
use block_events::{fetch_data_stream, BlockEvent, MempoolSpaceWebSocketRequestData}; | ||
use clap::{ArgGroup, Parser, Subcommand}; | ||
use futures_util::pin_mut; | ||
use futures_util::StreamExt; | ||
use futures_util::{pin_mut, StreamExt}; | ||
use serde::{Deserialize, Serialize}; | ||
use std::str::FromStr; | ||
|
||
#[derive(Parser)] | ||
#[clap(name = "CLI block explorer with mempool.space websocket - WIP")] | ||
#[clap(author = "Leonardo L.")] | ||
#[clap(version = "0.1")] | ||
#[clap(about = "A work in progress CLI block explorer to be used with BDK, consuming data from mempool.space websocket.\n | ||
This an initial competency test for Summer of Bitcoin 2022", | ||
long_about = None)] | ||
#[clap(name = "block-events-cli")] | ||
#[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.")] | ||
|
||
struct Cli { | ||
#[clap(subcommand)] | ||
|
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
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