Merge pull request #7284 from alvasw/BtcWalletV2_Implement_addMiningFeesToBsqTx

BtcWalletV2: Implement addMiningFeesToBsqTx
This commit is contained in:
Alejandro García 2024-11-08 02:58:25 +00:00 committed by GitHub
commit 6886161b48
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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;
}
}