Skip to content

Commit

Permalink
do not double add collateral
Browse files Browse the repository at this point in the history
  • Loading branch information
micahkendall committed Jan 16, 2024
1 parent 3a1e5c8 commit 3071a79
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/translucent/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,14 +849,8 @@ export class Tx {

const adaInput = walletUTxOs[utxoAdaSearch[utxoAdaSearch.length-1][0]]
this.txBuilder.add_input(C.SingleInputBuilder.new(adaInput.input(), adaInput.output()).payment_key())
for (const utxo of walletUTxOs) {
if (utxo.to_bytes()!=adaInput.to_bytes()){
this.txBuilder.add_utxo(
C.SingleInputBuilder.new(utxo.input(), utxo.output()).payment_key(),
);
};
};

let collateralInput: C.TransactionUnspentOutput
{
let foundUtxo = utxoToCore(walletUTxOs.filter(
(x) =>
Expand All @@ -867,6 +861,7 @@ export class Tx {
if (foundUtxo == undefined) {
throw "Could not find a suitable collateral UTxO.";
} else {
collateralInput = foundUtxo
let collateralUTxO = C.SingleInputBuilder.new(
foundUtxo.input(),
foundUtxo.output(),
Expand All @@ -892,6 +887,14 @@ export class Tx {
}
}

for (const utxo of walletUTxOs) {
if (utxo.to_bytes()!=adaInput.to_bytes() && utxo.to_bytes()!=collateralInput.to_bytes()){
this.txBuilder.add_utxo(
C.SingleInputBuilder.new(utxo.input(), utxo.output()).payment_key(),
);
};
};

this.txBuilder.select_utxos(2);
let txRedeemerBuilder = this.txBuilder.build_for_evaluation(
0,
Expand Down

0 comments on commit 3071a79

Please sign in to comment.