Skip to content

Commit

Permalink
Merge pull request #7284 from alvasw/BtcWalletV2_Implement_addMiningF…
Browse files Browse the repository at this point in the history
…eesToBsqTx

BtcWalletV2: Implement addMiningFeesToBsqTx
  • Loading branch information
alejandrogarcia83 authored Nov 8, 2024
2 parents a59939d + fbebdb7 commit 6886161
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions core/src/main/java/bisq/core/btc/wallet/BtcWalletV2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package bisq.core.btc.wallet;

import org.bitcoinj.core.Coin;
import org.bitcoinj.core.InsufficientMoneyException;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.wallet.CoinSelector;
import org.bitcoinj.wallet.SendRequest;
import org.bitcoinj.wallet.Wallet;

public class BtcWalletV2 {
private final CoinSelector coinSelector;
private final Wallet wallet;

public BtcWalletV2(CoinSelector coinSelector, Wallet wallet) {
this.coinSelector = coinSelector;
this.wallet = wallet;
}

public Transaction addMiningFeesToBsqTx(Transaction bsqTx, Coin txFee) throws InsufficientMoneyException {
int signOffset = bsqTx.getInputs().size();

SendRequest sendRequest = SendRequest.forTx(bsqTx);
sendRequest.ensureMinRequiredFee = true;
sendRequest.feePerKb = txFee;
sendRequest.shuffleOutputs = false;
sendRequest.signInputs = false;
sendRequest.coinSelector = coinSelector;

wallet.completeTx(sendRequest);

Transaction finalTx = sendRequest.tx;
BisqTransactionSigner.sign(wallet, finalTx, signOffset);
return finalTx;
}
}

0 comments on commit 6886161

Please sign in to comment.