rustywallet_batch/lib.rs
1//! # rustywallet-batch
2//!
3//! High-performance batch key and address generation for cryptocurrency wallets.
4//!
5//! This crate provides efficient APIs for generating large batches of private keys
6//! and addresses with parallel processing, SIMD optimization, and memory-efficient streaming.
7//!
8//! ## Features
9//!
10//! - **Batch Generation**: Generate millions of keys and addresses efficiently
11//! - **Address Generation**: Support for P2PKH, P2WPKH, and P2TR address types
12//! - **Parallel Processing**: Utilize all CPU cores with rayon
13//! - **Memory Streaming**: Process unlimited keys/addresses without memory exhaustion
14//! - **Incremental Scanning**: Scan key ranges using EC point addition
15//! - **SIMD Optimization**: Use SIMD instructions for faster processing
16//! - **Memory-Mapped Output**: Write directly to files without buffering
17//! - **Resume Capability**: Checkpoint and resume long-running operations
18//! - **Configurable**: Flexible configuration for different use cases
19//!
20//! ## Batch Address Generation
21//!
22//! ```rust
23//! use rustywallet_batch::address::{BatchAddressGenerator, BatchAddressType};
24//! use rustywallet_address::Network;
25//!
26//! // Generate 1000 P2WPKH addresses in parallel
27//! let generator = BatchAddressGenerator::new(BatchAddressType::P2WPKH, Network::BitcoinMainnet);
28//! let addresses = generator.generate_vec(1000).unwrap();
29//!
30//! println!("Generated {} addresses", addresses.len());
31//!
32//! // Stream addresses for memory efficiency
33//! for (key, addr) in generator.generate_stream(1_000_000).take(100) {
34//! println!("{}: {}", key.to_hex(), addr);
35//! }
36//! ```
37//!
38//! ## Quick Start
39//!
40//! ```rust
41//! use rustywallet_batch::prelude::*;
42//!
43//! // Generate 1000 keys in parallel
44//! let keys = BatchGenerator::new()
45//! .count(1000)
46//! .parallel()
47//! .generate_vec()
48//! .unwrap();
49//!
50//! println!("Generated {} keys", keys.len());
51//! ```
52//!
53//! ## Streaming Large Batches
54//!
55//! ```rust
56//! use rustywallet_batch::prelude::*;
57//!
58//! // Stream keys without storing all in memory
59//! let stream = BatchGenerator::new()
60//! .count(1_000_000)
61//! .generate()
62//! .unwrap();
63//!
64//! for key in stream.take(100) {
65//! println!("{}", key.unwrap().to_hex());
66//! }
67//! ```
68//!
69//! ## Memory-Mapped File Output
70//!
71//! ```no_run
72//! use rustywallet_batch::mmap::{MmapBatchGenerator, OutputFormat};
73//!
74//! // Generate keys directly to file
75//! let count = MmapBatchGenerator::new("keys.txt", 1_000_000)
76//! .format(OutputFormat::Hex)
77//! .parallel(true)
78//! .generate()
79//! .unwrap();
80//!
81//! println!("Generated {} keys to file", count);
82//! ```
83//!
84//! ## Resumable Generation
85//!
86//! ```no_run
87//! use rustywallet_batch::checkpoint::ResumableBatchGenerator;
88//!
89//! // Start or resume generation with checkpoints
90//! let mut generator = ResumableBatchGenerator::new(
91//! "my-job",
92//! 10_000_000,
93//! "keys.txt",
94//! "checkpoint.json",
95//! );
96//!
97//! generator.generate_with_progress(|progress| {
98//! println!("Progress: {:.1}%", progress);
99//! }).unwrap();
100//! ```
101//!
102//! ## SIMD Optimization
103//!
104//! ```rust
105//! use rustywallet_batch::simd::SimdBatchProcessor;
106//!
107//! // Check SIMD availability
108//! println!("SIMD: {} ({})",
109//! SimdBatchProcessor::is_available(),
110//! SimdBatchProcessor::feature_name()
111//! );
112//!
113//! // Generate with SIMD optimization
114//! let processor = SimdBatchProcessor::new();
115//! let keys = processor.parallel_generate(10_000);
116//! ```
117//!
118//! ## Incremental Key Scanning
119//!
120//! ```rust
121//! use rustywallet_batch::prelude::*;
122//! use rustywallet_keys::prelude::PrivateKey;
123//!
124//! // Scan from a base key
125//! let base = PrivateKey::from_hex(
126//! "0000000000000000000000000000000000000000000000000000000000000001"
127//! ).unwrap();
128//!
129//! let scanner = KeyScanner::new(base)
130//! .direction(ScanDirection::Forward);
131//!
132//! for key in scanner.scan_range(10) {
133//! println!("{}", key.unwrap().to_hex());
134//! }
135//! ```
136//!
137//! ## Configuration Presets
138//!
139//! ```rust
140//! use rustywallet_batch::prelude::*;
141//!
142//! // Fast mode - maximum speed
143//! let config = BatchConfig::fast();
144//!
145//! // Balanced mode - good speed with reasonable memory
146//! let config = BatchConfig::balanced();
147//!
148//! // Memory efficient - minimal memory usage
149//! let config = BatchConfig::memory_efficient();
150//! ```
151
152pub mod address;
153pub mod checkpoint;
154pub mod config;
155pub mod error;
156pub mod fast_gen;
157pub mod generator;
158pub mod mmap;
159pub mod prelude;
160pub mod scanner;
161pub mod simd;
162pub mod stream;
163
164#[cfg(test)]
165mod tests;
166
167// Re-export main types at crate root
168pub use address::{AddressStream, BatchAddressGenerator, BatchAddressType};
169pub use checkpoint::{Checkpoint, GenerationMode, ResumableBatchGenerator};
170pub use config::BatchConfig;
171pub use error::BatchError;
172pub use fast_gen::{FastKeyGenerator, IncrementalKeyGenerator};
173pub use generator::BatchGenerator;
174pub use mmap::{MmapBatchGenerator, MmapWriter, OutputFormat};
175pub use scanner::{KeyScanner, ScanDirection};
176pub use simd::SimdBatchProcessor;
177pub use stream::KeyStream;