Skip to content

Commit

Permalink
add JSDoc to qi hdwallet methods
Browse files Browse the repository at this point in the history
  • Loading branch information
alejoacosta74 authored and rileystephens28 committed Nov 27, 2024
1 parent 880aa69 commit 7856d47
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
17 changes: 0 additions & 17 deletions src/transaction/abstract-coinselector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export interface CoinSelectionConfig {
target?: bigint;
fee?: bigint;
includeLocked?: boolean;
maxDenomination?: number;
// Any future parameters can be added here
}

Expand Down Expand Up @@ -114,20 +113,4 @@ export abstract class AbstractCoinSelector {
throw new Error('No UTXOs available');
}
}

/**
* Sorts UTXOs by their denomination.
*
* @param {UTXO[]} utxos - The UTXOs to sort.
* @param {'asc' | 'desc'} order - The direction to sort ('asc' for ascending, 'desc' for descending).
* @returns {UTXO[]} The sorted UTXOs.
*/
protected sortUTXOsByDenomination(utxos: UTXO[], order: 'asc' | 'desc' = 'asc'): UTXO[] {
return [...utxos].sort((a, b) => {
const aValue = BigInt(a.denomination !== null ? denominations[a.denomination] : 0);
const bValue = BigInt(b.denomination !== null ? denominations[b.denomination] : 0);
const diff = order === 'asc' ? aValue - bValue : bValue - aValue;
return diff > BigInt(0) ? 1 : diff < BigInt(0) ? -1 : 0;
});
}
}
24 changes: 24 additions & 0 deletions src/transaction/coinselector-fewest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,28 @@ export class FewestCoinSelector extends AbstractCoinSelector {

this.changeOutputs = this.createChangeOutputs(changeAmount);
}

/**
* Sorts UTXOs by their denomination.
*
* @param {UTXO[]} utxos - The UTXOs to sort.
* @param {'asc' | 'desc'} direction - The direction to sort ('asc' for ascending, 'desc' for descending).
* @returns {UTXO[]} The sorted UTXOs.
*/
private sortUTXOsByDenomination(utxos: UTXO[], direction: 'asc' | 'desc'): UTXO[] {
if (direction === 'asc') {
return [...utxos].sort((a, b) => {
const diff =
BigInt(a.denomination !== null ? denominations[a.denomination] : 0) -
BigInt(b.denomination !== null ? denominations[b.denomination] : 0);
return diff > BigInt(0) ? 1 : diff < BigInt(0) ? -1 : 0;
});
}
return [...utxos].sort((a, b) => {
const diff =
BigInt(b.denomination !== null ? denominations[b.denomination] : 0) -
BigInt(a.denomination !== null ? denominations[a.denomination] : 0);
return diff > BigInt(0) ? 1 : diff < BigInt(0) ? -1 : 0;
});
}
}

0 comments on commit 7856d47

Please sign in to comment.