pub struct BatchAddressGenerator { /* private fields */ }Expand description
Batch address generator for efficient address generation.
BatchAddressGenerator provides a high-performance API for generating
large batches of addresses with parallel processing and streaming output.
§Example
use rustywallet_batch::address::{BatchAddressGenerator, BatchAddressType};
use rustywallet_address::Network;
// Create generator for P2WPKH addresses on mainnet
let generator = BatchAddressGenerator::new(BatchAddressType::P2WPKH, Network::BitcoinMainnet);
// Generate 100 addresses as a vector
let addresses = generator.generate_vec(100).unwrap();
assert_eq!(addresses.len(), 100);
// Or stream addresses for memory efficiency
for (key, addr) in generator.generate_stream(1000).take(10) {
println!("{}: {}", key.to_hex(), addr);
}Implementations§
Source§impl BatchAddressGenerator
impl BatchAddressGenerator
Sourcepub fn new(address_type: BatchAddressType, network: Network) -> Self
pub fn new(address_type: BatchAddressType, network: Network) -> Self
Create a new batch address generator.
§Arguments
address_type- The type of addresses to generate (P2PKH, P2WPKH, P2TR)network- The Bitcoin network (mainnet or testnet)
§Example
use rustywallet_batch::address::{BatchAddressGenerator, BatchAddressType};
use rustywallet_address::Network;
let generator = BatchAddressGenerator::new(BatchAddressType::P2TR, Network::BitcoinMainnet);Sourcepub fn parallel(self, enabled: bool) -> Self
pub fn parallel(self, enabled: bool) -> Self
Enable or disable parallel processing.
Parallel processing is enabled by default for better performance.
Sourcepub fn chunk_size(self, size: usize) -> Self
pub fn chunk_size(self, size: usize) -> Self
Set the chunk size for streaming operations.
Larger chunks improve throughput but use more memory. Default is 1000.
Sourcepub fn address_type(&self) -> BatchAddressType
pub fn address_type(&self) -> BatchAddressType
Get the address type.
Sourcepub fn generate_stream(&self, count: usize) -> AddressStream ⓘ
pub fn generate_stream(&self, count: usize) -> AddressStream ⓘ
Generate addresses as a streaming iterator.
This method returns an iterator that generates key-address pairs on-demand, allowing processing of millions of addresses without memory exhaustion.
§Arguments
count- The number of addresses to generate
§Example
use rustywallet_batch::address::{BatchAddressGenerator, BatchAddressType};
use rustywallet_address::Network;
let generator = BatchAddressGenerator::new(BatchAddressType::P2WPKH, Network::BitcoinMainnet);
// Stream 1 million addresses without storing all in memory
for (key, addr) in generator.generate_stream(1_000_000).take(100) {
println!("{}", addr);
}Sourcepub fn generate_vec(
&self,
count: usize,
) -> Result<Vec<(PrivateKey, String)>, BatchError>
pub fn generate_vec( &self, count: usize, ) -> Result<Vec<(PrivateKey, String)>, BatchError>
Generate addresses and collect them into a vector.
This method generates all addresses and stores them in memory.
For large batches, consider using generate_stream() for streaming.
§Arguments
count- The number of addresses to generate
§Example
use rustywallet_batch::address::{BatchAddressGenerator, BatchAddressType};
use rustywallet_address::Network;
let generator = BatchAddressGenerator::new(BatchAddressType::P2PKH, Network::BitcoinMainnet);
let addresses = generator.generate_vec(1000).unwrap();
for (key, addr) in &addresses {
assert!(addr.starts_with('1'));
}Trait Implementations§
Source§impl Clone for BatchAddressGenerator
impl Clone for BatchAddressGenerator
Source§fn clone(&self) -> BatchAddressGenerator
fn clone(&self) -> BatchAddressGenerator
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BatchAddressGenerator
impl RefUnwindSafe for BatchAddressGenerator
impl Send for BatchAddressGenerator
impl Sync for BatchAddressGenerator
impl Unpin for BatchAddressGenerator
impl UnwindSafe for BatchAddressGenerator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more