Skip to content

Commit

Permalink
Merge pull request #1605 from IntersectMBO/fix/add-change-config-for-…
Browse files Browse the repository at this point in the history
…inputs-selection

fix(wallet): fix inputs selection with the change config
  • Loading branch information
MSzalowski authored Jul 29, 2024
2 parents 8174a9f + 96fc496 commit 71412e0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ changes.

- Fix querying metadata-validation service from haskell backend [Issue 1612](https://github.com/IntersectMBO/govtool/issues/1612)
- Fix thread killed by timeout manager [Issue 1417](https://github.com/IntersectMBO/govtool/issues/1417)
- Changed use new CSL UTxO selection to take into account change

### Changed

Expand Down
17 changes: 12 additions & 5 deletions govtool/frontend/src/context/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
GovernanceAction,
TreasuryWithdrawals,
TreasuryWithdrawalsAction,
ChangeConfig,
} from "@emurgo/cardano-serialization-lib-asmjs";
import { Buffer } from "buffer";
import { useNavigate } from "react-router-dom";
Expand Down Expand Up @@ -524,17 +525,23 @@ const CardanoProvider = (props: Props) => {
const txUnspentOutputs = await getTxUnspentOutputs(utxos);

// Use UTxO selection strategy 3
const changeConfig = ChangeConfig.new(shelleyChangeAddress);
try {
txBuilder.add_inputs_from(txUnspentOutputs, 3);
txBuilder.add_inputs_from_and_change(
txUnspentOutputs,
3,
changeConfig,
);
} catch (e) {
console.error(e);
// Use UTxO selection strategy 2 if strategy 3 fails
txBuilder.add_inputs_from(txUnspentOutputs, 2);
txBuilder.add_inputs_from_and_change(
txUnspentOutputs,
2,
changeConfig,
);
}

// Set change address, incase too much ADA provided for fee
txBuilder.add_change_if_needed(shelleyChangeAddress);

// Build transaction body
const txBody = txBuilder.build();

Expand Down

0 comments on commit 71412e0

Please sign in to comment.