From 7a58bfbafa19fd155ae95ba5daf12fb4fe58ce12 Mon Sep 17 00:00:00 2001 From: Oscar Guindzberg Date: Tue, 6 Oct 2020 15:22:53 -0300 Subject: [PATCH] Use SegwitAddress for fee estimation --- .../java/bisq/core/btc/wallet/BtcWalletService.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 fdbc5cbda7..8573e1c687 100644 --- a/core/src/main/java/bisq/core/btc/wallet/BtcWalletService.java +++ b/core/src/main/java/bisq/core/btc/wallet/BtcWalletService.java @@ -34,7 +34,7 @@ import org.bitcoinj.core.AddressFormatException; import org.bitcoinj.core.Coin; import org.bitcoinj.core.ECKey; import org.bitcoinj.core.InsufficientMoneyException; -import org.bitcoinj.core.LegacyAddress; +import org.bitcoinj.core.SegwitAddress; import org.bitcoinj.core.Transaction; import org.bitcoinj.core.TransactionConfidence; import org.bitcoinj.core.TransactionInput; @@ -992,7 +992,9 @@ public class BtcWalletService extends WalletService { counter++; fee = txFeeForWithdrawalPerByte.multiply(txSize); // We use a dummy address for the output - final String dummyReceiver = LegacyAddress.fromKey(params, new ECKey()).toBase58(); + // 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); wallet.completeTx(sendRequest); tx = sendRequest.tx; @@ -1021,7 +1023,9 @@ public class BtcWalletService extends WalletService { public int getEstimatedFeeTxSize(List outputValues, Coin txFee) throws InsufficientMoneyException, AddressFormatException { Transaction transaction = new Transaction(params); - Address dummyAddress = LegacyAddress.fromKey(params, new ECKey()); + // In reality txs have a mix of segwit/legacy ouputs, 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. + Address dummyAddress = SegwitAddress.fromKey(params, new ECKey()); outputValues.forEach(outputValue -> transaction.addOutput(outputValue, dummyAddress)); SendRequest sendRequest = SendRequest.forTx(transaction);