rustywallet_mempool/
lib.rs

1//! # rustywallet-mempool
2//!
3//! Mempool.space API client for fee estimation, address info, and transaction tracking.
4//!
5//! ## Features
6//!
7//! - **Fee estimation** - Get recommended fee rates for different confirmation targets
8//! - **Address info** - Get balance, transaction count, and UTXOs
9//! - **Transaction tracking** - Get transaction details and confirmation status
10//! - **Broadcasting** - Broadcast signed transactions to the network
11//! - **Block info** - Get current block height and block details
12//! - **WebSocket support** - Real-time updates for blocks, fees, and addresses
13//! - **Lightning stats** - Lightning Network capacity, nodes, and channels
14//! - **Mining stats** - Pool hashrate distribution and difficulty adjustments
15//!
16//! ## Quick Start
17//!
18//! ```no_run
19//! use rustywallet_mempool::MempoolClient;
20//!
21//! #[tokio::main]
22//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
23//!     let client = MempoolClient::new();
24//!     
25//!     // Get fee estimates
26//!     let fees = client.get_fees().await?;
27//!     println!("Next block: {} sat/vB", fees.fastest_fee);
28//!     println!("1 hour: {} sat/vB", fees.hour_fee);
29//!     println!("Economy: {} sat/vB", fees.economy_fee);
30//!     
31//!     // Get address balance
32//!     let info = client.get_address("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa").await?;
33//!     println!("Balance: {} sats", info.confirmed_balance());
34//!     println!("Transactions: {}", info.tx_count());
35//!     
36//!     // Get UTXOs
37//!     let utxos = client.get_utxos("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa").await?;
38//!     println!("UTXOs: {}", utxos.len());
39//!     
40//!     // Get current block height
41//!     let height = client.get_block_height().await?;
42//!     println!("Block height: {}", height);
43//!     
44//!     Ok(())
45//! }
46//! ```
47//!
48//! ## WebSocket Real-time Updates
49//!
50//! ```no_run
51//! use rustywallet_mempool::websocket::{MempoolWsClient, WsSubscription};
52//!
53//! #[tokio::main]
54//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
55//!     let ws = MempoolWsClient::new();
56//!     
57//!     // Configure subscriptions
58//!     let sub = WsSubscription::new()
59//!         .with_blocks()
60//!         .with_fees()
61//!         .track_address("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa");
62//!     
63//!     ws.set_subscription(sub).await;
64//!     
65//!     Ok(())
66//! }
67//! ```
68//!
69//! ## Lightning Network Stats
70//!
71//! ```no_run
72//! use rustywallet_mempool::MempoolClient;
73//!
74//! #[tokio::main]
75//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
76//!     let client = MempoolClient::new();
77//!     
78//!     // Get Lightning Network statistics
79//!     let stats = client.get_lightning_stats().await?;
80//!     println!("Capacity: {} BTC", stats.latest.capacity_btc());
81//!     println!("Channels: {}", stats.latest.channel_count);
82//!     println!("Nodes: {}", stats.latest.node_count);
83//!     
84//!     Ok(())
85//! }
86//! ```
87//!
88//! ## Mining Pool Stats
89//!
90//! ```no_run
91//! use rustywallet_mempool::MempoolClient;
92//!
93//! #[tokio::main]
94//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
95//!     let client = MempoolClient::new();
96//!     
97//!     // Get hashrate distribution
98//!     let dist = client.get_hashrate_distribution("1w").await?;
99//!     for pool in dist.top_pools(5) {
100//!         println!("{}: {:.1}%", pool.pool.name, pool.share_percent());
101//!     }
102//!     
103//!     // Get difficulty adjustment
104//!     let adj = client.get_difficulty_adjustment().await?;
105//!     println!("Next adjustment: {:.2}%", adj.difficulty_change_percent());
106//!     
107//!     Ok(())
108//! }
109//! ```
110//!
111//! ## Networks
112//!
113//! ```no_run
114//! use rustywallet_mempool::MempoolClient;
115//!
116//! // Mainnet (default)
117//! let mainnet = MempoolClient::new();
118//!
119//! // Testnet
120//! let testnet = MempoolClient::testnet();
121//!
122//! // Signet
123//! let signet = MempoolClient::signet();
124//!
125//! // Custom endpoint
126//! let custom = MempoolClient::with_base_url("https://my-mempool.example.com/api");
127//! ```
128
129#![warn(missing_docs)]
130#![warn(rustdoc::missing_crate_level_docs)]
131
132pub mod client;
133pub mod error;
134pub mod lightning;
135pub mod mining;
136pub mod types;
137pub mod websocket;
138
139// Re-exports
140pub use client::{MempoolClient, MAINNET_URL, SIGNET_URL, TESTNET_URL};
141pub use error::{MempoolError, Result};
142pub use types::{AddressInfo, BlockInfo, ChainStats, FeeEstimates, MempoolStats, Transaction, TxStatus, Utxo, UtxoStatus};
143
144// v0.2 re-exports
145pub use lightning::{LightningChannel, LightningNode, LightningNetworkStats, LightningStats};
146pub use mining::{BlockRewardStats, DifficultyAdjustment, HashrateDistribution, MiningPoolStats, PoolBlock, PoolInfo};
147pub use websocket::{
148    AddressTxEvent, BlockEvent, MempoolInfoEvent, MempoolWsClient, TxConfirmedEvent,
149    WsConnectionStatus, WsEvent, WsSubscription, WsSubscriptionBuilder,
150    MAINNET_WS_URL, TESTNET_WS_URL, SIGNET_WS_URL,
151};