From e7b7e41831ddd8edb8c10c6dc8b6c330312224a2 Mon Sep 17 00:00:00 2001 From: Steven Barclay Date: Fri, 2 Aug 2024 01:37:57 +0200 Subject: [PATCH] Add some missing @Nullable annotations Make 'aesKey' method parameters @Nullable where obviously applicable, for consistency (as it was missed out in a number of places). Also make the v5-protocol-specific fee bump fields of 'InputsForDepositTxRequest' @Nullable, as expected. --- .../main/java/bisq/core/btc/setup/WalletConfig.java | 2 +- .../bisq/core/btc/wallet/ClaimTransactionFactory.java | 6 ++++-- .../core/btc/wallet/RedirectionTransactionFactory.java | 4 +++- .../main/java/bisq/core/btc/wallet/WalletService.java | 6 +++--- .../core/btc/wallet/WarningTransactionFactory.java | 4 +++- core/src/main/java/bisq/core/trade/TradeManager.java | 4 ++-- .../bisq_v1/messages/InputsForDepositTxRequest.java | 6 ++++-- .../desktop/main/funds/withdrawal/WithdrawalView.java | 10 ++++++---- .../main/overlays/windows/BtcEmptyWalletWindow.java | 6 ++++-- .../pendingtrades/PendingTradesDataModel.java | 2 +- 10 files changed, 31 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/bisq/core/btc/setup/WalletConfig.java b/core/src/main/java/bisq/core/btc/setup/WalletConfig.java index afa52f8482a..381449c39be 100644 --- a/core/src/main/java/bisq/core/btc/setup/WalletConfig.java +++ b/core/src/main/java/bisq/core/btc/setup/WalletConfig.java @@ -548,7 +548,7 @@ public File directory() { return directory; } - public void maybeAddSegwitKeychain(Wallet wallet, KeyParameter aesKey, boolean isBsqWallet) { + public void maybeAddSegwitKeychain(Wallet wallet, @Nullable KeyParameter aesKey, boolean isBsqWallet) { var nonSegwitAccountPath = isBsqWallet ? BisqKeyChainGroupStructure.BIP44_BSQ_NON_SEGWIT_ACCOUNT_PATH : BisqKeyChainGroupStructure.BIP44_BTC_NON_SEGWIT_ACCOUNT_PATH; diff --git a/core/src/main/java/bisq/core/btc/wallet/ClaimTransactionFactory.java b/core/src/main/java/bisq/core/btc/wallet/ClaimTransactionFactory.java index 348a9533b07..4fd546e9ee5 100644 --- a/core/src/main/java/bisq/core/btc/wallet/ClaimTransactionFactory.java +++ b/core/src/main/java/bisq/core/btc/wallet/ClaimTransactionFactory.java @@ -36,6 +36,8 @@ import org.bouncycastle.crypto.params.KeyParameter; +import javax.annotation.Nullable; + import static com.google.common.base.Preconditions.checkArgument; public class ClaimTransactionFactory { @@ -52,7 +54,7 @@ public Transaction createSignedClaimTransaction(TransactionOutput warningTxOutpu long miningFee, byte[] peersMultiSigPubKey, DeterministicKey myMultiSigKeyPair, - KeyParameter aesKey) + @Nullable KeyParameter aesKey) throws AddressFormatException, TransactionVerificationException { Transaction claimTx = createUnsignedClaimTransaction(warningTxOutput, claimDelay, payoutAddress, miningFee); @@ -90,7 +92,7 @@ private ECKey.ECDSASignature signClaimTransaction(Transaction claimTx, byte[] buyerPubKey, byte[] sellerPubKey, DeterministicKey myMultiSigKeyPair, - KeyParameter aesKey) + @Nullable KeyParameter aesKey) throws TransactionVerificationException { Script redeemScript = WarningTransactionFactory.createRedeemScript(isBuyer, buyerPubKey, sellerPubKey, claimDelay); diff --git a/core/src/main/java/bisq/core/btc/wallet/RedirectionTransactionFactory.java b/core/src/main/java/bisq/core/btc/wallet/RedirectionTransactionFactory.java index bfa7461eb04..beb3cedbb45 100644 --- a/core/src/main/java/bisq/core/btc/wallet/RedirectionTransactionFactory.java +++ b/core/src/main/java/bisq/core/btc/wallet/RedirectionTransactionFactory.java @@ -41,6 +41,8 @@ import java.util.List; +import javax.annotation.Nullable; + import static com.google.common.base.Preconditions.checkArgument; public class RedirectionTransactionFactory { @@ -82,7 +84,7 @@ public byte[] signRedirectionTransaction(TransactionOutput warningTxOutput, byte[] buyerPubKey, byte[] sellerPubKey, DeterministicKey myMultiSigKeyPair, - KeyParameter aesKey) + @Nullable KeyParameter aesKey) throws TransactionVerificationException { Script redeemScript = WarningTransactionFactory.createRedeemScript(!isBuyer, buyerPubKey, sellerPubKey, claimDelay); diff --git a/core/src/main/java/bisq/core/btc/wallet/WalletService.java b/core/src/main/java/bisq/core/btc/wallet/WalletService.java index 7b0566cb3c1..aa498726b04 100644 --- a/core/src/main/java/bisq/core/btc/wallet/WalletService.java +++ b/core/src/main/java/bisq/core/btc/wallet/WalletService.java @@ -283,7 +283,7 @@ public static void checkScriptSig(Transaction transaction, /////////////////////////////////////////////////////////////////////////////////////////// public static void signTx(Wallet wallet, - KeyParameter aesKey, + @Nullable KeyParameter aesKey, Transaction tx) throws WalletException, TransactionVerificationException { for (int i = 0; i < tx.getInputs().size(); i++) { @@ -309,7 +309,7 @@ public static void signTx(Wallet wallet, } public static void signTransactionInput(Wallet wallet, - KeyParameter aesKey, + @Nullable KeyParameter aesKey, Transaction tx, TransactionInput txIn, int index) { @@ -634,7 +634,7 @@ public Coin getDust(Transaction proposedTransaction) { /////////////////////////////////////////////////////////////////////////////////////////// public void emptyBtcWallet(String toAddress, - KeyParameter aesKey, + @Nullable KeyParameter aesKey, ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) throws InsufficientMoneyException, AddressFormatException { diff --git a/core/src/main/java/bisq/core/btc/wallet/WarningTransactionFactory.java b/core/src/main/java/bisq/core/btc/wallet/WarningTransactionFactory.java index 540776dbde1..d7d2d882808 100644 --- a/core/src/main/java/bisq/core/btc/wallet/WarningTransactionFactory.java +++ b/core/src/main/java/bisq/core/btc/wallet/WarningTransactionFactory.java @@ -39,6 +39,8 @@ import org.bouncycastle.crypto.params.KeyParameter; +import javax.annotation.Nullable; + import static com.google.common.base.Preconditions.checkArgument; import static org.bitcoinj.script.ScriptOpCodes.*; @@ -89,7 +91,7 @@ public byte[] signWarningTransaction(Transaction warningTx, DeterministicKey myMultiSigKeyPair, byte[] buyerPubKey, byte[] sellerPubKey, - KeyParameter aesKey) + @Nullable KeyParameter aesKey) throws TransactionVerificationException { Script redeemScript = TradeWalletService.get2of2MultiSigRedeemScript(buyerPubKey, sellerPubKey); diff --git a/core/src/main/java/bisq/core/trade/TradeManager.java b/core/src/main/java/bisq/core/trade/TradeManager.java index 5e8d548b4f8..30c609f6f2f 100644 --- a/core/src/main/java/bisq/core/trade/TradeManager.java +++ b/core/src/main/java/bisq/core/trade/TradeManager.java @@ -679,7 +679,7 @@ private OfferAvailabilityModel getOfferAvailabilityModel(Offer offer, boolean is public void onWithdrawRequest(String toAddress, Coin amount, Coin fee, - KeyParameter aesKey, + @Nullable KeyParameter aesKey, Trade trade, @Nullable String memo, ResultHandler resultHandler, @@ -688,7 +688,7 @@ public void onWithdrawRequest(String toAddress, AddressEntry.Context.TRADE_PAYOUT).getAddressString(); FutureCallback callback = new FutureCallback<>() { @Override - public void onSuccess(@javax.annotation.Nullable Transaction transaction) { + public void onSuccess(@Nullable Transaction transaction) { if (transaction != null) { log.debug("onWithdraw onSuccess tx ID:" + transaction.getTxId().toString()); onTradeCompleted(trade); diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/messages/InputsForDepositTxRequest.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/messages/InputsForDepositTxRequest.java index 70e8cc8dc5f..49f1514f2bd 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/messages/InputsForDepositTxRequest.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/messages/InputsForDepositTxRequest.java @@ -84,7 +84,9 @@ public final class InputsForDepositTxRequest extends TradeMessage implements Dir private final int burningManSelectionHeight; // Added for v5 protocol + @Nullable private final String takersWarningTxFeeBumpAddress; + @Nullable private final String takersRedirectTxFeeBumpAddress; public InputsForDepositTxRequest(String tradeId, @@ -116,8 +118,8 @@ public InputsForDepositTxRequest(String tradeId, @Nullable byte[] hashOfTakersPaymentAccountPayload, @Nullable String takersPaymentMethodId, int burningManSelectionHeight, - String takersWarningTxFeeBumpAddress, - String takersRedirectTxFeeBumpAddress) { + @Nullable String takersWarningTxFeeBumpAddress, + @Nullable String takersRedirectTxFeeBumpAddress) { super(messageVersion, tradeId, uid); this.senderNodeAddress = senderNodeAddress; this.tradeAmount = tradeAmount; 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 ab2f519d970..cfebea019e2 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 @@ -114,6 +114,8 @@ import org.jetbrains.annotations.NotNull; +import javax.annotation.Nullable; + import static bisq.desktop.util.FormBuilder.*; import static com.google.common.base.Preconditions.checkNotNull; @@ -457,7 +459,7 @@ private void onWithdraw() { .actionButtonText(Res.get("shared.yes")) .onAction(() -> doWithdraw(sendersAmount, fee, new FutureCallback<>() { @Override - public void onSuccess(@javax.annotation.Nullable Transaction transaction) { + public void onSuccess(@Nullable Transaction transaction) { if (transaction != null) { String key = "showTransactionSent"; if (DontShowAgainLookup.showAgain(key)) { @@ -561,12 +563,13 @@ private void doWithdraw(Coin amount, Coin fee, FutureCallback callb } } - private void sendFunds(Coin amount, Coin fee, KeyParameter aesKey, FutureCallback callback) { + private void sendFunds(Coin amount, Coin fee, @Nullable KeyParameter aesKey, FutureCallback callback) { try { String memo = withdrawMemoTextField.getText(); if (memo.isEmpty()) { memo = null; } + //noinspection unused Transaction transaction = btcWalletService.sendFundsForMultipleAddresses(fromAddresses, withdrawToTextField.getText(), amount, @@ -705,8 +708,7 @@ private void setSelectColumnCellFactory() { public TableCell call(TableColumn column) { return new TableCell<>() { - - CheckBox checkBox = new AutoTooltipCheckBox(); + final CheckBox checkBox = new AutoTooltipCheckBox(); @Override public void updateItem(final WithdrawalListItem item, boolean empty) { diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/windows/BtcEmptyWalletWindow.java b/desktop/src/main/java/bisq/desktop/main/overlays/windows/BtcEmptyWalletWindow.java index 12c675e2f47..52cc7200d3b 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/windows/BtcEmptyWalletWindow.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/windows/BtcEmptyWalletWindow.java @@ -43,6 +43,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.annotation.Nullable; + import static bisq.desktop.util.FormBuilder.addInputTextField; import static bisq.desktop.util.FormBuilder.addMultilineLabel; import static bisq.desktop.util.FormBuilder.addTopLabelTextField; @@ -142,7 +144,7 @@ private void addContent() { GridPane.setMargin(hBox, new Insets(10, 0, 0, 0)); } - private void doEmptyWallet(KeyParameter aesKey) { + private void doEmptyWallet(@Nullable KeyParameter aesKey) { if (GUIUtil.isReadyForTxBroadcastOrShowPopup(p2PService, walletsSetup)) { if (!openOfferManager.getObservableList().isEmpty()) { UserThread.runAfter(() -> @@ -156,7 +158,7 @@ private void doEmptyWallet(KeyParameter aesKey) { } } - private void doEmptyWallet2(KeyParameter aesKey) { + private void doEmptyWallet2(@Nullable KeyParameter aesKey) { emptyWalletButton.setDisable(true); openOfferManager.removeAllOpenOffers(() -> { try { diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java index 1f73fa66f33..54873717f67 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java @@ -222,7 +222,7 @@ public void onFiatPaymentReceived(ResultHandler resultHandler, ErrorMessageHandl public void onWithdrawRequest(String toAddress, Coin amount, Coin fee, - KeyParameter aesKey, + @Nullable KeyParameter aesKey, @Nullable String memo, ResultHandler resultHandler, FaultHandler faultHandler) {