diff --git a/src/transaction/abstract-coinselector.ts b/src/transaction/abstract-coinselector.ts index 51d148fb..d825a099 100644 --- a/src/transaction/abstract-coinselector.ts +++ b/src/transaction/abstract-coinselector.ts @@ -41,7 +41,6 @@ export interface CoinSelectionConfig { target?: bigint; fee?: bigint; includeLocked?: boolean; - maxDenomination?: number; // Any future parameters can be added here } @@ -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; - }); - } } diff --git a/src/transaction/coinselector-fewest.ts b/src/transaction/coinselector-fewest.ts index 6e27ff82..21c12747 100644 --- a/src/transaction/coinselector-fewest.ts +++ b/src/transaction/coinselector-fewest.ts @@ -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; + }); + } }