From 78d61e0958ed1efb57ccfe5d94e39c6621181b00 Mon Sep 17 00:00:00 2001 From: Steven Barclay Date: Wed, 18 Dec 2019 01:53:42 +0000 Subject: [PATCH 1/3] Remove unused parameters from assorted methods Exclude abstract or default methods, as well as cases where the parameter is currently unused but is probably intended to be used later. --- .../java/bisq/core/dao/presentation/DaoUtil.java | 5 ++--- .../java/bisq/core/offer/CreateOfferService.java | 3 +-- core/src/main/java/bisq/core/offer/OfferUtil.java | 9 ++++----- .../src/main/java/bisq/core/user/Preferences.java | 15 ++++++--------- .../test/java/bisq/core/user/PreferencesTest.java | 2 +- .../desktop/components/PeerInfoIconSmall.java | 2 -- .../dashboard/GovernanceDashboardView.java | 15 +++++---------- .../dao/governance/make/MakeProposalView.java | 6 ++---- .../desktop/main/funds/deposit/DepositView.java | 2 -- .../transactions/TransactionListItemFactory.java | 6 ------ .../funds/transactions/TransactionsListItem.java | 3 --- .../main/market/offerbook/OfferBookChartView.java | 1 - .../main/offer/takeoffer/TakeOfferViewModel.java | 6 +++--- .../java/bisq/desktop/maker/PreferenceMakers.java | 2 +- 14 files changed, 25 insertions(+), 52 deletions(-) diff --git a/core/src/main/java/bisq/core/dao/presentation/DaoUtil.java b/core/src/main/java/bisq/core/dao/presentation/DaoUtil.java index bb251f564de..44a02536e47 100644 --- a/core/src/main/java/bisq/core/dao/presentation/DaoUtil.java +++ b/core/src/main/java/bisq/core/dao/presentation/DaoUtil.java @@ -21,7 +21,6 @@ import bisq.core.dao.state.model.governance.DaoPhase; import bisq.core.locale.Res; import bisq.core.util.FormattingUtils; -import bisq.core.util.coin.CoinFormatter; import java.text.SimpleDateFormat; @@ -33,7 +32,7 @@ */ public class DaoUtil { - public static String getNextPhaseDuration(int height, DaoPhase.Phase phase, DaoFacade daoFacade, CoinFormatter formatter) { + public static String getNextPhaseDuration(int height, DaoPhase.Phase phase, DaoFacade daoFacade) { final int currentCycleDuration = daoFacade.getCurrentCycleDuration(); long start = daoFacade.getFirstBlockOfPhaseForDisplay(height, phase) + currentCycleDuration; long end = daoFacade.getLastBlockOfPhaseForDisplay(height, phase) + currentCycleDuration; @@ -47,7 +46,7 @@ public static String getNextPhaseDuration(int height, DaoPhase.Phase phase, DaoF return Res.get("dao.cycle.phaseDurationWithoutBlocks", start, end, startDateTime, endDateTime); } - public static String getPhaseDuration(int height, DaoPhase.Phase phase, DaoFacade daoFacade, CoinFormatter formatter) { + public static String getPhaseDuration(int height, DaoPhase.Phase phase, DaoFacade daoFacade) { long start = daoFacade.getFirstBlockOfPhaseForDisplay(height, phase); long end = daoFacade.getLastBlockOfPhaseForDisplay(height, phase); long duration = daoFacade.getDurationForPhaseForDisplay(phase); diff --git a/core/src/main/java/bisq/core/offer/CreateOfferService.java b/core/src/main/java/bisq/core/offer/CreateOfferService.java index 106f28e96a1..f3791aae35e 100644 --- a/core/src/main/java/bisq/core/offer/CreateOfferService.java +++ b/core/src/main/java/bisq/core/offer/CreateOfferService.java @@ -201,8 +201,7 @@ public Offer createAndGetOffer(String offerId, Map extraDataMap = OfferUtil.getExtraDataMap(accountAgeWitnessService, referralIdService, paymentAccount, - currencyCode, - preferences); + currencyCode); OfferUtil.validateOfferData(filterManager, p2PService, diff --git a/core/src/main/java/bisq/core/offer/OfferUtil.java b/core/src/main/java/bisq/core/offer/OfferUtil.java index bebf49a6210..a4291e5021f 100644 --- a/core/src/main/java/bisq/core/offer/OfferUtil.java +++ b/core/src/main/java/bisq/core/offer/OfferUtil.java @@ -291,9 +291,9 @@ public static Optional getFeeInUserFiatCurrency(Coin makerFee, boolean i bsqFormatter); } - public static Optional getFeeInUserFiatCurrency(Coin makerFee, boolean isCurrencyForMakerFeeBtc, - String userCurrencyCode, PriceFeedService priceFeedService, - CoinFormatter bsqFormatter) { + private static Optional getFeeInUserFiatCurrency(Coin makerFee, boolean isCurrencyForMakerFeeBtc, + String userCurrencyCode, PriceFeedService priceFeedService, + CoinFormatter bsqFormatter) { // We use the users currency derived from his selected country. // We don't use the preferredTradeCurrency from preferences as that can be also set to an altcoin. @@ -325,8 +325,7 @@ public static Optional getFeeInUserFiatCurrency(Coin makerFee, boolean i public static Map getExtraDataMap(AccountAgeWitnessService accountAgeWitnessService, ReferralIdService referralIdService, PaymentAccount paymentAccount, - String currencyCode, - Preferences preferences) { + String currencyCode) { Map extraDataMap = new HashMap<>(); if (CurrencyUtil.isFiatCurrency(currencyCode)) { String myWitnessHashAsHex = accountAgeWitnessService.getMyWitnessHashAsHex(paymentAccount.getPaymentAccountPayload()); diff --git a/core/src/main/java/bisq/core/user/Preferences.java b/core/src/main/java/bisq/core/user/Preferences.java index 7d826b7a47b..8676d31945a 100644 --- a/core/src/main/java/bisq/core/user/Preferences.java +++ b/core/src/main/java/bisq/core/user/Preferences.java @@ -152,8 +152,7 @@ public Preferences(Storage storage, @Named(DaoOptionKeys.FULL_DAO_NODE) String fullDaoNode, @Named(DaoOptionKeys.RPC_USER) String rpcUser, @Named(DaoOptionKeys.RPC_PASSWORD) String rpcPassword, - @Named(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT) String rpcBlockNotificationPort, - @Named(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_HOST) String rpcBlockNotificationHost) { + @Named(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT) String rpcBlockNotificationPort) { this.storage = storage; @@ -329,7 +328,7 @@ public void setUseAnimations(boolean useAnimations) { } public void setCssTheme(boolean useDarkMode) { - this.cssThemeProperty.set(useDarkMode == true ? 1 : 0); + this.cssThemeProperty.set(useDarkMode ? 1 : 0); } public void addFiatCurrency(FiatCurrency tradeCurrency) { @@ -339,8 +338,7 @@ public void addFiatCurrency(FiatCurrency tradeCurrency) { public void removeFiatCurrency(FiatCurrency tradeCurrency) { if (tradeCurrenciesAsObservable.size() > 1) { - if (fiatCurrenciesAsObservable.contains(tradeCurrency)) - fiatCurrenciesAsObservable.remove(tradeCurrency); + fiatCurrenciesAsObservable.remove(tradeCurrency); if (prefPayload.getPreferredTradeCurrency() != null && prefPayload.getPreferredTradeCurrency().equals(tradeCurrency)) @@ -357,8 +355,7 @@ public void addCryptoCurrency(CryptoCurrency tradeCurrency) { public void removeCryptoCurrency(CryptoCurrency tradeCurrency) { if (tradeCurrenciesAsObservable.size() > 1) { - if (cryptoCurrenciesAsObservable.contains(tradeCurrency)) - cryptoCurrenciesAsObservable.remove(tradeCurrency); + cryptoCurrenciesAsObservable.remove(tradeCurrency); if (prefPayload.getPreferredTradeCurrency() != null && prefPayload.getPreferredTradeCurrency().equals(tradeCurrency)) @@ -538,12 +535,12 @@ public void setBsqBlockChainExplorer(BlockChainExplorer bsqBlockChainExplorer) { persist(); } - public void setBlockChainExplorerTestNet(BlockChainExplorer blockChainExplorerTestNet) { + private void setBlockChainExplorerTestNet(BlockChainExplorer blockChainExplorerTestNet) { prefPayload.setBlockChainExplorerTestNet(blockChainExplorerTestNet); persist(); } - public void setBlockChainExplorerMainNet(BlockChainExplorer blockChainExplorerMainNet) { + private void setBlockChainExplorerMainNet(BlockChainExplorer blockChainExplorerMainNet) { prefPayload.setBlockChainExplorerMainNet(blockChainExplorerMainNet); persist(); } diff --git a/core/src/test/java/bisq/core/user/PreferencesTest.java b/core/src/test/java/bisq/core/user/PreferencesTest.java index 6da24a2288e..5c37b6b0c47 100644 --- a/core/src/test/java/bisq/core/user/PreferencesTest.java +++ b/core/src/test/java/bisq/core/user/PreferencesTest.java @@ -61,7 +61,7 @@ public void setUp() { storage = mock(Storage.class); bisqEnvironment = mock(BisqEnvironment.class); - preferences = new Preferences(storage, bisqEnvironment, null, null, null, null, null, null, null, null); + preferences = new Preferences(storage, bisqEnvironment, null, null, null, null, null, null, null); } @Test diff --git a/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java b/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java index ca1afb51513..d1cb74d57c0 100644 --- a/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java +++ b/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java @@ -4,7 +4,6 @@ import bisq.core.alert.PrivateNotificationManager; import bisq.core.offer.Offer; import bisq.core.user.Preferences; -import bisq.core.util.coin.CoinFormatter; import bisq.network.p2p.NodeAddress; @@ -13,7 +12,6 @@ public PeerInfoIconSmall(NodeAddress nodeAddress, String role, Offer offer, Preferences preferences, AccountAgeWitnessService accountAgeWitnessService, - CoinFormatter formatter, boolean useDevPrivilegeKeys) { // We don't want to show number of trades in that case as it would be unreadable. // Also we don't need the privateNotificationManager as no interaction will take place with this icon. diff --git a/desktop/src/main/java/bisq/desktop/main/dao/governance/dashboard/GovernanceDashboardView.java b/desktop/src/main/java/bisq/desktop/main/dao/governance/dashboard/GovernanceDashboardView.java index 1080eacb4c2..d6926cb24d5 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/governance/dashboard/GovernanceDashboardView.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/governance/dashboard/GovernanceDashboardView.java @@ -30,11 +30,8 @@ import bisq.core.dao.state.model.blockchain.Block; import bisq.core.dao.state.model.governance.DaoPhase; import bisq.core.locale.Res; -import bisq.core.util.FormattingUtils; -import bisq.core.util.coin.CoinFormatter; import javax.inject.Inject; -import javax.inject.Named; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; @@ -50,7 +47,6 @@ public class GovernanceDashboardView extends ActivatableView imp private final DaoFacade daoFacade; private final PeriodService periodService; private final PhasesView phasesView; - private final CoinFormatter formatter; private int gridRow = 0; private TextField currentPhaseTextField, currentBlockHeightTextField, proposalTextField, blindVoteTextField, voteRevealTextField, voteResultTextField; @@ -61,11 +57,10 @@ public class GovernanceDashboardView extends ActivatableView imp /////////////////////////////////////////////////////////////////////////////////////////// @Inject - public GovernanceDashboardView(DaoFacade daoFacade, PeriodService periodService, PhasesView phasesView, @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter) { + public GovernanceDashboardView(DaoFacade daoFacade, PeriodService periodService, PhasesView phasesView) { this.daoFacade = daoFacade; this.periodService = periodService; this.phasesView = phasesView; - this.formatter = formatter; } @Override @@ -127,9 +122,9 @@ private void applyData(int height) { phase = periodService.getPhaseForHeight(height + 1); } currentPhaseTextField.setText(Res.get("dao.phase." + phase.name())); - proposalTextField.setText(DaoUtil.getPhaseDuration(height, DaoPhase.Phase.PROPOSAL, daoFacade, formatter)); - blindVoteTextField.setText(DaoUtil.getPhaseDuration(height, DaoPhase.Phase.BLIND_VOTE, daoFacade, formatter)); - voteRevealTextField.setText(DaoUtil.getPhaseDuration(height, DaoPhase.Phase.VOTE_REVEAL, daoFacade, formatter)); - voteResultTextField.setText(DaoUtil.getPhaseDuration(height, DaoPhase.Phase.RESULT, daoFacade, formatter)); + proposalTextField.setText(DaoUtil.getPhaseDuration(height, DaoPhase.Phase.PROPOSAL, daoFacade)); + blindVoteTextField.setText(DaoUtil.getPhaseDuration(height, DaoPhase.Phase.BLIND_VOTE, daoFacade)); + voteRevealTextField.setText(DaoUtil.getPhaseDuration(height, DaoPhase.Phase.VOTE_REVEAL, daoFacade)); + voteResultTextField.setText(DaoUtil.getPhaseDuration(height, DaoPhase.Phase.RESULT, daoFacade)); } } diff --git a/desktop/src/main/java/bisq/desktop/main/dao/governance/make/MakeProposalView.java b/desktop/src/main/java/bisq/desktop/main/dao/governance/make/MakeProposalView.java index 04407705671..89372c93931 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/governance/make/MakeProposalView.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/governance/make/MakeProposalView.java @@ -271,7 +271,7 @@ public void onParseBlockCompleteAfterBatchProcessing(Block block) { /////////////////////////////////////////////////////////////////////////////////////////// private void updateTimeUntilNextProposalPhase(int height) { - nextProposalTextField.setText(DaoUtil.getNextPhaseDuration(height, DaoPhase.Phase.PROPOSAL, daoFacade, btcFormatter)); + nextProposalTextField.setText(DaoUtil.getNextPhaseDuration(height, DaoPhase.Phase.PROPOSAL, daoFacade)); } private void publishMyProposal(ProposalType type) { @@ -298,9 +298,7 @@ private void publishMyProposal(ProposalType type) { new Popup().warning(Res.get("dao.proposal.create.missingBsqFundsForBond", bsqFormatter.formatCoinWithCode(missing))) .actionButtonText(Res.get("dao.proposal.create.publish")) - .onAction(() -> { - showFeeInfoAndPublishMyProposal(proposal, transaction, miningFee, txSize, fee); - }) + .onAction(() -> showFeeInfoAndPublishMyProposal(proposal, transaction, miningFee, txSize, fee)) .show(); } else { showFeeInfoAndPublishMyProposal(proposal, transaction, miningFee, txSize, fee); diff --git a/desktop/src/main/java/bisq/desktop/main/funds/deposit/DepositView.java b/desktop/src/main/java/bisq/desktop/main/funds/deposit/DepositView.java index 455e16b4af3..3d08c7528ce 100644 --- a/desktop/src/main/java/bisq/desktop/main/funds/deposit/DepositView.java +++ b/desktop/src/main/java/bisq/desktop/main/funds/deposit/DepositView.java @@ -34,7 +34,6 @@ import bisq.core.btc.model.AddressEntry; import bisq.core.btc.wallet.BtcWalletService; import bisq.core.locale.Res; -import bisq.core.provider.fee.FeeService; import bisq.core.user.Preferences; import bisq.core.util.FormattingUtils; import bisq.core.util.ParsingUtils; @@ -123,7 +122,6 @@ public class DepositView extends ActivatableView { @Inject private DepositView(BtcWalletService walletService, - FeeService feeService, Preferences preferences, @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter) { this.walletService = walletService; diff --git a/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionListItemFactory.java b/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionListItemFactory.java index 64294a045f8..55234b486cd 100644 --- a/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionListItemFactory.java +++ b/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionListItemFactory.java @@ -24,8 +24,6 @@ import bisq.core.util.FormattingUtils; import bisq.core.util.coin.CoinFormatter; -import bisq.common.crypto.PubKeyRing; - import org.bitcoinj.core.Transaction; import javax.inject.Inject; @@ -40,7 +38,6 @@ public class TransactionListItemFactory { private final BtcWalletService btcWalletService; private final BsqWalletService bsqWalletService; private final DaoFacade daoFacade; - private final PubKeyRing pubKeyRing; private final CoinFormatter formatter; private final Preferences preferences; @@ -48,13 +45,11 @@ public class TransactionListItemFactory { TransactionListItemFactory(BtcWalletService btcWalletService, BsqWalletService bsqWalletService, DaoFacade daoFacade, - PubKeyRing pubKeyRing, @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter, Preferences preferences) { this.btcWalletService = btcWalletService; this.bsqWalletService = bsqWalletService; this.daoFacade = daoFacade; - this.pubKeyRing = pubKeyRing; this.formatter = formatter; this.preferences = preferences; } @@ -65,7 +60,6 @@ TransactionsListItem create(Transaction transaction, @Nullable TransactionAwareT bsqWalletService, tradable, daoFacade, - pubKeyRing, formatter, preferences.getIgnoreDustThreshold()); } diff --git a/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionsListItem.java b/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionsListItem.java index e8b9f47e2a0..6e65c728cd0 100644 --- a/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionsListItem.java +++ b/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionsListItem.java @@ -34,8 +34,6 @@ import bisq.core.trade.Trade; import bisq.core.util.coin.CoinFormatter; -import bisq.common.crypto.PubKeyRing; - import org.bitcoinj.core.Coin; import org.bitcoinj.core.Transaction; import org.bitcoinj.core.TransactionConfidence; @@ -89,7 +87,6 @@ class TransactionsListItem { BsqWalletService bsqWalletService, TransactionAwareTradable transactionAwareTradable, DaoFacade daoFacade, - PubKeyRing pubKeyRing, CoinFormatter formatter, long ignoreDustThreshold) { this.btcWalletService = btcWalletService; diff --git a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java index a0b7f20d501..283e4753dff 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java +++ b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java @@ -592,7 +592,6 @@ public void updateItem(final OfferListItem newItem, boolean empty) { offer, model.preferences, model.accountAgeWitnessService, - formatter, useDevPrivilegeKeys); // setAlignment(Pos.CENTER); setGraphic(peerInfoIcon); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferViewModel.java index bb9a805df16..20d0ae06f4a 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferViewModel.java @@ -247,7 +247,7 @@ void onTakeOffer(Runnable resultHandler) { dataModel.onTakeOffer(trade -> { this.trade = trade; trade.stateProperty().addListener(tradeStateListener); - applyTradeState(trade.getState()); + applyTradeState(); trade.errorMessageProperty().addListener(tradeErrorListener); applyTradeErrorMessage(trade.getErrorMessage()); takeOfferCompleted.set(true); @@ -486,7 +486,7 @@ private void applyTradeErrorMessage(@Nullable String errorMessage) { } } - private void applyTradeState(Trade.State tradeState) { + private void applyTradeState() { if (trade.isDepositPublished()) { if (trade.getDepositTx() != null) { if (takeOfferSucceededHandler != null) @@ -551,7 +551,7 @@ private void createListeners() { }; isWalletFundedListener = (ov, oldValue, newValue) -> updateButtonDisableState(); - tradeStateListener = (ov, oldValue, newValue) -> applyTradeState(newValue); + tradeStateListener = (ov, oldValue, newValue) -> applyTradeState(); tradeErrorListener = (ov, oldValue, newValue) -> applyTradeErrorMessage(newValue); offerStateListener = (ov, oldValue, newValue) -> applyOfferState(newValue); connectionListener = new ConnectionListener() { diff --git a/desktop/src/test/java/bisq/desktop/maker/PreferenceMakers.java b/desktop/src/test/java/bisq/desktop/maker/PreferenceMakers.java index 230b1ad6d90..1cd33a1ad51 100644 --- a/desktop/src/test/java/bisq/desktop/maker/PreferenceMakers.java +++ b/desktop/src/test/java/bisq/desktop/maker/PreferenceMakers.java @@ -43,7 +43,7 @@ public class PreferenceMakers { lookup.valueOf(btcNodesFromOptions, new SameValueDonor(null)), lookup.valueOf(useTorFlagFromOptions, new SameValueDonor(null)), lookup.valueOf(referralID, new SameValueDonor(null)), - null, null, null, null, null); + null, null, null, null); public static final Preferences empty = make(a(Preferences)); From cc7d0dec262c0b2765c71739489aad1599ed32c1 Mon Sep 17 00:00:00 2001 From: Steven Barclay Date: Wed, 18 Dec 2019 04:01:05 +0000 Subject: [PATCH 2/3] Actually use the injected Clock param of isDateInTolerance Use 'clock.millis()' instead of "new Date().getTime()" in SignedWitness & AccountAgeWitness, as the latter may have been left as an oversight. Also tidy the date field of the toString() methods. --- .../java/bisq/core/account/sign/SignedWitness.java | 10 +++++----- .../bisq/core/account/witness/AccountAgeWitness.java | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/bisq/core/account/sign/SignedWitness.java b/core/src/main/java/bisq/core/account/sign/SignedWitness.java index d2268400ac6..f699b8015e2 100644 --- a/core/src/main/java/bisq/core/account/sign/SignedWitness.java +++ b/core/src/main/java/bisq/core/account/sign/SignedWitness.java @@ -20,8 +20,8 @@ import bisq.network.p2p.storage.P2PDataStorage; import bisq.network.p2p.storage.payload.CapabilityRequiringPayload; import bisq.network.p2p.storage.payload.DateTolerantPayload; -import bisq.network.p2p.storage.payload.ProcessOncePersistableNetworkPayload; import bisq.network.p2p.storage.payload.PersistableNetworkPayload; +import bisq.network.p2p.storage.payload.ProcessOncePersistableNetworkPayload; import bisq.common.app.Capabilities; import bisq.common.app.Capability; @@ -35,8 +35,8 @@ import org.bitcoinj.core.Coin; import java.time.Clock; +import java.time.Instant; -import java.util.Date; import java.util.concurrent.TimeUnit; import lombok.Value; @@ -142,7 +142,7 @@ public static SignedWitness fromProto(protobuf.SignedWitness proto) { public boolean isDateInTolerance(Clock clock) { // We don't allow older or newer than 1 day. // Preventing forward dating is also important to protect against a sophisticated attack - return Math.abs(new Date().getTime() - date) <= TOLERANCE; + return Math.abs(clock.millis() - date) <= TOLERANCE; } @Override @@ -176,12 +176,12 @@ P2PDataStorage.ByteArray getHashAsByteArray() { @Override public String toString() { return "SignedWitness{" + - ",\n verificationMethod=" + verificationMethod + + "\n verificationMethod=" + verificationMethod + ",\n witnessHash=" + Utilities.bytesAsHexString(accountAgeWitnessHash) + ",\n signature=" + Utilities.bytesAsHexString(signature) + ",\n signerPubKey=" + Utilities.bytesAsHexString(signerPubKey) + ",\n witnessOwnerPubKey=" + Utilities.bytesAsHexString(witnessOwnerPubKey) + - ",\n date=" + date + + ",\n date=" + Instant.ofEpochMilli(date) + ",\n tradeAmount=" + Coin.valueOf(tradeAmount).toFriendlyString() + ",\n hash=" + Utilities.bytesAsHexString(hash) + "\n}"; diff --git a/core/src/main/java/bisq/core/account/witness/AccountAgeWitness.java b/core/src/main/java/bisq/core/account/witness/AccountAgeWitness.java index 07f05096602..969665d35fe 100644 --- a/core/src/main/java/bisq/core/account/witness/AccountAgeWitness.java +++ b/core/src/main/java/bisq/core/account/witness/AccountAgeWitness.java @@ -19,8 +19,8 @@ import bisq.network.p2p.storage.P2PDataStorage; import bisq.network.p2p.storage.payload.DateTolerantPayload; -import bisq.network.p2p.storage.payload.ProcessOncePersistableNetworkPayload; import bisq.network.p2p.storage.payload.PersistableNetworkPayload; +import bisq.network.p2p.storage.payload.ProcessOncePersistableNetworkPayload; import bisq.common.proto.persistable.PersistableEnvelope; import bisq.common.util.Utilities; @@ -28,8 +28,8 @@ import com.google.protobuf.ByteString; import java.time.Clock; +import java.time.Instant; -import java.util.Date; import java.util.concurrent.TimeUnit; import lombok.Value; @@ -65,7 +65,7 @@ public protobuf.PersistableNetworkPayload toProtoMessage() { return protobuf.PersistableNetworkPayload.newBuilder().setAccountAgeWitness(builder).build(); } - public protobuf.AccountAgeWitness toProtoAccountAgeWitness() { + protobuf.AccountAgeWitness toProtoAccountAgeWitness() { return toProtoMessage().getAccountAgeWitness(); } @@ -89,7 +89,7 @@ public static AccountAgeWitness fromProto(protobuf.AccountAgeWitness proto) { public boolean isDateInTolerance(Clock clock) { // We don't allow older or newer than 1 day. // Preventing forward dating is also important to protect against a sophisticated attack - return Math.abs(new Date().getTime() - date) <= TOLERANCE; + return Math.abs(clock.millis() - date) <= TOLERANCE; } @Override @@ -107,7 +107,7 @@ public byte[] getHash() { // Getters /////////////////////////////////////////////////////////////////////////////////////////// - public P2PDataStorage.ByteArray getHashAsByteArray() { + P2PDataStorage.ByteArray getHashAsByteArray() { return new P2PDataStorage.ByteArray(hash); } @@ -115,7 +115,7 @@ public P2PDataStorage.ByteArray getHashAsByteArray() { public String toString() { return "AccountAgeWitness{" + "\n hash=" + Utilities.bytesAsHexString(hash) + - ",\n date=" + new Date(date) + + ",\n date=" + Instant.ofEpochMilli(date) + "\n}"; } } From d0a76b9ff297fcfe59f6348a9ede90d87ccb64ef Mon Sep 17 00:00:00 2001 From: Steven Barclay Date: Wed, 18 Dec 2019 23:02:20 +0000 Subject: [PATCH 3/3] Suppress warnings of unused method params which may be needed later Also fix forwarding of telescoping method parameters in FormBuilder and FormattingUtils. --- .../core/btc/wallet/TradeWalletService.java | 25 +++++++++---------- .../main/java/bisq/core/locale/BankUtil.java | 4 +-- .../java/bisq/core/util/FormattingUtils.java | 4 +-- .../java/bisq/desktop/util/FormBuilder.java | 12 ++++----- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java b/core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java index 8a570dd8301..5dd117791e9 100644 --- a/core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java +++ b/core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java @@ -707,7 +707,7 @@ public Transaction finalizeDelayedPayoutTx(Transaction delayedPayoutTx, return delayedPayoutTx; } - public boolean verifiesDepositTxAndDelayedPayoutTx(Transaction depositTx, + public boolean verifiesDepositTxAndDelayedPayoutTx(@SuppressWarnings("unused") Transaction depositTx, Transaction delayedPayoutTx) { // todo add more checks if (delayedPayoutTx.getLockTime() == 0) { @@ -963,17 +963,17 @@ public Transaction traderSignAndFinalizeDisputedPayoutTx(byte[] depositTxSeriali // Emergency payoutTx /////////////////////////////////////////////////////////////////////////////////////////// - public Transaction emergencySignAndPublishPayoutTxFrom2of2MultiSig(String depositTxHex, - Coin buyerPayoutAmount, - Coin sellerPayoutAmount, - Coin txFee, - String buyerAddressString, - String sellerAddressString, - String buyerPrivateKeyAsHex, - String sellerPrivateKeyAsHex, - String buyerPubKeyAsHex, - String sellerPubKeyAsHex, - TxBroadcaster.Callback callback) + public void emergencySignAndPublishPayoutTxFrom2of2MultiSig(String depositTxHex, + Coin buyerPayoutAmount, + Coin sellerPayoutAmount, + Coin txFee, + String buyerAddressString, + String sellerAddressString, + String buyerPrivateKeyAsHex, + String sellerPrivateKeyAsHex, + String buyerPubKeyAsHex, + String sellerPubKeyAsHex, + TxBroadcaster.Callback callback) throws AddressFormatException, TransactionVerificationException, WalletException { byte[] buyerPubKey = ECKey.fromPublicOnly(Utils.HEX.decode(buyerPubKeyAsHex)).getPubKey(); byte[] sellerPubKey = ECKey.fromPublicOnly(Utils.HEX.decode(sellerPubKeyAsHex)).getPubKey(); @@ -1018,7 +1018,6 @@ public Transaction emergencySignAndPublishPayoutTxFrom2of2MultiSig(String deposi WalletService.verifyTransaction(payoutTx); WalletService.checkWalletConsistency(wallet); broadcastTx(payoutTx, callback, 20); - return payoutTx; } diff --git a/core/src/main/java/bisq/core/locale/BankUtil.java b/core/src/main/java/bisq/core/locale/BankUtil.java index 5d2a6c4dcb3..a1bb2615b23 100644 --- a/core/src/main/java/bisq/core/locale/BankUtil.java +++ b/core/src/main/java/bisq/core/locale/BankUtil.java @@ -30,8 +30,8 @@ public class BankUtil { // BankName @SuppressWarnings("SameReturnValue") - public static boolean isBankNameRequired(String countryCode) { - // Currently we always return true but let's keep that method to be more flexible in case we what to not show + public static boolean isBankNameRequired(@SuppressWarnings("unused") String countryCode) { + // Currently we always return true but let's keep that method to be more flexible in case we want to not show // it at some new payment method. return true; /* diff --git a/core/src/main/java/bisq/core/util/FormattingUtils.java b/core/src/main/java/bisq/core/util/FormattingUtils.java index 7c470c727d8..ac1512148f6 100644 --- a/core/src/main/java/bisq/core/util/FormattingUtils.java +++ b/core/src/main/java/bisq/core/util/FormattingUtils.java @@ -157,7 +157,7 @@ public static String formatPrice(Price price, MonetaryFormat fiatPriceFormat, bo } public static String formatPrice(Price price, boolean appendCurrencyCode) { - return formatPrice(price, fiatPriceFormat, true); + return formatPrice(price, fiatPriceFormat, appendCurrencyCode); } public static String formatPrice(Price price) { @@ -279,7 +279,7 @@ else if (bytes < mb) } @NotNull - public static String fillUpPlacesWithEmptyStrings(String formattedNumber, int maxNumberOfDigits) { + public static String fillUpPlacesWithEmptyStrings(String formattedNumber, @SuppressWarnings("unused") int maxNumberOfDigits) { //FIXME: temporary deactivate adding spaces in front of numbers as we don't use a monospace font right now. /*int numberOfPlacesToFill = maxNumberOfDigits - formattedNumber.length(); for (int i = 0; i < numberOfPlacesToFill; i++) { diff --git a/desktop/src/main/java/bisq/desktop/util/FormBuilder.java b/desktop/src/main/java/bisq/desktop/util/FormBuilder.java index 85d70513bbc..cf4ed73b85a 100644 --- a/desktop/src/main/java/bisq/desktop/util/FormBuilder.java +++ b/desktop/src/main/java/bisq/desktop/util/FormBuilder.java @@ -504,9 +504,9 @@ public static TextArea addTextArea(GridPane gridPane, int rowIndex, String promp public static TextArea addTextArea(GridPane gridPane, int rowIndex, String prompt, double top) { - TextArea textArea = new BisqTextArea(); + JFXTextArea textArea = new BisqTextArea(); textArea.setPromptText(prompt); - ((JFXTextArea) textArea).setLabelFloat(true); + textArea.setLabelFloat(true); textArea.setWrapText(true); GridPane.setRowIndex(textArea, rowIndex); @@ -901,7 +901,7 @@ public static CheckBox addCheckBox(GridPane gridPane, int rowIndex, String check } public static CheckBox addCheckBox(GridPane gridPane, int rowIndex, String checkBoxTitle, double top) { - return addCheckBox(gridPane, rowIndex, 0, checkBoxTitle, 0); + return addCheckBox(gridPane, rowIndex, 0, checkBoxTitle, top); } public static CheckBox addCheckBox(GridPane gridPane, @@ -1221,7 +1221,7 @@ public static Tuple4> addTopLabelTextFi final Label topLabel2 = getTopLabel(titleCombobox); AutocompleteComboBox comboBox = new AutocompleteComboBox<>(); comboBox.setPromptText(titleCombobox); - ((JFXComboBox) comboBox).setLabelFloat(true); + comboBox.setLabelFloat(true); topLabelVBox2.getChildren().addAll(topLabel2, comboBox); hBox.getChildren().addAll(topLabelVBox1, topLabelVBox2); @@ -1278,9 +1278,9 @@ public static Tuple4, Label, TextField, HBox> addComboBoxTopLabe HBox hBox = new HBox(); hBox.setSpacing(10); - ComboBox comboBox = new JFXComboBox<>(); + JFXComboBox comboBox = new JFXComboBox<>(); comboBox.setPromptText(titleCombobox); - ((JFXComboBox) comboBox).setLabelFloat(true); + comboBox.setLabelFloat(true); TextField textField = new BisqTextField();