Skip to content

Commit

Permalink
chore: update experimental utxo selection
Browse files Browse the repository at this point in the history
  • Loading branch information
HinsonSIDAN committed Aug 27, 2024
1 parent f91842a commit 7a6acdf
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/mesh-common/src/utxo-selection/experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ export const experimentalSelectUtxos = (
const singletons = new Set<number>();
const pairs = new Set<number>();
const rest = new Set<number>();
const collaterals = new Set<number>();
for (let i = 0; i < inputs.length; i++) {
switch (inputs[i]!.output.amount.length) {
case 1: {
const quantity = inputs[i]!.output.amount[0]?.quantity;
if (quantity == "5000000" || quantity == "10000000") {
collaterals.add(i);
break;
}
onlyLovelace.add(i);
break;
}
Expand Down Expand Up @@ -111,6 +117,12 @@ export const experimentalSelectUtxos = (
addUtxoWithAssetAmount(inputIndex, "lovelace", rest);
}

for (const inputIndex of collaterals) {
const assetRequired = totalRequiredAssets.get("lovelace");
if (!assetRequired || Number(assetRequired) <= 0) break;
addUtxoWithAssetAmount(inputIndex, "lovelace", collaterals);
}

for (const assetUnit of totalRequiredAssets.keys()) {
if (Number(totalRequiredAssets.get(assetUnit)) > 0) {
console.warn("Insufficient funds for", assetUnit);
Expand Down

0 comments on commit 7a6acdf

Please sign in to comment.