Skip to main content
Optimizes wallet leaf structure by consolidating or splitting leaves. This is an async generator that yields progress updates.

Method Signature

async *optimizeLeaves(
  multiplicity?: number
): AsyncGenerator<{
  step: number;
  total: number;
  controller: AbortController;
}>

Parameters

multiplicity
number
Optimization multiplicity (0-5, default from config)

Yields

progress
object
required
Progress object containing:
  • step: Current step number
  • total: Total number of steps
  • controller: AbortController to cancel optimization

Example

for await (const progress of wallet.optimizeLeaves()) {
  console.log(`Step ${progress.step} of ${progress.total}`);
  
  // Cancel if needed
  if (shouldCancel) {
    progress.controller.abort();
    break;
  }
}
console.log("Optimization complete");