-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create new conversion tx coin selector class and add few minor optimi…
…zations to syncing logic
- Loading branch information
1 parent
3a82e85
commit 06e9688
Showing
3 changed files
with
82 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { FewestCoinSelector } from './coinselector-fewest.js'; | ||
import { UTXO, denominate, denominations } from './utxo.js'; | ||
|
||
/** | ||
* The ConversionSelector class provides a coin selection algorithm that selects the fewest UTXOs required to meet the | ||
* target amount. This algorithm is useful for minimizing the size of the transaction and the fees associated with it. | ||
* | ||
* This class is a modified version of {@link FewestCoinSelector | **FewestCoinSelector** } and implements the | ||
* {@link FewestCoinSelector.createSpendOutputs | **createSpendOutputs** } method to provide the actual coin selection | ||
* logic. | ||
* | ||
* @category Transaction | ||
*/ | ||
export class ConversionCoinSelector extends FewestCoinSelector { | ||
/** | ||
* Creates spend outputs based on the target amount and input denominations. | ||
* | ||
* @param {bigint} amount - The target amount to spend. | ||
* @returns {UTXO[]} The spend outputs. | ||
*/ | ||
protected override createSpendOutputs(amount: bigint): UTXO[] { | ||
// Spend outpoints are not limited to max input denomination | ||
const spendDenominations = denominate(amount); | ||
|
||
return spendDenominations.map((denominationValue) => { | ||
const utxo = new UTXO(); | ||
utxo.denomination = denominations.indexOf(denominationValue); | ||
return utxo; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters