Skip to content

Commit

Permalink
Moved input adding and output value calculation under the same loop
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszslabon committed Sep 27, 2023
1 parent 770032c commit 039b2a9
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions typescript/src/deposit-sweep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,33 +160,25 @@ export async function assembleDepositSweepTransaction(
witness
)

let outputValue = BigNumber.from(0)
if (mainUtxo) {
outputValue = outputValue.add(mainUtxo.value)
}
for (const utxo of utxos) {
outputValue = outputValue.add(utxo.value)
}
outputValue = outputValue.sub(fee)

// Create the transaction.
const transaction = new Transaction()

// Add the transaction's inputs.
let outputValue = BigNumber.from(0)
if (mainUtxo) {
transaction.addInput(
mainUtxo.transactionHash.reverse().toBuffer(),
mainUtxo.outputIndex
)
outputValue = outputValue.add(mainUtxo.value)
}
for (const utxo of utxos) {
transaction.addInput(
utxo.transactionHash.reverse().toBuffer(),
utxo.outputIndex
)
outputValue = outputValue.add(utxo.value)
}
outputValue = outputValue.sub(fee)

// Add transaction output.
const scriptPubKey = address.toOutputScript(walletAddress, network)
transaction.addOutput(scriptPubKey, outputValue.toNumber())

Expand Down

0 comments on commit 039b2a9

Please sign in to comment.