diff --git a/core/src/main/java/bisq/core/api/CoreWalletsService.java b/core/src/main/java/bisq/core/api/CoreWalletsService.java index a4e88578fc9..149a18d655d 100644 --- a/core/src/main/java/bisq/core/api/CoreWalletsService.java +++ b/core/src/main/java/bisq/core/api/CoreWalletsService.java @@ -289,6 +289,7 @@ void sendBtc(String address, // See WithdrawalView # onWithdraw (and refactor). Transaction feeEstimationTransaction = btcWalletService.getFeeEstimationTransactionForMultipleAddresses(fromAddresses, + address, receiverAmount, txFeePerVbyte); if (feeEstimationTransaction == null) diff --git a/core/src/main/java/bisq/core/btc/wallet/BtcWalletService.java b/core/src/main/java/bisq/core/btc/wallet/BtcWalletService.java index 64151d47162..f1c5e7ad01e 100644 --- a/core/src/main/java/bisq/core/btc/wallet/BtcWalletService.java +++ b/core/src/main/java/bisq/core/btc/wallet/BtcWalletService.java @@ -1056,13 +1056,7 @@ public Transaction getFeeEstimationTransaction(String fromAddress, } public Transaction getFeeEstimationTransactionForMultipleAddresses(Set fromAddresses, - Coin amount) - throws AddressFormatException, AddressEntryException, InsufficientFundsException { - Coin txFeeForWithdrawalPerVbyte = getTxFeeForWithdrawalPerVbyte(); - return getFeeEstimationTransactionForMultipleAddresses(fromAddresses, amount, txFeeForWithdrawalPerVbyte); - } - - public Transaction getFeeEstimationTransactionForMultipleAddresses(Set fromAddresses, + String toAddress, Coin amount, Coin txFeeForWithdrawalPerVbyte) throws AddressFormatException, AddressEntryException, InsufficientFundsException { @@ -1090,11 +1084,7 @@ public Transaction getFeeEstimationTransactionForMultipleAddresses(Set f do { counter++; fee = txFeeForWithdrawalPerVbyte.multiply(txVsize); - // We use a dummy address for the output - // We don't know here whether the output is segwit or not but we don't care too much because the size of - // a segwit ouput is just 3 byte smaller than the size of a legacy ouput. - final String dummyReceiver = SegwitAddress.fromKey(params, new ECKey()).toString(); - SendRequest sendRequest = getSendRequestForMultipleAddresses(fromAddresses, dummyReceiver, amount, fee, null, aesKey); + SendRequest sendRequest = getSendRequestForMultipleAddresses(fromAddresses, toAddress, amount, fee, null, aesKey); wallet.completeTx(sendRequest); tx = sendRequest.tx; txVsize = tx.getVsize(); @@ -1113,14 +1103,14 @@ public Transaction getFeeEstimationTransactionForMultipleAddresses(Set f } private boolean feeEstimationNotSatisfied(int counter, Transaction tx) { - return feeEstimationNotSatisfied(counter, tx, getTxFeeForWithdrawalPerVbyte()); + return feeEstimationNotSatisfied(counter, tx.getFee().value, tx.getVsize(), getTxFeeForWithdrawalPerVbyte()); } - private boolean feeEstimationNotSatisfied(int counter, Transaction tx, Coin txFeeForWithdrawalPerVbyte) { - long targetFee = txFeeForWithdrawalPerVbyte.multiply(tx.getVsize()).value; + private boolean feeEstimationNotSatisfied(int counter, long txFee, long txVsize, Coin txFeeForWithdrawalPerVbyte) { + long targetFee = txFeeForWithdrawalPerVbyte.multiply(txVsize).value; + long higherThanTargetFee = txFee - targetFee; return counter < 10 && - (tx.getFee().value < targetFee || - tx.getFee().value - targetFee > 1000); + (txFee < targetFee || higherThanTargetFee > 1000); } public int getEstimatedFeeTxVsize(List outputValues, Coin txFee) diff --git a/desktop/src/main/java/bisq/desktop/main/funds/withdrawal/WithdrawalView.java b/desktop/src/main/java/bisq/desktop/main/funds/withdrawal/WithdrawalView.java index 368b74edaa4..1934b1cc5a2 100644 --- a/desktop/src/main/java/bisq/desktop/main/funds/withdrawal/WithdrawalView.java +++ b/desktop/src/main/java/bisq/desktop/main/funds/withdrawal/WithdrawalView.java @@ -406,9 +406,9 @@ private void onWithdraw() { final Coin sendersAmount; // We do not know sendersAmount if senderPaysFee is true. We repeat fee calculation after first attempt if senderPaysFee is true. - Transaction feeEstimationTransaction = btcWalletService.getFeeEstimationTransactionForMultipleAddresses(fromAddresses, amountAsCoin, feeRate); + Transaction feeEstimationTransaction = btcWalletService.getFeeEstimationTransactionForMultipleAddresses(fromAddresses, withdrawToAddress, amountAsCoin, feeRate); if (feeExcluded && feeEstimationTransaction != null) { - feeEstimationTransaction = btcWalletService.getFeeEstimationTransactionForMultipleAddresses(fromAddresses, amountAsCoin.add(feeEstimationTransaction.getFee()), feeRate); + feeEstimationTransaction = btcWalletService.getFeeEstimationTransactionForMultipleAddresses(fromAddresses, withdrawToAddress, amountAsCoin.add(feeEstimationTransaction.getFee()), feeRate); } checkNotNull(feeEstimationTransaction, "feeEstimationTransaction must not be null");