pub struct BatchOptimizer { /* private fields */ }Expand description
Batch optimizer
Optimizes batch withdrawals to minimize fees and transaction count.
§Examples
use kaccy_bitcoin::{BatchOptimizer, BatchWithdrawal, BatchStrategy};
let optimizer = BatchOptimizer::default();
let withdrawals = vec![
BatchWithdrawal {
user_id: "user1".to_string(),
address: "bc1qaddr1".to_string(),
amount_sats: 50_000,
priority: 1,
},
BatchWithdrawal {
user_id: "user2".to_string(),
address: "bc1qaddr2".to_string(),
amount_sats: 75_000,
priority: 1,
},
];
let optimized = optimizer.optimize(withdrawals, BatchStrategy::MinimizeFees)?;
println!("Fee savings: {} sats", optimized.estimated_savings);Implementations§
Source§impl BatchOptimizer
impl BatchOptimizer
Sourcepub fn new(
max_outputs_per_tx: usize,
min_batch_size: usize,
fee_rate: f64,
) -> Self
pub fn new( max_outputs_per_tx: usize, min_batch_size: usize, fee_rate: f64, ) -> Self
Create a new batch optimizer
§Examples
use kaccy_bitcoin::BatchOptimizer;
let optimizer = BatchOptimizer::new(
100, // max outputs per tx
2, // min batch size
10.0, // fee rate sat/vB
);Sourcepub fn optimize(
&self,
withdrawals: Vec<BatchWithdrawal>,
strategy: BatchStrategy,
) -> Result<OptimizedBatch>
pub fn optimize( &self, withdrawals: Vec<BatchWithdrawal>, strategy: BatchStrategy, ) -> Result<OptimizedBatch>
Optimize a batch of withdrawals
Sourcepub fn group_by_user(
withdrawals: Vec<BatchWithdrawal>,
) -> HashMap<String, Vec<BatchWithdrawal>>
pub fn group_by_user( withdrawals: Vec<BatchWithdrawal>, ) -> HashMap<String, Vec<BatchWithdrawal>>
Group withdrawals by user
Sourcepub fn analyze_efficiency(&self, batches: &OptimizedBatch) -> BatchEfficiency
pub fn analyze_efficiency(&self, batches: &OptimizedBatch) -> BatchEfficiency
Analyze batch efficiency
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BatchOptimizer
impl RefUnwindSafe for BatchOptimizer
impl Send for BatchOptimizer
impl Sync for BatchOptimizer
impl Unpin for BatchOptimizer
impl UnwindSafe for BatchOptimizer
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
Mutably borrows from an owned value. Read more