Skip to content

Commit

Permalink
Merge branch 'master' into reduce-BSFormatter-interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Carter authored Nov 19, 2019
2 parents b8730ad + 906a252 commit aa24ddb
Show file tree
Hide file tree
Showing 75 changed files with 2,398 additions and 1,922 deletions.
8 changes: 3 additions & 5 deletions common/src/main/java/bisq/common/app/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.rolling.FixedWindowRollingPolicy;
import ch.qos.logback.core.rolling.RollingFileAppender;
import ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy;
Expand All @@ -38,7 +39,7 @@ public static void setLevel(Level logLevel) {
public static void setup(String fileName) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();

RollingFileAppender appender = new RollingFileAppender();
RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
appender.setContext(loggerContext);
appender.setFile(fileName + ".log");

Expand All @@ -50,7 +51,7 @@ public static void setup(String fileName) {
rollingPolicy.setMaxIndex(10);
rollingPolicy.start();

SizeBasedTriggeringPolicy triggeringPolicy = new SizeBasedTriggeringPolicy();
SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<>();
triggeringPolicy.setMaxFileSize(FileSize.valueOf("10MB"));
triggeringPolicy.start();

Expand All @@ -59,15 +60,12 @@ public static void setup(String fileName) {
encoder.setPattern("%d{MMM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{15}: %msg %xEx%n");
encoder.start();

//noinspection unchecked
appender.setEncoder(encoder);
appender.setRollingPolicy(rollingPolicy);
//noinspection unchecked
appender.setTriggeringPolicy(triggeringPolicy);
appender.start();

logbackLogger = loggerContext.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
//noinspection unchecked
logbackLogger.addAppender(appender);
logbackLogger.setLevel(Level.INFO);

Expand Down
9 changes: 4 additions & 5 deletions common/src/main/java/bisq/common/proto/ProtoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,14 @@ public static <E extends Enum<E>> E enumFromProto(Class<E> enumType, String name
return result;
}

public static <T extends Message> Iterable<T> collectionToProto(Collection<? extends Proto> collection) {
public static <T extends Message> Iterable<T> collectionToProto(Collection<? extends Proto> collection, Class<T> messageType) {
return collection.stream()
.map(e -> {
final Message message = e.toProtoMessage();
try {
//noinspection unchecked
return (T) message;
} catch (Throwable t) {
log.error("message could not be casted. message=" + message);
return messageType.cast(message);
} catch (ClassCastException t) {
log.error("Message could not be cast. message={}, messageType={}", message, messageType);
return null;
}
})
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/app/BisqEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,11 @@ PropertySource<?> getAppDirProperties() throws Exception {
return new ResourcePropertySource(BISQ_APP_DIR_PROPERTY_SOURCE_NAME, resource);
}

private String getProperty (PropertySource properties, String propertyKey, String defaultValue) {
private String getProperty(PropertySource properties, String propertyKey, String defaultValue) {
return properties.containsProperty(propertyKey) ? (String) properties.getProperty(propertyKey) : defaultValue;
}

private List<String> getListProperty (String key, List defaultValue) {
private List<String> getListProperty(String key, List<String> defaultValue) {
final String value = getProperty(key, "");
return value.isEmpty() ? defaultValue : Arrays.asList(StringUtils.deleteWhitespace(value).split(","));
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/btc/setup/WalletConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import com.google.common.util.concurrent.AbstractIdleService;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;

import java.net.InetAddress;
import java.net.InetSocketAddress;
Expand Down Expand Up @@ -465,7 +466,7 @@ protected void startUp() throws Exception {
vPeerGroup.startBlockChainDownload(listener);
listener.await();
} else {
Futures.addCallback(vPeerGroup.startAsync(), new FutureCallback() {
Futures.addCallback((ListenableFuture<?>) vPeerGroup.startAsync(), new FutureCallback<Object>() {
@Override
public void onSuccess(@Nullable Object result) {
final PeerDataEventListener listener = downloadListener == null ?
Expand All @@ -476,7 +477,6 @@ public void onSuccess(@Nullable Object result) {
@Override
public void onFailure(@NotNull Throwable t) {
throw new RuntimeException(t);

}
});
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/payment/PaymentAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public protobuf.PaymentAccount toProtoMessage() {
.setCreationDate(creationDate)
.setPaymentAccountPayload((protobuf.PaymentAccountPayload) paymentAccountPayload.toProtoMessage())
.setAccountName(accountName)
.addAllTradeCurrencies(ProtoUtil.<protobuf.TradeCurrency>collectionToProto(tradeCurrencies));
.addAllTradeCurrencies(ProtoUtil.collectionToProto(tradeCurrencies, protobuf.TradeCurrency.class));
Optional.ofNullable(selectedTradeCurrency).ifPresent(selectedTradeCurrency -> builder.setSelectedTradeCurrency((protobuf.TradeCurrency) selectedTradeCurrency.toProtoMessage()));
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static boolean isAmountValidForOffer(Offer offer,
AccountAgeWitnessService accountAgeWitnessService) {
boolean hasChargebackRisk = PaymentMethod.hasChargebackRisk(offer.getPaymentMethod(), offer.getCurrencyCode());
boolean hasValidAccountAgeWitness = accountAgeWitnessService.getMyTradeLimit(paymentAccount,
offer.getCurrencyCode(), offer.getMirroredDirection()) >= offer.getAmount().value;
offer.getCurrencyCode(), offer.getMirroredDirection()) >= offer.getMinAmount().value;
return !hasChargebackRisk || hasValidAccountAgeWitness;
}

Expand Down
7 changes: 3 additions & 4 deletions core/src/main/java/bisq/core/provider/fee/FeeProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,15 @@ public FeeProvider(PriceNodeHttpClient httpClient, ProvidersRepository providers
public Tuple2<Map<String, Long>, Map<String, Long>> getFees() throws IOException {
String json = httpClient.requestWithGET("getFees", "User-Agent", "bisq/" + Version.VERSION + ", uid:" + httpClient.getUid());

LinkedTreeMap<String, Object> linkedTreeMap = new Gson().<LinkedTreeMap<String, Object>>fromJson(json, LinkedTreeMap.class);
LinkedTreeMap<?, ?> linkedTreeMap = new Gson().fromJson(json, LinkedTreeMap.class);
Map<String, Long> tsMap = new HashMap<>();
tsMap.put("bitcoinFeesTs", ((Double) linkedTreeMap.get("bitcoinFeesTs")).longValue());

Map<String, Long> map = new HashMap<>();

try {
//noinspection unchecked
LinkedTreeMap<String, Double> dataMap = (LinkedTreeMap<String, Double>) linkedTreeMap.get("dataMap");
Long btcTxFee = dataMap.get("btcTxFee").longValue();
LinkedTreeMap<?, ?> dataMap = (LinkedTreeMap<?, ?>) linkedTreeMap.get("dataMap");
Long btcTxFee = ((Double) dataMap.get("btcTxFee")).longValue();

map.put("BTC", btcTxFee);
} catch (Throwable t) {
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/java/bisq/core/provider/price/PriceProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ public Tuple2<Map<String, Long>, Map<String, MarketPrice>> getAll() throws IOExc
String json = httpClient.requestWithGET("getAllMarketPrices", "User-Agent", "bisq/"
+ Version.VERSION + ", uid:" + httpClient.getUid());

LinkedTreeMap<String, Object> map = new Gson().<LinkedTreeMap<String, Object>>fromJson(json, LinkedTreeMap.class);
LinkedTreeMap<?, ?> map = new Gson().fromJson(json, LinkedTreeMap.class);
Map<String, Long> tsMap = new HashMap<>();
tsMap.put("btcAverageTs", ((Double) map.get("btcAverageTs")).longValue());
tsMap.put("poloniexTs", ((Double) map.get("poloniexTs")).longValue());
tsMap.put("coinmarketcapTs", ((Double) map.get("coinmarketcapTs")).longValue());

//noinspection unchecked
List<LinkedTreeMap<String, Object>> list = (ArrayList<LinkedTreeMap<String, Object>>) map.get("data");
list.forEach(treeMap -> {
List<?> list = (ArrayList<?>) map.get("data");
list.forEach(obj -> {
try {
LinkedTreeMap<?, ?> treeMap = (LinkedTreeMap<?, ?>) obj;
final String currencyCode = (String) treeMap.get("currencyCode");
final double price = (double) treeMap.get("price");
final double price = (Double) treeMap.get("price");
// json uses double for our timestampSec long value...
final long timestampSec = MathUtils.doubleToLong((double) treeMap.get("timestampSec"));
final long timestampSec = MathUtils.doubleToLong((Double) treeMap.get("timestampSec"));
marketPriceMap.put(currencyCode, new MarketPrice(currencyCode, price, timestampSec, true));
} catch (Throwable t) {
log.error(t.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Message toProtoMessage() {
list.forEach(dispute -> checkArgument(dispute.getSupportType().equals(SupportType.ARBITRATION), "Support type has to be ARBITRATION"));

return protobuf.PersistableEnvelope.newBuilder().setArbitrationDisputeList(protobuf.ArbitrationDisputeList.newBuilder()
.addAllDispute(ProtoUtil.collectionToProto(new ArrayList<>(list)))).build();
.addAllDispute(ProtoUtil.collectionToProto(new ArrayList<>(list), protobuf.Dispute.class))).build();
}

public static ArbitrationDisputeList fromProto(protobuf.ArbitrationDisputeList proto,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private MediationDisputeList(Storage<MediationDisputeList> storage, List<Dispute
@Override
public Message toProtoMessage() {
return protobuf.PersistableEnvelope.newBuilder().setMediationDisputeList(protobuf.MediationDisputeList.newBuilder()
.addAllDispute(ProtoUtil.collectionToProto(new ArrayList<>(list)))).build();
.addAllDispute(ProtoUtil.collectionToProto(new ArrayList<>(list), protobuf.Dispute.class))).build();
}

public static MediationDisputeList fromProto(protobuf.MediationDisputeList proto,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Message toProtoMessage() {
list.forEach(dispute -> checkArgument(dispute.getSupportType().equals(SupportType.REFUND), "Support type has to be REFUND"));

return protobuf.PersistableEnvelope.newBuilder().setRefundDisputeList(protobuf.RefundDisputeList.newBuilder()
.addAllDispute(ProtoUtil.collectionToProto(new ArrayList<>(list)))).build();
.addAllDispute(ProtoUtil.collectionToProto(new ArrayList<>(list), protobuf.Dispute.class))).build();
}

public static RefundDisputeList fromProto(protobuf.RefundDisputeList proto,
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/trade/TradableList.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Message toProtoMessage() {
ArrayList<T> clonedList = new ArrayList<>(this.list);
return protobuf.PersistableEnvelope.newBuilder()
.setTradableList(protobuf.TradableList.newBuilder()
.addAllTradable(ProtoUtil.collectionToProto(clonedList)))
.addAllTradable(ProtoUtil.collectionToProto(clonedList, protobuf.Tradable.class)))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ public protobuf.ProcessModel toProtoMessage() {
Optional.ofNullable(takeOfferFeeTxId).ifPresent(builder::setTakeOfferFeeTxId);
Optional.ofNullable(payoutTxSignature).ifPresent(e -> builder.setPayoutTxSignature(ByteString.copyFrom(payoutTxSignature)));
Optional.ofNullable(preparedDepositTx).ifPresent(e -> builder.setPreparedDepositTx(ByteString.copyFrom(preparedDepositTx)));
Optional.ofNullable(rawTransactionInputs).ifPresent(e -> builder.addAllRawTransactionInputs(ProtoUtil.collectionToProto(rawTransactionInputs)));
Optional.ofNullable(rawTransactionInputs).ifPresent(e -> builder.addAllRawTransactionInputs(
ProtoUtil.collectionToProto(rawTransactionInputs, protobuf.RawTransactionInput.class)));
Optional.ofNullable(changeOutputAddress).ifPresent(builder::setChangeOutputAddress);
Optional.ofNullable(myMultiSigPubKey).ifPresent(e -> builder.setMyMultiSigPubKey(ByteString.copyFrom(myMultiSigPubKey)));
Optional.ofNullable(tempTradingPeerNodeAddress).ifPresent(e -> builder.setTempTradingPeerNodeAddress(tempTradingPeerNodeAddress.toProtoMessage()));
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/bisq/core/trade/protocol/TradingPeer.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public Message toProtoMessage() {
Optional.ofNullable(signature).ifPresent(e -> builder.setSignature(ByteString.copyFrom(e)));
Optional.ofNullable(pubKeyRing).ifPresent(e -> builder.setPubKeyRing(e.toProtoMessage()));
Optional.ofNullable(multiSigPubKey).ifPresent(e -> builder.setMultiSigPubKey(ByteString.copyFrom(e)));
Optional.ofNullable(rawTransactionInputs).ifPresent(e -> builder.addAllRawTransactionInputs(ProtoUtil.collectionToProto(e)));
Optional.ofNullable(rawTransactionInputs).ifPresent(e -> builder.addAllRawTransactionInputs(
ProtoUtil.collectionToProto(e, protobuf.RawTransactionInput.class)));
Optional.ofNullable(changeOutputAddress).ifPresent(builder::setChangeOutputAddress);
Optional.ofNullable(accountAgeWitnessNonce).ifPresent(e -> builder.setAccountAgeWitnessNonce(ByteString.copyFrom(e)));
Optional.ofNullable(accountAgeWitnessSignature).ifPresent(e -> builder.setAccountAgeWitnessSignature(ByteString.copyFrom(e)));
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/user/UserPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public protobuf.PersistableEnvelope toProtoMessage() {
protobuf.UserPayload.Builder builder = protobuf.UserPayload.newBuilder();
Optional.ofNullable(accountId).ifPresent(e -> builder.setAccountId(accountId));
Optional.ofNullable(paymentAccounts)
.ifPresent(e -> builder.addAllPaymentAccounts(ProtoUtil.collectionToProto(paymentAccounts)));
.ifPresent(e -> builder.addAllPaymentAccounts(ProtoUtil.collectionToProto(paymentAccounts, protobuf.PaymentAccount.class)));
Optional.ofNullable(currentPaymentAccount)
.ifPresent(e -> builder.setCurrentPaymentAccount(currentPaymentAccount.toProtoMessage()));
Optional.ofNullable(acceptedLanguageLocaleCodes)
Expand All @@ -111,7 +111,7 @@ public protobuf.PersistableEnvelope toProtoMessage() {
message -> ((protobuf.StoragePayload) message).getMediator())));
Optional.ofNullable(priceAlertFilter).ifPresent(priceAlertFilter -> builder.setPriceAlertFilter(priceAlertFilter.toProtoMessage()));
Optional.ofNullable(marketAlertFilters)
.ifPresent(e -> builder.addAllMarketAlertFilters(ProtoUtil.collectionToProto(marketAlertFilters)));
.ifPresent(e -> builder.addAllMarketAlertFilters(ProtoUtil.collectionToProto(marketAlertFilters, protobuf.MarketAlertFilter.class)));

Optional.ofNullable(registeredRefundAgent)
.ifPresent(registeredRefundAgent -> builder.setRegisteredRefundAgent(registeredRefundAgent.toProtoMessage().getRefundAgent()));
Expand Down
8 changes: 3 additions & 5 deletions desktop/src/main/java/bisq/desktop/Navigation.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ public void readPersisted() {
List<Class<? extends View>> viewClasses = persisted.getPath().stream()
.map(className -> {
try {
//noinspection unchecked
return ((Class<? extends View>) Class.forName(className));
return (Class<? extends View>) Class.forName(className).asSubclass(View.class);
} catch (ClassNotFoundException e) {
log.warn("Could not find the viewPath class {}; exception: {}", className, e);
}
Expand Down Expand Up @@ -118,13 +117,12 @@ public void navigateTo(ViewPath newPath, @Nullable Object data) {
Class<? extends View> viewClass = newPath.get(i);
temp.add(viewClass);
if (currentPath == null ||
(currentPath != null &&
currentPath.size() > i &&
(currentPath.size() > i &&
viewClass != currentPath.get(i) &&
i != newPath.size() - 1)) {
ArrayList<Class<? extends View>> temp2 = new ArrayList<>(temp);
for (int n = i + 1; n < newPath.size(); n++) {
//noinspection unchecked,unchecked,unchecked
//noinspection unchecked
Class<? extends View>[] newTemp = new Class[i + 1];
currentPath = ViewPath.to(temp2.toArray(newTemp));
navigateTo(currentPath, data);
Expand Down
12 changes: 0 additions & 12 deletions desktop/src/main/java/bisq/desktop/common/model/Activatable.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,4 @@ public interface Activatable {
void _activate();

void _deactivate();


Activatable NO_OP_INSTANCE = new Activatable() {
@Override
public void _activate() {
}

@Override
public void _deactivate() {
}
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ public ActivatableViewAndModel(M model) {
super(checkNotNull(model, "Model must not be null"));
}

public ActivatableViewAndModel() {
//noinspection unchecked
this((M) Activatable.NO_OP_INSTANCE);
}

@Override
protected void prepareInitialize() {
if (root != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
public class AutocompleteComboBox<T> extends JFXComboBox<T> {
private ArrayList<T> completeList;
private ArrayList<T> matchingList;
private JFXComboBoxListViewSkin comboBoxListViewSkin;
private JFXComboBoxListViewSkin<T> comboBoxListViewSkin;

public AutocompleteComboBox() {
this(FXCollections.observableArrayList());
Expand All @@ -65,7 +65,7 @@ private AutocompleteComboBox(ObservableList<T> items) {
/**
* Set the complete list of ComboBox items. Use this instead of setItems().
*/
public void setAutocompleteItems(List<T> items) {
public void setAutocompleteItems(List<? extends T> items) {
completeList = new ArrayList<>(items);
matchingList = new ArrayList<>(completeList);
setValue(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,11 @@ protected void addTradeCurrencyComboBox() {
currencyComboBox.setPromptText("");
});

((AutocompleteComboBox) currencyComboBox).setAutocompleteItems(CurrencyUtil.getActiveSortedCryptoCurrencies(assetService, filterManager));
((AutocompleteComboBox<TradeCurrency>) currencyComboBox).setAutocompleteItems(
CurrencyUtil.getActiveSortedCryptoCurrencies(assetService, filterManager));
currencyComboBox.setVisibleRowCount(Math.min(currencyComboBox.getItems().size(), 10));

currencyComboBox.setConverter(new StringConverter<TradeCurrency>() {
currencyComboBox.setConverter(new StringConverter<>() {
@Override
public String toString(TradeCurrency tradeCurrency) {
return tradeCurrency != null ? tradeCurrency.getNameAndCode() : "";
Expand All @@ -223,12 +224,12 @@ public String toString(TradeCurrency tradeCurrency) {
@Override
public TradeCurrency fromString(String s) {
return currencyComboBox.getItems().stream().
filter(item -> item.getNameAndCode().equals(s)).
findAny().orElse(null);
filter(item -> item.getNameAndCode().equals(s)).
findAny().orElse(null);
}
});

((AutocompleteComboBox) currencyComboBox).setOnChangeConfirmed(e -> {
((AutocompleteComboBox<?>) currencyComboBox).setOnChangeConfirmed(e -> {
addressInputTextField.resetValidation();
addressInputTextField.validate();
paymentAccount.setSingleTradeCurrency(currencyComboBox.getSelectionModel().getSelectedItem());
Expand Down
Loading

0 comments on commit aa24ddb

Please sign in to comment.