Skip to content

Commit

Permalink
Remove unused method parameters (#3806)
Browse files Browse the repository at this point in the history
* 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.

* 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.

* Suppress warnings of unused method params which may be needed later

Also fix forwarding of telescoping method parameters in FormBuilder and
FormattingUtils.
  • Loading branch information
ripcurlx authored Dec 19, 2019
2 parents 8a279c7 + d0a76b9 commit b5ddb63
Show file tree
Hide file tree
Showing 20 changed files with 58 additions and 86 deletions.
10 changes: 5 additions & 5 deletions core/src/main/java/bisq/core/account/sign/SignedWitness.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@

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;

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;
Expand Down Expand Up @@ -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();
}

Expand All @@ -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
Expand All @@ -107,15 +107,15 @@ public byte[] getHash() {
// Getters
///////////////////////////////////////////////////////////////////////////////////////////

public P2PDataStorage.ByteArray getHashAsByteArray() {
P2PDataStorage.ByteArray getHashAsByteArray() {
return new P2PDataStorage.ByteArray(hash);
}

@Override
public String toString() {
return "AccountAgeWitness{" +
"\n hash=" + Utilities.bytesAsHexString(hash) +
",\n date=" + new Date(date) +
",\n date=" + Instant.ofEpochMilli(date) +
"\n}";
}
}
25 changes: 12 additions & 13 deletions core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1018,7 +1018,6 @@ public Transaction emergencySignAndPublishPayoutTxFrom2of2MultiSig(String deposi
WalletService.verifyTransaction(payoutTx);
WalletService.checkWalletConsistency(wallet);
broadcastTx(payoutTx, callback, 20);
return payoutTx;
}


Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/bisq/core/dao/presentation/DaoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/locale/BankUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/*
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/bisq/core/offer/CreateOfferService.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ public Offer createAndGetOffer(String offerId,
Map<String, String> extraDataMap = OfferUtil.getExtraDataMap(accountAgeWitnessService,
referralIdService,
paymentAccount,
currencyCode,
preferences);
currencyCode);

OfferUtil.validateOfferData(filterManager,
p2PService,
Expand Down
9 changes: 4 additions & 5 deletions core/src/main/java/bisq/core/offer/OfferUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ public static Optional<Volume> getFeeInUserFiatCurrency(Coin makerFee, boolean i
bsqFormatter);
}

public static Optional<Volume> getFeeInUserFiatCurrency(Coin makerFee, boolean isCurrencyForMakerFeeBtc,
String userCurrencyCode, PriceFeedService priceFeedService,
CoinFormatter bsqFormatter) {
private static Optional<Volume> 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.

Expand Down Expand Up @@ -325,8 +325,7 @@ public static Optional<Volume> getFeeInUserFiatCurrency(Coin makerFee, boolean i
public static Map<String, String> getExtraDataMap(AccountAgeWitnessService accountAgeWitnessService,
ReferralIdService referralIdService,
PaymentAccount paymentAccount,
String currencyCode,
Preferences preferences) {
String currencyCode) {
Map<String, String> extraDataMap = new HashMap<>();
if (CurrencyUtil.isFiatCurrency(currencyCode)) {
String myWitnessHashAsHex = accountAgeWitnessService.getMyWitnessHashAsHex(paymentAccount.getPaymentAccountPayload());
Expand Down
15 changes: 6 additions & 9 deletions core/src/main/java/bisq/core/user/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ public Preferences(Storage<PreferencesPayload> 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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/util/FormattingUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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++) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/bisq/core/user/PreferencesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -50,7 +47,6 @@ public class GovernanceDashboardView extends ActivatableView<GridPane, Void> 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;
Expand All @@ -61,11 +57,10 @@ public class GovernanceDashboardView extends ActivatableView<GridPane, Void> 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
Expand Down Expand Up @@ -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));
}
}
Loading

0 comments on commit b5ddb63

Please sign in to comment.