Skip to content

Commit

Permalink
Rename and add explanatory comment
Browse files Browse the repository at this point in the history
  • Loading branch information
julia-zack committed Jan 9, 2025
1 parent e35f590 commit 44b47b5
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -1370,42 +1370,47 @@ private Coin getPegoutRequestedAmount(BtcTransaction pegoutTransaction) {
totalAmount = totalAmount.add(input.getValue());
}

TransactionOutput changeOutput = pegoutTransaction.getOutput(pegoutTransaction.getOutputs().size() - 1);
int changeOutputIndex = pegoutTransaction.getOutputs().size() - 1;
TransactionOutput changeOutput = pegoutTransaction.getOutput(changeOutputIndex);
Coin changeOutputAmount = changeOutput.getValue();
// since the user pays for the pegout fees, the actual amount
// being sent is different from the requested amount,
// that is the total amount from used inputs, minus the change output
return totalAmount.minus(changeOutputAmount);
}

private void settleMigrationRelease(PegoutsWaitingForConfirmations pegoutsWaitingForConfirmations, BtcTransaction migrationTransaction, Keccak256 migrationCreationTxHash) {
Coin requestedAmount = getMigrationRequestedAmount(migrationTransaction);
Coin amountToMigrate = amountToMigrate(migrationTransaction);
List<UTXO> utxosToUse = federationSupport.getRetiringFederationBtcUTXOs();

settleReleaseRequest(utxosToUse, pegoutsWaitingForConfirmations, migrationTransaction, migrationCreationTxHash, requestedAmount);
settleReleaseRequest(utxosToUse, pegoutsWaitingForConfirmations, migrationTransaction, migrationCreationTxHash, amountToMigrate);
}

private Coin getMigrationRequestedAmount(BtcTransaction migrationTransaction) {
Coin requestedAmount = Coin.ZERO;
private Coin amountToMigrate(BtcTransaction migrationTransaction) {
Coin amountToMigrate = Coin.ZERO;
for (int i = 0; i < migrationTransaction.getInputs().size(); i ++) {
TransactionInput input = migrationTransaction.getInput(i);
requestedAmount = requestedAmount.add(input.getValue());
amountToMigrate = amountToMigrate.add(input.getValue());
}

return requestedAmount;
return amountToMigrate;
}

private void settleSvpFundTransactionRelease(PegoutsWaitingForConfirmations pegoutsWaitingForConfirmations, BtcTransaction svpFundTransaction, Keccak256 svpFundCreationTxHash) {
List<UTXO> utxosToUse = federationSupport.getActiveFederationBtcUTXOs();
Coin requestedAmount = getSvpFundTxRequestedAmount(svpFundTransaction);
settleReleaseRequest(utxosToUse, pegoutsWaitingForConfirmations, svpFundTransaction, svpFundCreationTxHash, requestedAmount);
Coin svpFundTxSentAmount = getSvpFundTxSentAmount(svpFundTransaction);

settleReleaseRequest(utxosToUse, pegoutsWaitingForConfirmations, svpFundTransaction, svpFundCreationTxHash, svpFundTxSentAmount);
}

private Coin getSvpFundTxRequestedAmount(BtcTransaction svpFundTransaction) {
Coin requestedAmount = Coin.ZERO;
private Coin getSvpFundTxSentAmount(BtcTransaction svpFundTransaction) {
Coin svpFundTxSentAmount = Coin.ZERO;
for (int i = 0; i < svpFundTransaction.getOutputs().size() - 1; i ++) {
TransactionOutput output = svpFundTransaction.getOutput(i);
requestedAmount = requestedAmount.add(output.getValue());
svpFundTxSentAmount = svpFundTxSentAmount.add(output.getValue());
}

return requestedAmount;
return svpFundTxSentAmount;
}

private void settleReleaseRequest(List<UTXO> utxosToUse, PegoutsWaitingForConfirmations pegoutsWaitingForConfirmations, BtcTransaction releaseTransaction, Keccak256 releaseCreationTxHash, Coin requestedAmount) {
Expand Down

0 comments on commit 44b47b5

Please sign in to comment.