Use ProtoUtil.protoToNullableString and protoToToNullableByteArray instead of isEmpty checks and null assignement.

Use fromProto for BlockChainExplorer, Country, CryptoCurrency, FiatCurrency
Use @EqualsAndHashCode(callSuper = true) for PaymentAccounts
Replace Samenknoten with Seednodes in german translation
Clean up PB definitions.
This commit is contained in:
Manfred Karrer 2017-06-07 20:25:38 +02:00
parent 1e01ef3650
commit 22d90f627c
44 changed files with 394 additions and 361 deletions

View File

@ -24,6 +24,6 @@ import java.io.Serializable;
/**
* Base interface for Envelope and Payload.
*/
interface Proto extends Serializable {
public interface Proto extends Serializable {
Message toProtoMessage();
}

View File

@ -44,4 +44,10 @@ public final class Country implements PersistablePayload {
return PB.Country.newBuilder().setCode(code).setName(name)
.setRegion(PB.Region.newBuilder().setCode(region.code).setName(region.name)).build();
}
public static Country fromProto(PB.Country proto) {
return new Country(proto.getCode(),
proto.getName(),
Region.fromProto(proto.getRegion()));
}
}

View File

@ -21,8 +21,6 @@ import com.google.protobuf.Message;
import io.bisq.generated.protobuffer.PB;
import lombok.Getter;
import java.util.Optional;
public final class CryptoCurrency extends TradeCurrency {
// http://boschista.deviantart.com/journal/Cool-ASCII-Symbols-214218618
private final static String PREFIX = "";
@ -30,32 +28,53 @@ public final class CryptoCurrency extends TradeCurrency {
@Getter
private boolean isAsset = false;
public CryptoCurrency(String currencyCode, String name) {
public CryptoCurrency(String currencyCode,
String name) {
this(currencyCode, name, false);
}
public CryptoCurrency(String currencyCode, String name, boolean isAsset) {
public CryptoCurrency(String currencyCode,
String name,
boolean isAsset) {
super(currencyCode, name);
this.isAsset = isAsset;
}
public CryptoCurrency(String currencyCode, String name, String symbol, boolean isAsset) {
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private CryptoCurrency(String currencyCode,
String name,
String symbol,
boolean isAsset) {
super(currencyCode, name, symbol);
this.isAsset = isAsset;
}
@Override
public Message toProtoMessage() {
return getTradeCurrencyBuilder()
.setCryptoCurrency(PB.CryptoCurrency.newBuilder()
.setIsAsset(isAsset))
.build();
}
public static CryptoCurrency fromProto(PB.TradeCurrency proto) {
return new CryptoCurrency(proto.getCode(),
proto.getName(),
proto.getSymbol(),
proto.getCryptoCurrency().getIsAsset());
}
///////////////////////////////////////////////////////////////////////////////////////////
// API
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public String getDisplayPrefix() {
return PREFIX;
}
@Override
public Message toProtoMessage() {
PB.TradeCurrency.Builder builder = PB.TradeCurrency.newBuilder()
.setCode(code)
.setName(name)
.setCryptoCurrency(PB.CryptoCurrency.newBuilder().setIsAsset(isAsset));
Optional.ofNullable(symbol).ifPresent(builder::setSymbol);
return builder.build();
}
}

View File

@ -26,7 +26,6 @@ import lombok.ToString;
import java.util.Currency;
import java.util.Locale;
import java.util.Optional;
@EqualsAndHashCode(callSuper = true)
@ToString
@ -52,6 +51,29 @@ public final class FiatCurrency extends TradeCurrency {
this.currency = currency;
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public Message toProtoMessage() {
PB.Currency.Builder currencyBuilder = PB.Currency.newBuilder().setCurrencyCode(currency.getCurrencyCode());
PB.FiatCurrency.Builder fiatCurrencyBuilder = PB.FiatCurrency.newBuilder().setCurrency(currencyBuilder);
return getTradeCurrencyBuilder()
.setFiatCurrency(fiatCurrencyBuilder)
.build();
}
public static FiatCurrency fromProto(PB.TradeCurrency proto) {
return new FiatCurrency(proto.getCode());
}
///////////////////////////////////////////////////////////////////////////////////////////
// API
///////////////////////////////////////////////////////////////////////////////////////////
private static Locale getLocale() {
return GlobalSettings.getLocale();
}
@ -61,16 +83,4 @@ public final class FiatCurrency extends TradeCurrency {
return PREFIX;
}
@Override
public Message toProtoMessage() {
PB.Currency.Builder currencyBuilder = PB.Currency.newBuilder().setCurrencyCode(currency.getCurrencyCode());
PB.FiatCurrency.Builder fiatCurrencyBuilder = PB.FiatCurrency.newBuilder().setCurrency(currencyBuilder);
PB.TradeCurrency.Builder builder = PB.TradeCurrency.newBuilder()
.setCode(code)
.setName(name)
.setFiatCurrency(fiatCurrencyBuilder);
Optional.ofNullable(symbol).ifPresent(builder::setSymbol);
return builder.build();
}
}

View File

@ -41,4 +41,8 @@ public final class Region implements PersistablePayload {
public Message toProtoMessage() {
return PB.Region.newBuilder().setCode(code).setName(name).build();
}
public static Region fromProto(PB.Region proto) {
return new Region(proto.getCode(), proto.getName());
}
}

View File

@ -27,6 +27,7 @@ import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.util.Optional;
@EqualsAndHashCode
@ToString
@ -55,17 +56,22 @@ public abstract class TradeCurrency implements PersistablePayload, Comparable<Tr
public static TradeCurrency fromProto(PB.TradeCurrency proto) {
switch (proto.getMessageCase()) {
case FIAT_CURRENCY:
return new FiatCurrency(proto.getCode());
return FiatCurrency.fromProto(proto);
case CRYPTO_CURRENCY:
return new CryptoCurrency(proto.getCode(),
proto.getName(),
proto.getSymbol(),
proto.getCryptoCurrency().getIsAsset());
return CryptoCurrency.fromProto(proto);
default:
throw new ProtobufferException("Unknown message case: " + proto.getMessageCase());
}
}
public PB.TradeCurrency.Builder getTradeCurrencyBuilder() {
PB.TradeCurrency.Builder builder = PB.TradeCurrency.newBuilder()
.setCode(code)
.setName(name);
Optional.ofNullable(symbol).ifPresent(builder::setSymbol);
return builder;
}
///////////////////////////////////////////////////////////////////////////////////////////
// API

View File

@ -19,11 +19,12 @@ package io.bisq.common.proto;
import com.google.protobuf.ByteString;
import com.google.protobuf.Message;
import io.bisq.common.Payload;
import io.bisq.common.Proto;
import io.bisq.common.locale.CurrencyUtil;
import io.bisq.generated.protobuffer.PB;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;
import java.util.Set;
@ -45,8 +46,14 @@ public class ProtoUtil {
* Returns the input String, except when it's the empty string: "", then null is returned.
* Note: "" is the default value for a protobuffer string, so this means it's not filled in.
*/
public static String emptyStringToNull(String stringFromProto) {
return "".equals(stringFromProto) ? null : stringFromProto;
@Nullable
public static String protoToNullableString(String proto) {
return "".equals(proto) ? null : proto;
}
@Nullable
public static byte[] protoToToNullableByteArray(ByteString proto) {
return proto.isEmpty() ? null : proto.toByteArray();
}
public static <E extends Enum<E>> E enumFromProto(Class<E> e, String id) {
@ -60,7 +67,7 @@ public class ProtoUtil {
return result;
}
public static <T extends Message> Iterable<T> collectionToProto(Collection<? extends Payload> collection) {
public static <T extends Message> Iterable<T> collectionToProto(Collection<? extends Proto> collection) {
return collection.stream()
.map(e -> {
final Message message = e.toProtoMessage();
@ -76,7 +83,7 @@ public class ProtoUtil {
.collect(Collectors.toList());
}
public static <T> Iterable<T> collectionToProto(Collection<? extends Payload> collection, Function<? super Message, T> extra) {
public static <T> Iterable<T> collectionToProto(Collection<? extends Proto> collection, Function<? super Message, T> extra) {
return collection.stream().map(o -> extra.apply(o.toProtoMessage())).collect(Collectors.toList());
}
}

View File

@ -17,7 +17,6 @@
package io.bisq.common.proto.persistable;
import com.google.common.collect.Lists;
import com.google.protobuf.Message;
import io.bisq.generated.protobuffer.PB;
import lombok.*;
@ -32,7 +31,7 @@ import java.util.List;
@Getter
@Setter
public class NavigationPath implements PersistableEnvelope {
private List<String> path = Lists.newArrayList();
private List<String> path = new ArrayList<>();
@Override
public Message toProtoMessage() {

View File

@ -790,12 +790,16 @@ message PersistableEnvelope {
PersistedEntryMap persisted_entry_map = 2;
PeerList peer_list = 3;
AddressEntryList address_entry_list = 4;
TradableList tradable_list = 5;
TradeStatisticsList trade_statistics_list = 6;
DisputeList dispute_list = 7;
PreferencesPayload preferences_payload = 8;
UserPayload user_payload = 9;
NavigationPath navigation_path = 10;
NavigationPath navigation_path = 5;
TradableList tradable_list = 6;
TradeStatisticsList trade_statistics_list = 7;
DisputeList dispute_list = 8;
PreferencesPayload preferences_payload = 9;
UserPayload user_payload = 10;
// TODO not fully implemented yet
CompensationRequestPayload compensation_request_payload = 11;
VoteItemsList vote_items_list = 12;
BsqChainState bsq_chain_state = 13;
@ -804,69 +808,38 @@ message PersistableEnvelope {
///////////////////////////////////////////////////////////////////////////////////////////
// Preferences
// Collections
///////////////////////////////////////////////////////////////////////////////////////////
message PreferencesPayload {
string user_language = 1;
Country user_country = 2;
repeated TradeCurrency fiat_currencies = 3;
repeated TradeCurrency crypto_currencies = 4;
BlockChainExplorer block_chain_explorer_main_net = 5;
BlockChainExplorer block_chain_explorer_test_net = 6;
BlockChainExplorer bsq_block_chain_explorer = 7;
string backup_directory = 8;
bool auto_select_arbitrators = 9;
map<string, bool> dont_show_again_map = 10;
bool tac_accepted = 11;
bool use_tor_for_bitcoin_j = 12;
bool show_own_offers_in_offer_book = 13;
TradeCurrency preferred_trade_currency = 14;
int64 withdrawal_tx_fee_in_bytes = 15;
bool use_custom_withdrawal_tx_fee = 16;
double max_price_distance_in_percent = 17;
string offer_book_chart_screen_currency_code = 18;
string trade_charts_screen_currency_code = 19;
string buy_screen_currency_code = 20;
string sell_screen_currency_code = 21;
int32 trade_statistics_tick_unit_index = 22;
bool resync_Spv_requested = 23;
bool sort_market_currencies_numerically = 24;
bool use_percentage_based_price = 25;
map<string, string> peer_tag_map = 26;
string bitcoin_nodes = 27;
repeated string ignore_traders_list = 28;
string directory_chooser_path = 29;
int64 buyer_security_deposit_as_long = 30;
string btc_denomination = 31;
bool use_animations = 32;
PaymentAccount selectedPayment_account_for_createOffer = 33;
bool pay_fee_in_Btc = 34;
message SequenceNumberMap {
repeated SequenceNumberEntry sequence_number_entries = 1;
}
///////////////////////////////////////////////////////////////////////////////////////////
// UserPayload
///////////////////////////////////////////////////////////////////////////////////////////
message UserPayload {
string account_id = 1;
repeated PaymentAccount payment_accounts = 2;
PaymentAccount current_payment_account = 3;
repeated string accepted_language_locale_codes = 4;
Alert developers_alert = 5;
Alert displayed_alert = 6;
Filter developers_filter = 7;
repeated Arbitrator accepted_arbitrators = 8;
repeated Mediator accepted_mediators = 9;
Arbitrator registered_arbitrator = 10;
Mediator registered_mediator = 11;
message SequenceNumberEntry {
ByteArray bytes = 1;
MapValue map_value = 2;
}
message ByteArray {
bytes bytes = 1;
}
///////////////////////////////////////////////////////////////////////////////////////////
// AddressEntry
///////////////////////////////////////////////////////////////////////////////////////////
message MapValue {
int32 sequence_nr = 1;
int64 time_stamp = 2;
}
message PersistedEntryMap {
map<string, ProtectedStorageEntry> persisted_entry_map = 1;
}
message PeerList {
repeated Peer peer = 1;
}
message AddressEntryList {
repeated AddressEntry address_entry = 1;
}
message AddressEntry {
enum Context {
@ -886,8 +859,8 @@ message AddressEntry {
int64 coin_locked_in_multi_sig = 11;
}
message AddressEntryList {
repeated AddressEntry address_entry = 1;
message NavigationPath {
repeated string path = 1;
}
@ -895,6 +868,14 @@ message AddressEntryList {
// Offer/Trade
///////////////////////////////////////////////////////////////////////////////////////////
message TradableList {
repeated Tradable tradable = 1;
}
message TradeStatisticsList {
repeated TradeStatistics trade_statistics = 1;
}
message Offer {
enum State {
PB_ERROR = 0;
@ -932,9 +913,7 @@ message Tradable {
}
}
message TradableList {
repeated Tradable tradable = 1;
}
message Trade {
enum State {
@ -1033,10 +1012,6 @@ message BuyerAsTakerTrade {
Trade trade = 1;
}
message SellerTrade {
Trade trade = 1;
}
message SellerAsMakerTrade {
Trade trade = 1;
}
@ -1078,23 +1053,78 @@ message TradingPeer {
string change_output_address = 11;
}
message TradeStatisticsList {
repeated TradeStatistics trade_statistics = 1;
}
message PendingTradeList {
repeated Trade trade = 1;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Dispute
///////////////////////////////////////////////////////////////////////////////////////////
message ClosedTradeList {
repeated Trade trade = 1;
}
message FailedTradeList {
repeated Trade trade = 1;
message DisputeList {
repeated Dispute dispute = 1;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Preferences
///////////////////////////////////////////////////////////////////////////////////////////
message PreferencesPayload {
string user_language = 1;
Country user_country = 2;
repeated TradeCurrency fiat_currencies = 3;
repeated TradeCurrency crypto_currencies = 4;
BlockChainExplorer block_chain_explorer_main_net = 5;
BlockChainExplorer block_chain_explorer_test_net = 6;
BlockChainExplorer bsq_block_chain_explorer = 7;
string backup_directory = 8;
bool auto_select_arbitrators = 9;
map<string, bool> dont_show_again_map = 10;
bool tac_accepted = 11;
bool use_tor_for_bitcoin_j = 12;
bool show_own_offers_in_offer_book = 13;
TradeCurrency preferred_trade_currency = 14;
int64 withdrawal_tx_fee_in_bytes = 15;
bool use_custom_withdrawal_tx_fee = 16;
double max_price_distance_in_percent = 17;
string offer_book_chart_screen_currency_code = 18;
string trade_charts_screen_currency_code = 19;
string buy_screen_currency_code = 20;
string sell_screen_currency_code = 21;
int32 trade_statistics_tick_unit_index = 22;
bool resync_Spv_requested = 23;
bool sort_market_currencies_numerically = 24;
bool use_percentage_based_price = 25;
map<string, string> peer_tag_map = 26;
string bitcoin_nodes = 27;
repeated string ignore_traders_list = 28;
string directory_chooser_path = 29;
int64 buyer_security_deposit_as_long = 30;
string btc_denomination = 31;
bool use_animations = 32;
PaymentAccount selectedPayment_account_for_createOffer = 33;
bool pay_fee_in_Btc = 34;
}
///////////////////////////////////////////////////////////////////////////////////////////
// UserPayload
///////////////////////////////////////////////////////////////////////////////////////////
message UserPayload {
string account_id = 1;
repeated PaymentAccount payment_accounts = 2;
PaymentAccount current_payment_account = 3;
repeated string accepted_language_locale_codes = 4;
Alert developers_alert = 5;
Alert displayed_alert = 6;
Filter developers_filter = 7;
repeated Arbitrator accepted_arbitrators = 8;
repeated Mediator accepted_mediators = 9;
Arbitrator registered_arbitrator = 10;
Mediator registered_mediator = 11;
}
// TODO fully implemented yet
///////////////////////////////////////////////////////////////////////////////////////////
// DAO
///////////////////////////////////////////////////////////////////////////////////////////
@ -1157,54 +1187,17 @@ message CompensationRequestVoteItemCollection {
}
///////////////////////////////////////////////////////////////////////////////////////////
// Misc
///////////////////////////////////////////////////////////////////////////////////////////
message Transaction {
bytes hash = 1;
}
message PeerList {
repeated Peer peer = 1;
}
message PersistedEntryMap {
map<string, ProtectedStorageEntry> persisted_entry_map = 1;
}
message SequenceNumberMap {
repeated SequenceNumberEntry sequence_number_entries = 1;
}
message SequenceNumberEntry {
ByteArray bytes = 1;
MapValue map_value = 2;
}
message MapValue {
int32 sequence_nr = 1;
int64 time_stamp = 2;
}
message BlockChainExplorer {
string name = 1;
string tx_url = 2;
string address_url = 3;
}
message ByteArray {
bytes bytes = 1;
}
message NavigationPath {
repeated string path = 1;
}
message DisputeList {
repeated Dispute dispute = 1;
}
message PaymentAccount {
string id = 1;
int64 creation_date = 2;
@ -1221,7 +1214,6 @@ message PaymentMethod {
int64 max_trade_limit = 3;
}
// Currency
message Currency {
@ -1246,15 +1238,6 @@ message FiatCurrency {
Currency currency = 1;
}
// Locale
message Locale {
string language = 1;
string country = 2;
string variant = 3;
}
message Country {
string code = 1;
string name = 2;
@ -1267,6 +1250,7 @@ message Region {
}
///////////////////////////////////////////////////////////////////////////////////////////
// Mock
///////////////////////////////////////////////////////////////////////////////////////////

View File

@ -226,11 +226,11 @@ mainView.bootstrapState.torNodeCreated=Torknoten erstellt
mainView.bootstrapState.hiddenServicePublished=Versteckter Dienst veröffentlicht
mainView.bootstrapState.initialDataReceived=Anfangsdaten erhalten
mainView.bootstrapWarning.noSeedNodesAvailable=Keine Samenknoten verfügbar
mainView.bootstrapWarning.noNodesAvailable=Keine Samenknoten und Peers verfügbar
mainView.bootstrapWarning.noSeedNodesAvailable=Keine Seednodes verfügbar
mainView.bootstrapWarning.noNodesAvailable=Keine Seednodes und Peers verfügbar
mainView.bootstrapWarning.bootstrappingToP2PFailed=Verbindungsherstellung zum P2P Netzwerk fehlgeschlagen
mainView.p2pNetworkWarnMsg.noNodesAvailable=Es sind keine Samenknoten oder andauernde Peers verfügbar um Daten anzufordern.\nÜberprüfen sie bitte ihre Internetverbindung oder versuchen sie die Anwendung neu zu starten.
mainView.p2pNetworkWarnMsg.noNodesAvailable=Es sind keine Seednodes oder andauernde Peers verfügbar um Daten anzufordern.\nÜberprüfen sie bitte ihre Internetverbindung oder versuchen sie die Anwendung neu zu starten.
mainView.p2pNetworkWarnMsg.connectionToP2PFailed=Verbinden mit P2P Netzwerk fehlgeschlagen (gemeldeter Fehler\: {0}).\nBitte überprüfen sie ihre Internetverbindungen oder versuchen sie die Anwendung neu zu starten.
mainView.walletServiceErrorMsg.timeout=Verbinden mit Bitcoinnetzwerk fehlgeschlagen, aufgrund von timeout.
@ -711,7 +711,7 @@ settings.net.needRestart=Sie müssen die Anwendung neu starten, um die Änderung
settings.net.notKnownYet=Noch nicht bekannt...
settings.net.sentReceived=Gesendet\: {0}, erhalten\: {1}
settings.net.ips=Per Komma getrennt IP Adressen hinzufügen
settings.net.seedNode=Samenknoten
settings.net.seedNode=Seednodes
settings.net.directPeer=Peer (direkt)
settings.net.peer=Peer
settings.net.inbound=eingehend

View File

@ -19,6 +19,7 @@ package io.bisq.core.arbitration;
import com.google.protobuf.ByteString;
import io.bisq.common.crypto.PubKeyRing;
import io.bisq.common.proto.ProtoUtil;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.NodeAddress;
import io.bisq.network.p2p.storage.payload.StoragePayload;
@ -115,8 +116,8 @@ public final class Arbitrator implements StoragePayload {
proto.getRegistrationDate(),
proto.getRegistrationPubKey().toByteArray(),
proto.getRegistrationSignature(),
proto.getEmailAddress().isEmpty() ? null : proto.getEmailAddress(),
proto.getInfo().isEmpty() ? null : proto.getInfo(),
ProtoUtil.protoToNullableString(proto.getEmailAddress()),
ProtoUtil.protoToNullableString(proto.getInfo()),
CollectionUtils.isEmpty(proto.getExtraDataMap()) ? null : proto.getExtraDataMap());
}

View File

@ -19,6 +19,7 @@ package io.bisq.core.arbitration;
import com.google.protobuf.ByteString;
import io.bisq.common.crypto.PubKeyRing;
import io.bisq.common.proto.ProtoUtil;
import io.bisq.common.proto.network.NetworkPayload;
import io.bisq.common.storage.Storage;
import io.bisq.common.util.Utilities;
@ -205,14 +206,14 @@ public final class Dispute implements NetworkPayload {
PubKeyRing.fromProto(proto.getTraderPubKeyRing()),
proto.getTradeDate(),
Contract.fromProto(proto.getContract(), coreProtoResolver),
proto.getContractHash().toByteArray().length == 0 ? null : proto.getContractHash().toByteArray(),
proto.getDepositTxSerialized().toByteArray().length == 0 ? null : proto.getDepositTxSerialized().toByteArray(),
proto.getPayoutTxSerialized().toByteArray().length == 0 ? null : proto.getPayoutTxSerialized().toByteArray(),
proto.getDepositTxId().isEmpty() ? null : proto.getDepositTxId(),
proto.getPayoutTxId().isEmpty() ? null : proto.getPayoutTxId(),
ProtoUtil.protoToToNullableByteArray(proto.getContractHash()),
ProtoUtil.protoToToNullableByteArray(proto.getDepositTxSerialized()),
ProtoUtil.protoToToNullableByteArray(proto.getPayoutTxSerialized()),
ProtoUtil.protoToNullableString(proto.getDepositTxId()),
ProtoUtil.protoToNullableString(proto.getPayoutTxId()),
proto.getContractAsJson(),
proto.getMakerContractSignature().isEmpty() ? null : proto.getMakerContractSignature(),
proto.getTakerContractSignature().isEmpty() ? null : proto.getTakerContractSignature(),
ProtoUtil.protoToNullableString(proto.getMakerContractSignature()),
ProtoUtil.protoToNullableString(proto.getTakerContractSignature()),
PubKeyRing.fromProto(proto.getArbitratorPubKeyRing()),
proto.getIsSupportTicket());
@ -222,8 +223,9 @@ public final class Dispute implements NetworkPayload {
dispute.openingDate = proto.getOpeningDate();
dispute.isClosedProperty.set(proto.getIsClosed());
DisputeResult.fromProto(proto.getDisputeResult()).ifPresent(dispute.disputeResultProperty::set);
dispute.disputePayoutTxId = proto.getDisputePayoutTxId().isEmpty() ? null : proto.getDisputePayoutTxId();
if (proto.hasDisputeResult())
dispute.disputeResultProperty.set(DisputeResult.fromProto(proto.getDisputeResult()));
dispute.disputePayoutTxId = ProtoUtil.protoToNullableString(proto.getDisputePayoutTxId());
return dispute;
}

View File

@ -33,7 +33,6 @@ import lombok.extern.slf4j.Slf4j;
import org.bitcoinj.core.Coin;
import java.util.Date;
import java.util.Optional;
@EqualsAndHashCode
@Getter
@ -114,9 +113,8 @@ public final class DisputeResult implements NetworkPayload {
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
public static Optional<DisputeResult> fromProto(PB.DisputeResult proto) {
return proto.equals(proto.getDefaultInstanceForType()) ? Optional.empty() :
Optional.of(new DisputeResult(proto.getTradeId(),
public static DisputeResult fromProto(PB.DisputeResult proto) {
return new DisputeResult(proto.getTradeId(),
proto.getTraderId(),
ProtoUtil.enumFromProto(DisputeResult.Winner.class, proto.getWinner().name()),
proto.getReasonOrdinal(),
@ -130,7 +128,7 @@ public final class DisputeResult implements NetworkPayload {
proto.getSellerPayoutAmount(),
proto.getArbitratorPubKey().toByteArray(),
proto.getCloseDate(),
proto.getIsLoserPublisher()));
proto.getIsLoserPublisher());
}
@Override

View File

@ -19,6 +19,7 @@ package io.bisq.core.arbitration;
import com.google.protobuf.ByteString;
import io.bisq.common.crypto.PubKeyRing;
import io.bisq.common.proto.ProtoUtil;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.NodeAddress;
import io.bisq.network.p2p.storage.payload.StoragePayload;
@ -106,8 +107,8 @@ public final class Mediator implements StoragePayload {
proto.getRegistrationDate(),
proto.getRegistrationPubKey().toByteArray(),
proto.getRegistrationSignature(),
proto.getEmailAddress().isEmpty() ? null : proto.getEmailAddress(),
proto.getInfo().isEmpty() ? null : proto.getInfo(),
ProtoUtil.protoToNullableString(proto.getEmailAddress()),
ProtoUtil.protoToNullableString(proto.getInfo()),
CollectionUtils.isEmpty(proto.getExtraDataMap()) ? null : proto.getExtraDataMap());
}

View File

@ -24,8 +24,6 @@ import io.bisq.network.p2p.NodeAddress;
import lombok.EqualsAndHashCode;
import lombok.Value;
import java.util.Optional;
import static com.google.common.base.Preconditions.checkArgument;
@Value
@ -53,10 +51,8 @@ public final class DisputeResultMessage extends DisputeMessage {
}
public static DisputeResultMessage fromProto(PB.DisputeResultMessage proto) {
checkArgument(!proto.equals(proto.getDefaultInstanceForType()), "PB.DisputeResultMessage must be set (we received default instance)");
final Optional<DisputeResult> disputeResult = DisputeResult.fromProto(proto.getDisputeResult());
checkArgument(disputeResult.isPresent(), "DisputeResult is not present");
return new DisputeResultMessage(disputeResult.get(),
checkArgument(proto.hasDisputeResult(), "DisputeResult must be set");
return new DisputeResultMessage(DisputeResult.fromProto(proto.getDisputeResult()),
NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getUid());
}

View File

@ -116,7 +116,7 @@ public final class AddressEntry implements PersistablePayload {
return new AddressEntry(proto.getPubKey().toByteArray(),
proto.getPubKeyHash().toByteArray(),
ProtoUtil.enumFromProto(AddressEntry.Context.class, proto.getContext().name()),
proto.getOfferId().isEmpty() ? null : proto.getOfferId(),
ProtoUtil.protoToNullableString(proto.getOfferId()),
Coin.valueOf(proto.getCoinLockedInMultiSig()));
}

View File

@ -287,13 +287,13 @@ public final class OfferPayload implements StoragePayload, RequiresOwnerIsOnline
public static OfferPayload fromProto(PB.OfferPayload proto) {
checkArgument(!proto.getOfferFeePaymentTxId().isEmpty(), "OfferFeePaymentTxId must be set in PB.OfferPayload");
String countryCode = proto.getCountryCode().isEmpty() ? null : proto.getCountryCode();
String bankId = proto.getBankId().isEmpty() ? null : proto.getBankId();
String countryCode = ProtoUtil.protoToNullableString(proto.getCountryCode());
String bankId = ProtoUtil.protoToNullableString(proto.getBankId());
List<String> acceptedBankIds = proto.getAcceptedBankIdsList().isEmpty() ?
null : proto.getAcceptedBankIdsList().stream().collect(Collectors.toList());
List<String> acceptedCountryCodes = proto.getAcceptedCountryCodesList().isEmpty() ?
null : proto.getAcceptedCountryCodesList().stream().collect(Collectors.toList());
String hashOfChallenge = proto.getHashOfChallenge().isEmpty() ? null : proto.getHashOfChallenge();
String hashOfChallenge = ProtoUtil.protoToNullableString(proto.getHashOfChallenge());
Map<String, String> extraDataMapMap = CollectionUtils.isEmpty(proto.getExtraDataMap()) ?
null : proto.getExtraDataMap();
return new OfferPayload(proto.getId(),

View File

@ -21,7 +21,9 @@ import io.bisq.common.locale.FiatCurrency;
import io.bisq.core.payment.payload.AliPayAccountPayload;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.payment.payload.PaymentMethod;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
public final class AliPayAccount extends PaymentAccount {
public AliPayAccount() {
super(PaymentMethod.ALI_PAY);

View File

@ -21,7 +21,9 @@ import io.bisq.common.locale.FiatCurrency;
import io.bisq.core.payment.payload.ChaseQuickPayAccountPayload;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.payment.payload.PaymentMethod;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
public final class ChaseQuickPayAccount extends PaymentAccount {
public ChaseQuickPayAccount() {
super(PaymentMethod.CHASE_QUICK_PAY);

View File

@ -21,7 +21,9 @@ import io.bisq.common.locale.FiatCurrency;
import io.bisq.core.payment.payload.ClearXchangeAccountPayload;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.payment.payload.PaymentMethod;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
public final class ClearXchangeAccount extends PaymentAccount {
public ClearXchangeAccount() {
super(PaymentMethod.CLEAR_X_CHANGE);

View File

@ -20,15 +20,13 @@ package io.bisq.core.payment;
import io.bisq.common.locale.Country;
import io.bisq.core.payment.payload.CountryBasedPaymentAccountPayload;
import io.bisq.core.payment.payload.PaymentMethod;
import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
@EqualsAndHashCode(callSuper = true)
public abstract class CountryBasedPaymentAccount extends PaymentAccount {
private static final Logger log = LoggerFactory.getLogger(CountryBasedPaymentAccount.class);
@Nullable
protected Country country;
@ -47,7 +45,6 @@ public abstract class CountryBasedPaymentAccount extends PaymentAccount {
// Getter, Setter
///////////////////////////////////////////////////////////////////////////////////////////
@Nullable
public Country getCountry() {
return country;
@ -57,30 +54,4 @@ public abstract class CountryBasedPaymentAccount extends PaymentAccount {
this.country = country;
((CountryBasedPaymentAccountPayload) paymentAccountPayload).setCountryCode(country.code);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CountryBasedPaymentAccount)) return false;
if (!super.equals(o)) return false;
CountryBasedPaymentAccount that = (CountryBasedPaymentAccount) o;
return !(country != null ? !country.equals(that.country) : that.country != null);
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (country != null ? country.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "CountryBasedPaymentAccount{" +
"country=" + country +
"} " + super.toString();
}
}

View File

@ -20,7 +20,9 @@ package io.bisq.core.payment;
import io.bisq.core.payment.payload.CryptoCurrencyAccountPayload;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.payment.payload.PaymentMethod;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
public final class CryptoCurrencyAccount extends PaymentAccount {
public CryptoCurrencyAccount() {

View File

@ -21,7 +21,9 @@ import io.bisq.common.locale.FiatCurrency;
import io.bisq.core.payment.payload.FasterPaymentsAccountPayload;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.payment.payload.PaymentMethod;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
public final class FasterPaymentsAccount extends PaymentAccount {
public FasterPaymentsAccount() {
super(PaymentMethod.FASTER_PAYMENTS);

View File

@ -21,7 +21,9 @@ import io.bisq.common.locale.FiatCurrency;
import io.bisq.core.payment.payload.InteracETransferAccountPayload;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.payment.payload.PaymentMethod;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
public final class InteracETransferAccount extends PaymentAccount {
public InteracETransferAccount() {
super(PaymentMethod.INTERAC_E_TRANSFER);

View File

@ -21,7 +21,9 @@ import io.bisq.core.payment.payload.BankAccountPayload;
import io.bisq.core.payment.payload.NationalBankAccountPayload;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.payment.payload.PaymentMethod;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
public final class NationalBankAccount extends CountryBasedPaymentAccount implements SameCountryRestrictedBankAccount {
public NationalBankAccount() {
super(PaymentMethod.NATIONAL_BANK);

View File

@ -21,8 +21,10 @@ import io.bisq.common.locale.CurrencyUtil;
import io.bisq.core.payment.payload.OKPayAccountPayload;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.payment.payload.PaymentMethod;
import lombok.EqualsAndHashCode;
//TODO missing support for selected trade currency
@EqualsAndHashCode(callSuper = true)
public final class OKPayAccount extends PaymentAccount {
public OKPayAccount() {
super(PaymentMethod.OK_PAY);

View File

@ -34,6 +34,8 @@ import javax.annotation.Nullable;
import java.util.*;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull;
@EqualsAndHashCode
@ToString
@Getter
@ -51,7 +53,7 @@ public abstract class PaymentAccount implements PersistablePayload {
@Setter
protected String accountName;
protected final List<TradeCurrency> tradeCurrencies = new ArrayList<>();
@Setter
@Setter @Nullable
protected TradeCurrency selectedTradeCurrency;
@ -74,9 +76,9 @@ public abstract class PaymentAccount implements PersistablePayload {
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public PB.PaymentAccount toProtoMessage() {
checkNotNull(accountName, "accountName must not be null");
PB.PaymentAccount.Builder builder = PB.PaymentAccount.newBuilder()
.setPaymentMethod(paymentMethod.toProtoMessage())
.setId(id)
@ -89,14 +91,15 @@ public abstract class PaymentAccount implements PersistablePayload {
}
public static PaymentAccount fromProto(PB.PaymentAccount proto, CoreProtoResolver coreProtoResolver) {
PaymentAccount paymentAccount = PaymentAccountFactory.getPaymentAccount(PaymentMethod.getPaymentMethodById(proto.getPaymentMethod().getId()));
paymentAccount.setId(proto.getId());
paymentAccount.setCreationDate(proto.getCreationDate());
paymentAccount.setAccountName(proto.getAccountName());
paymentAccount.getTradeCurrencies().addAll(proto.getTradeCurrenciesList().stream().map(TradeCurrency::fromProto).collect(Collectors.toList()));
paymentAccount.setSelectedTradeCurrency(paymentAccount.getSelectedTradeCurrency());
paymentAccount.setPaymentAccountPayload(coreProtoResolver.fromProto(proto.getPaymentAccountPayload()));
return paymentAccount;
PaymentAccount account = PaymentAccountFactory.getPaymentAccount(PaymentMethod.getPaymentMethodById(proto.getPaymentMethod().getId()));
account.setId(proto.getId());
account.setCreationDate(proto.getCreationDate());
account.setAccountName(proto.getAccountName());
account.getTradeCurrencies().addAll(proto.getTradeCurrenciesList().stream().map(TradeCurrency::fromProto).collect(Collectors.toList()));
account.setPaymentAccountPayload(coreProtoResolver.fromProto(proto.getPaymentAccountPayload()));
if (proto.hasSelectedTradeCurrency())
account.setSelectedTradeCurrency(TradeCurrency.fromProto(proto.getSelectedTradeCurrency()));
return account;
}
@ -136,10 +139,5 @@ public abstract class PaymentAccount implements PersistablePayload {
return null;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Getter, Setter
///////////////////////////////////////////////////////////////////////////////////////////
protected abstract PaymentAccountPayload getPayload();
}

View File

@ -5,8 +5,7 @@ import io.bisq.core.offer.Offer;
import io.bisq.core.payment.payload.PaymentMethod;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.Collection;
@ -16,9 +15,8 @@ import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull;
@Slf4j
public class PaymentAccountUtil {
private static final Logger log = LoggerFactory.getLogger(PaymentAccountUtil.class);
public static boolean isAnyPaymentAccountValidForOffer(Offer offer, Collection<PaymentAccount> paymentAccounts) {
for (PaymentAccount paymentAccount : paymentAccounts) {
if (isPaymentAccountValidForOffer(offer, paymentAccount))
@ -103,5 +101,4 @@ public class PaymentAccountUtil {
return arePaymentMethodsEqual;
}
}
}

View File

@ -21,7 +21,9 @@ import io.bisq.common.locale.FiatCurrency;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.payment.payload.PaymentMethod;
import io.bisq.core.payment.payload.PerfectMoneyAccountPayload;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
public final class PerfectMoneyAccount extends PaymentAccount {
public PerfectMoneyAccount() {
super(PaymentMethod.PERFECT_MONEY);
@ -40,6 +42,4 @@ public final class PerfectMoneyAccount extends PaymentAccount {
public String getAccountNr() {
return ((PerfectMoneyAccountPayload) paymentAccountPayload).getAccountNr();
}
}

View File

@ -21,7 +21,9 @@ import io.bisq.core.payment.payload.BankAccountPayload;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.payment.payload.PaymentMethod;
import io.bisq.core.payment.payload.SameBankAccountPayload;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
public final class SameBankAccount extends CountryBasedPaymentAccount implements BankNameRestrictedBankAccount, SameCountryRestrictedBankAccount {
public SameBankAccount() {
super(PaymentMethod.SAME_BANK);

View File

@ -21,9 +21,11 @@ import io.bisq.common.locale.CountryUtil;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.payment.payload.PaymentMethod;
import io.bisq.core.payment.payload.SepaAccountPayload;
import lombok.EqualsAndHashCode;
import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class SepaAccount extends CountryBasedPaymentAccount implements BankAccount {
public SepaAccount() {
super(PaymentMethod.SEPA);
@ -75,6 +77,4 @@ public final class SepaAccount extends CountryBasedPaymentAccount implements Ban
public void removeAcceptedCountry(String countryCode) {
((SepaAccountPayload) paymentAccountPayload).removeAcceptedCountry(countryCode);
}
}

View File

@ -20,9 +20,11 @@ package io.bisq.core.payment;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.payment.payload.PaymentMethod;
import io.bisq.core.payment.payload.SpecificBanksAccountPayload;
import lombok.EqualsAndHashCode;
import java.util.ArrayList;
@EqualsAndHashCode(callSuper = true)
public final class SpecificBanksAccount extends CountryBasedPaymentAccount implements BankNameRestrictedBankAccount, SameCountryRestrictedBankAccount {
public SpecificBanksAccount() {
super(PaymentMethod.SPECIFIC_BANKS);

View File

@ -21,7 +21,9 @@ import io.bisq.common.locale.FiatCurrency;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.payment.payload.PaymentMethod;
import io.bisq.core.payment.payload.SwishAccountPayload;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
public final class SwishAccount extends PaymentAccount {
public SwishAccount() {
super(PaymentMethod.SWISH);

View File

@ -21,7 +21,9 @@ import io.bisq.common.locale.FiatCurrency;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.payment.payload.PaymentMethod;
import io.bisq.core.payment.payload.USPostalMoneyOrderAccountPayload;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
public final class USPostalMoneyOrderAccount extends PaymentAccount {
public USPostalMoneyOrderAccount() {
super(PaymentMethod.US_POSTAL_MONEY_ORDER);

View File

@ -82,7 +82,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable {
public static final List<PaymentMethod> ALL_VALUES = new ArrayList<>(Arrays.asList(
// EUR
SEPA = new PaymentMethod(SEPA_ID, 4 * DAY, Coin.parseCoin("0.5")),
SEPA = new PaymentMethod(SEPA_ID, 6 * DAY, Coin.parseCoin("0.5")),
// Global
NATIONAL_BANK = new PaymentMethod(NATIONAL_BANK_ID, 4 * DAY, Coin.parseCoin("0.5")),
@ -121,8 +121,8 @@ public final class PaymentMethod implements PersistablePayload, Comparable {
///////////////////////////////////////////////////////////////////////////////////////////
private final String id;
private long maxTradePeriod;
private long maxTradeLimit;
private final long maxTradePeriod;
private final long maxTradeLimit;
///////////////////////////////////////////////////////////////////////////////////////////
@ -152,7 +152,8 @@ public final class PaymentMethod implements PersistablePayload, Comparable {
return PB.PaymentMethod.newBuilder()
.setId(id)
.setMaxTradePeriod(maxTradePeriod)
.setMaxTradeLimit(maxTradeLimit).build();
.setMaxTradeLimit(maxTradeLimit)
.build();
}
public static PaymentMethod fromProto(PB.PaymentMethod proto) {

View File

@ -400,19 +400,19 @@ public abstract class Trade implements Tradable, Model {
trade.setDisputeState(DisputeState.fromProto(proto.getDisputeState()));
trade.setTradePeriodState(TradePeriodState.fromProto(proto.getTradePeriodState()));
trade.setTakerFeeTxId(proto.getTakerFeeTxId().isEmpty() ? null : proto.getTakerFeeTxId());
trade.setDepositTxId(proto.getDepositTxId().isEmpty() ? null : proto.getDepositTxId());
trade.setPayoutTxId(proto.getPayoutTxId().isEmpty() ? null : proto.getPayoutTxId());
trade.setTakerFeeTxId(ProtoUtil.protoToNullableString(proto.getTakerFeeTxId()));
trade.setDepositTxId(ProtoUtil.protoToNullableString(proto.getDepositTxId()));
trade.setPayoutTxId(ProtoUtil.protoToNullableString(proto.getPayoutTxId()));
trade.setTradingPeerNodeAddress(NodeAddress.fromProto(proto.getTradingPeerNodeAddress()));
trade.setContract(Contract.fromProto(proto.getContract(), coreProtoResolver));
trade.setContractAsJson(proto.getContractAsJson().isEmpty() ? null : proto.getContractAsJson());
trade.setTakerContractSignature(proto.getTakerContractSignature().isEmpty() ? null : proto.getTakerContractSignature());
trade.setMakerContractSignature(proto.getMakerContractSignature().isEmpty() ? null : proto.getMakerContractSignature());
trade.setContractAsJson(ProtoUtil.protoToNullableString(proto.getContractAsJson()));
trade.setTakerContractSignature(ProtoUtil.protoToNullableString(proto.getTakerContractSignature()));
trade.setMakerContractSignature(ProtoUtil.protoToNullableString(proto.getMakerContractSignature()));
trade.setArbitratorNodeAddress(NodeAddress.fromProto(proto.getArbitratorNodeAddress()));
trade.setMediatorNodeAddress(NodeAddress.fromProto(proto.getMediatorNodeAddress()));
trade.setArbitratorBtcPubKey(proto.getArbitratorBtcPubKey().toByteArray());
trade.setTakerPaymentAccountId(proto.getTakerPaymentAccountId().isEmpty() ? null : proto.getTakerPaymentAccountId());
trade.setErrorMessage(proto.getErrorMessage().isEmpty() ? null : proto.getErrorMessage());
trade.setTakerPaymentAccountId(ProtoUtil.protoToNullableString(proto.getTakerPaymentAccountId()));
trade.setErrorMessage(ProtoUtil.protoToNullableString(proto.getErrorMessage()));
return trade;
}
@ -504,7 +504,7 @@ public abstract class Trade implements Tradable, Model {
}
public void removeDecryptedMessageWithPubKey(DecryptedMessageWithPubKey decryptedMessageWithPubKey) {
if (decryptedMessageWithPubKeySet.contains(decryptedMessageWithPubKey))
if (decryptedMessageWithPubKeySet.contains(decryptedMessageWithPubKey))
decryptedMessageWithPubKeySet.remove(decryptedMessageWithPubKey);
}

View File

@ -19,6 +19,7 @@ package io.bisq.core.trade.messages;
import com.google.protobuf.ByteString;
import io.bisq.common.crypto.PubKeyRing;
import io.bisq.common.proto.ProtoUtil;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.core.btc.data.RawTransactionInput;
import io.bisq.core.payment.payload.PaymentAccountPayload;
@ -152,7 +153,7 @@ public final class PayDepositRequest extends TradeMessage {
proto.getIsCurrencyForTakerFeeBtc(),
rawTransactionInputs,
proto.getChangeOutputValue(),
proto.getChangeOutputAddress().isEmpty() ? null : proto.getChangeOutputAddress(),
ProtoUtil.protoToNullableString(proto.getChangeOutputAddress()),
proto.getTakerMultiSigPubKey().toByteArray(),
proto.getTakerPayoutAddressString(),
PubKeyRing.fromProto(proto.getTakerPubKeyRing()),

View File

@ -162,8 +162,8 @@ public class ProcessModel implements Model, PersistablePayload {
processModel.setUseSavingsWallet(proto.getUseSavingsWallet());
// nullable
processModel.setTakeOfferFeeTxId(proto.getTakeOfferFeeTxId().isEmpty() ? null : proto.getTakeOfferFeeTxId());
processModel.setPayoutTxSignature(proto.getPayoutTxSignature().isEmpty() ? null : proto.getPayoutTxSignature().toByteArray());
processModel.setTakeOfferFeeTxId(ProtoUtil.protoToNullableString(proto.getTakeOfferFeeTxId()));
processModel.setPayoutTxSignature(ProtoUtil.protoToToNullableByteArray(proto.getPayoutTxSignature()));
List<NodeAddress> takerAcceptedArbitratorNodeAddresses = proto.getTakerAcceptedArbitratorNodeAddressesList().isEmpty() ?
null : proto.getTakerAcceptedArbitratorNodeAddressesList().stream()
.map(NodeAddress::fromProto).collect(Collectors.toList());
@ -172,13 +172,13 @@ public class ProcessModel implements Model, PersistablePayload {
.map(NodeAddress::fromProto).collect(Collectors.toList());
processModel.setTakerAcceptedArbitratorNodeAddresses(takerAcceptedArbitratorNodeAddresses);
processModel.setTakerAcceptedMediatorNodeAddresses(takerAcceptedMediatorNodeAddresses);
processModel.setPreparedDepositTx(proto.getPreparedDepositTx().isEmpty() ? null : proto.getPreparedDepositTx().toByteArray());
processModel.setPreparedDepositTx(ProtoUtil.protoToToNullableByteArray(proto.getPreparedDepositTx()));
List<RawTransactionInput> rawTransactionInputs = proto.getRawTransactionInputsList().isEmpty() ?
null : proto.getRawTransactionInputsList().stream()
.map(RawTransactionInput::fromProto).collect(Collectors.toList());
processModel.setRawTransactionInputs(rawTransactionInputs);
processModel.setChangeOutputAddress(proto.getChangeOutputAddress().isEmpty() ? null : proto.getChangeOutputAddress());
processModel.setMyMultiSigPubKey(proto.getMyMultiSigPubKey().isEmpty() ? null : proto.getMyMultiSigPubKey().toByteArray());
processModel.setChangeOutputAddress(ProtoUtil.protoToNullableString(proto.getChangeOutputAddress()));
processModel.setMyMultiSigPubKey(ProtoUtil.protoToToNullableByteArray(proto.getMyMultiSigPubKey()));
processModel.setTempTradingPeerNodeAddress(NodeAddress.fromProto(proto.getTempTradingPeerNodeAddress()));
return processModel;
}

View File

@ -84,19 +84,19 @@ public final class TradingPeer implements PersistablePayload {
public static TradingPeer fromProto(PB.TradingPeer proto, CoreProtoResolver coreProtoResolver) {
TradingPeer tradingPeer = new TradingPeer();
tradingPeer.setChangeOutputValue(proto.getChangeOutputValue());
tradingPeer.setAccountId(proto.getAccountId().isEmpty() ? null : proto.getAccountId());
tradingPeer.setAccountId(ProtoUtil.protoToNullableString(proto.getAccountId()));
tradingPeer.setPaymentAccountPayload(coreProtoResolver.fromProto(proto.getPaymentAccountPayload()));
tradingPeer.setPayoutAddressString(proto.getPayoutAddressString().isEmpty() ? null : proto.getPayoutAddressString());
tradingPeer.setContractAsJson(proto.getContractAsJson().isEmpty() ? null : proto.getContractAsJson());
tradingPeer.setContractSignature(proto.getContractSignature().isEmpty() ? null : proto.getContractSignature());
tradingPeer.setSignature(proto.getSignature().isEmpty() ? null : proto.getSignature().toByteArray());
tradingPeer.setPayoutAddressString(ProtoUtil.protoToNullableString(proto.getPayoutAddressString()));
tradingPeer.setContractAsJson(ProtoUtil.protoToNullableString(proto.getContractAsJson()));
tradingPeer.setContractSignature(ProtoUtil.protoToNullableString(proto.getContractSignature()));
tradingPeer.setSignature(ProtoUtil.protoToToNullableByteArray(proto.getSignature()));
tradingPeer.setPubKeyRing(PubKeyRing.fromProto(proto.getPubKeyRing()));
tradingPeer.setMultiSigPubKey(proto.getMultiSigPubKey().isEmpty() ? null : proto.getMultiSigPubKey().toByteArray());
tradingPeer.setMultiSigPubKey(ProtoUtil.protoToToNullableByteArray(proto.getMultiSigPubKey()));
List<RawTransactionInput> rawTransactionInputs = proto.getRawTransactionInputsList().isEmpty() ?
null : proto.getRawTransactionInputsList().stream()
.map(RawTransactionInput::fromProto).collect(Collectors.toList());
tradingPeer.setRawTransactionInputs(rawTransactionInputs);
tradingPeer.setChangeOutputAddress(proto.getChangeOutputAddress().isEmpty() ? null : proto.getChangeOutputAddress());
tradingPeer.setChangeOutputAddress(ProtoUtil.protoToNullableString(proto.getChangeOutputAddress()));
return tradingPeer;
}
}

View File

@ -36,4 +36,10 @@ public final class BlockChainExplorer implements PersistablePayload {
public Message toProtoMessage() {
return PB.BlockChainExplorer.newBuilder().setName(name).setTxUrl(txUrl).setAddressUrl(addressUrl).build();
}
public static BlockChainExplorer fromProto(PB.BlockChainExplorer proto) {
return new BlockChainExplorer(proto.getName(),
proto.getTxUrl(),
proto.getAddressUrl());
}
}

View File

@ -2,7 +2,10 @@ package io.bisq.core.user;
import com.google.common.collect.Maps;
import com.google.protobuf.Message;
import io.bisq.common.locale.*;
import io.bisq.common.locale.Country;
import io.bisq.common.locale.CryptoCurrency;
import io.bisq.common.locale.FiatCurrency;
import io.bisq.common.locale.TradeCurrency;
import io.bisq.common.proto.ProtoUtil;
import io.bisq.common.proto.persistable.PersistableEnvelope;
import io.bisq.core.btc.Restrictions;
@ -21,15 +24,10 @@ import java.util.stream.Collectors;
@Data
@AllArgsConstructor
public final class PreferencesPayload implements PersistableEnvelope {
private String userLanguage;
private Country userCountry;
// getter is for the property
private String btcDenomination = Preferences.BTC_DENOMINATIONS.get(0);
// getter is for the property
private boolean useAnimations;
private final List<FiatCurrency> fiatCurrencies = new ArrayList<>();
private final List<CryptoCurrency> cryptoCurrencies = new ArrayList<>();
private List<FiatCurrency> fiatCurrencies = new ArrayList<>();
private List<CryptoCurrency> cryptoCurrencies = new ArrayList<>();
private BlockChainExplorer blockChainExplorerMainNet;
private BlockChainExplorer blockChainExplorerTestNet;
private BlockChainExplorer bsqBlockChainExplorer = new BlockChainExplorer("bisq", "https://explorer.bisq.io/tx.html?tx=",
@ -55,6 +53,7 @@ public final class PreferencesPayload implements PersistableEnvelope {
@Nullable
private String sellScreenCurrencyCode;
private int tradeStatisticsTickUnitIndex = 3;
private boolean resyncSpvRequested;
private boolean sortMarketCurrenciesNumerically = true;
private boolean usePercentageBasedPrice = true;
private Map<String, String> peerTagMap = new HashMap<>();
@ -62,10 +61,12 @@ public final class PreferencesPayload implements PersistableEnvelope {
private List<String> ignoreTradersList = new ArrayList<>();
private String directoryChooserPath;
private long buyerSecurityDepositAsLong = Restrictions.DEFAULT_BUYER_SECURITY_DEPOSIT.value;
private String btcDenomination = Preferences.BTC_DENOMINATIONS.get(0);
private boolean useAnimations;
@Nullable
private PaymentAccount selectedPaymentAccountForCreateOffer;
private boolean payFeeInBtc = true;
private boolean resyncSpvRequested;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
@ -74,6 +75,7 @@ public final class PreferencesPayload implements PersistableEnvelope {
public PreferencesPayload() {
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
@ -83,82 +85,93 @@ public final class PreferencesPayload implements PersistableEnvelope {
PB.PreferencesPayload.Builder builder = PB.PreferencesPayload.newBuilder()
.setUserLanguage(userLanguage)
.setUserCountry((PB.Country) userCountry.toProtoMessage())
.addAllFiatCurrencies(fiatCurrencies.stream().map(fiatCurrency -> ((PB.TradeCurrency) fiatCurrency.toProtoMessage())).collect(Collectors.toList()))
.addAllCryptoCurrencies(cryptoCurrencies.stream().map(cryptoCurrency -> ((PB.TradeCurrency) cryptoCurrency.toProtoMessage())).collect(Collectors.toList()))
.addAllFiatCurrencies(fiatCurrencies.stream()
.map(fiatCurrency -> ((PB.TradeCurrency) fiatCurrency.toProtoMessage()))
.collect(Collectors.toList()))
.addAllCryptoCurrencies(cryptoCurrencies.stream()
.map(cryptoCurrency -> ((PB.TradeCurrency) cryptoCurrency.toProtoMessage()))
.collect(Collectors.toList()))
.setBlockChainExplorerMainNet((PB.BlockChainExplorer) blockChainExplorerMainNet.toProtoMessage())
.setBlockChainExplorerTestNet((PB.BlockChainExplorer) blockChainExplorerTestNet.toProtoMessage())
.setBsqBlockChainExplorer((PB.BlockChainExplorer) bsqBlockChainExplorer.toProtoMessage())
.setAutoSelectArbitrators(autoSelectArbitrators)
.putAllDontShowAgainMap(dontShowAgainMap)
.setTacAccepted(tacAccepted)
.setUseAnimations(useAnimations)
.setUseTorForBitcoinJ(useTorForBitcoinJ)
.setShowOwnOffersInOfferBook(showOwnOffersInOfferBook)
.setPreferredTradeCurrency((PB.TradeCurrency) preferredTradeCurrency.toProtoMessage())
.setWithdrawalTxFeeInBytes(withdrawalTxFeeInBytes)
.setUseCustomWithdrawalTxFee(useCustomWithdrawalTxFee)
.setMaxPriceDistanceInPercent(maxPriceDistanceInPercent)
.setTradeStatisticsTickUnitIndex(tradeStatisticsTickUnitIndex)
.setResyncSpvRequested(resyncSpvRequested)
.setSortMarketCurrenciesNumerically(sortMarketCurrenciesNumerically)
.setUsePercentageBasedPrice(usePercentageBasedPrice)
.setPayFeeInBtc(payFeeInBtc)
.putAllPeerTagMap(peerTagMap)
.setBitcoinNodes(bitcoinNodes)
.addAllIgnoreTradersList(ignoreTradersList)
.setDirectoryChooserPath(directoryChooserPath)
.setBuyerSecurityDepositAsLong(buyerSecurityDepositAsLong);
.setBuyerSecurityDepositAsLong(buyerSecurityDepositAsLong)
.setBtcDenomination(btcDenomination)
.setUseAnimations(useAnimations)
.setPayFeeInBtc(payFeeInBtc);
Optional.ofNullable(backupDirectory).ifPresent(backupDir -> builder.setBackupDirectory(backupDir));
Optional.ofNullable(offerBookChartScreenCurrencyCode).ifPresent(code -> builder.setOfferBookChartScreenCurrencyCode(code));
Optional.ofNullable(tradeChartsScreenCurrencyCode).ifPresent(code -> builder.setTradeChartsScreenCurrencyCode(code));
Optional.ofNullable(buyScreenCurrencyCode).ifPresent(code -> builder.setBuyScreenCurrencyCode(code));
Optional.ofNullable(sellScreenCurrencyCode).ifPresent(code -> builder.setSellScreenCurrencyCode(code));
Optional.ofNullable(backupDirectory).ifPresent(builder::setBackupDirectory);
Optional.ofNullable(preferredTradeCurrency).ifPresent(e -> builder.setPreferredTradeCurrency((PB.TradeCurrency) e.toProtoMessage()));
Optional.ofNullable(offerBookChartScreenCurrencyCode).ifPresent(builder::setOfferBookChartScreenCurrencyCode);
Optional.ofNullable(tradeChartsScreenCurrencyCode).ifPresent(builder::setTradeChartsScreenCurrencyCode);
Optional.ofNullable(buyScreenCurrencyCode).ifPresent(builder::setBuyScreenCurrencyCode);
Optional.ofNullable(sellScreenCurrencyCode).ifPresent(builder::setSellScreenCurrencyCode);
Optional.ofNullable(selectedPaymentAccountForCreateOffer).ifPresent(
account -> builder.setSelectedPaymentAccountForCreateOffer(selectedPaymentAccountForCreateOffer.toProtoMessage()));
return PB.PersistableEnvelope.newBuilder().setPreferencesPayload(builder).build();
}
public static PersistableEnvelope fromProto(PB.PreferencesPayload proto, CoreProtoResolver coreProtoResolver) {
final PB.Country userCountry = proto.getUserCountry();
PaymentAccount paymentAccount = null;
if (proto.hasSelectedPaymentAccountForCreateOffer() && proto.getSelectedPaymentAccountForCreateOffer().hasPaymentMethod())
paymentAccount = PaymentAccount.fromProto(proto.getSelectedPaymentAccountForCreateOffer(), coreProtoResolver);
return new PreferencesPayload(
proto.getUserLanguage(),
new Country(proto.getUserCountry().getCode(),
proto.getUserCountry().getName(),
new Region(proto.getUserCountry().getRegion().getCode(), proto.getUserCountry().getRegion().getName())),
proto.getBtcDenomination(),
proto.getUseAnimations(),
new BlockChainExplorer(proto.getBlockChainExplorerMainNet().getName(),
proto.getBlockChainExplorerMainNet().getTxUrl(),
proto.getBlockChainExplorerMainNet().getAddressUrl()),
new BlockChainExplorer(proto.getBlockChainExplorerTestNet().getName(),
proto.getBlockChainExplorerTestNet().getTxUrl(),
proto.getBlockChainExplorerTestNet().getAddressUrl()),
new BlockChainExplorer(proto.getBsqBlockChainExplorer().getName(),
proto.getBsqBlockChainExplorer().getTxUrl(),
proto.getBsqBlockChainExplorer().getAddressUrl()),
ProtoUtil.emptyStringToNull(proto.getBackupDirectory()),
Country.fromProto(userCountry),
proto.getFiatCurrenciesList().isEmpty() ? new ArrayList<>() :
new ArrayList<>(proto.getFiatCurrenciesList().stream()
.map(FiatCurrency::fromProto)
.collect(Collectors.toList())),
proto.getCryptoCurrenciesList().isEmpty() ? new ArrayList<>() :
new ArrayList<>(proto.getCryptoCurrenciesList().stream()
.map(CryptoCurrency::fromProto)
.collect(Collectors.toList())),
BlockChainExplorer.fromProto(proto.getBlockChainExplorerMainNet()),
BlockChainExplorer.fromProto(proto.getBlockChainExplorerTestNet()),
BlockChainExplorer.fromProto(proto.getBsqBlockChainExplorer()),
ProtoUtil.protoToNullableString(proto.getBackupDirectory()),
proto.getAutoSelectArbitrators(),
Maps.newHashMap(proto.getDontShowAgainMapMap()), // proto returns an unmodifiable map by default
Maps.newHashMap(proto.getDontShowAgainMapMap()),
proto.getTacAccepted(),
proto.getUseTorForBitcoinJ(),
proto.getShowOwnOffersInOfferBook(),
TradeCurrency.fromProto(proto.getPreferredTradeCurrency()),
proto.hasPreferredTradeCurrency() ? TradeCurrency.fromProto(proto.getPreferredTradeCurrency()) : null,
proto.getWithdrawalTxFeeInBytes(),
proto.getUseCustomWithdrawalTxFee(),
proto.getMaxPriceDistanceInPercent(),
ProtoUtil.emptyStringToNull(proto.getOfferBookChartScreenCurrencyCode()),
ProtoUtil.emptyStringToNull(proto.getTradeChartsScreenCurrencyCode()),
ProtoUtil.emptyStringToNull(proto.getBuyScreenCurrencyCode()),
ProtoUtil.emptyStringToNull(proto.getSellScreenCurrencyCode()),
ProtoUtil.protoToNullableString(proto.getOfferBookChartScreenCurrencyCode()),
ProtoUtil.protoToNullableString(proto.getTradeChartsScreenCurrencyCode()),
ProtoUtil.protoToNullableString(proto.getBuyScreenCurrencyCode()),
ProtoUtil.protoToNullableString(proto.getSellScreenCurrencyCode()),
proto.getTradeStatisticsTickUnitIndex(),
proto.getResyncSpvRequested(),
proto.getSortMarketCurrenciesNumerically(),
proto.getUsePercentageBasedPrice(),
proto.getPeerTagMapMap(),
Maps.newHashMap(proto.getPeerTagMapMap()),
proto.getBitcoinNodes(),
proto.getIgnoreTradersListList(),
proto.getDirectoryChooserPath(),
proto.getBuyerSecurityDepositAsLong(),
proto.getSelectedPaymentAccountForCreateOffer().hasPaymentMethod() ?
PaymentAccount.fromProto(proto.getSelectedPaymentAccountForCreateOffer(), coreProtoResolver) :
null,
proto.getPayFeeInBtc(),
proto.getResyncSpvRequested());
proto.getBtcDenomination(),
proto.getUseAnimations(),
paymentAccount,
proto.getPayFeeInBtc());
}
}

View File

@ -29,6 +29,7 @@ import io.bisq.core.filter.Filter;
import io.bisq.core.payment.PaymentAccount;
import io.bisq.network.p2p.NodeAddress;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableSet;
@ -59,7 +60,6 @@ public final class User implements PersistedDataHost {
private ObjectProperty<PaymentAccount> currentPaymentAccountProperty;
private UserPayload userPayload = new UserPayload();
private boolean initialReadDone = false;
@Inject
public User(Storage<UserPayload> storage, KeyRing keyRing) throws NoSuchAlgorithmException {
@ -75,7 +75,7 @@ public final class User implements PersistedDataHost {
@Override
public void readPersisted() {
UserPayload persisted = storage.initAndGetPersistedWithFileName("User");
UserPayload persisted = storage.initAndGetPersistedWithFileName("UserPayload");
userPayload = persisted != null ? persisted : new UserPayload();
checkNotNull(userPayload.getPaymentAccounts(), "userPayload.getPaymentAccounts() must not be null");
@ -91,7 +91,6 @@ public final class User implements PersistedDataHost {
if (!userPayload.getAcceptedLanguageLocaleCodes().contains(english))
userPayload.getAcceptedLanguageLocaleCodes().add(english);
// Use that to guarantee update of the serializable field and to make a storage update in case of a change
paymentAccountsAsObservable.addListener((SetChangeListener<PaymentAccount>) change -> {
userPayload.setPaymentAccounts(new HashSet<>(paymentAccountsAsObservable));
@ -102,13 +101,10 @@ public final class User implements PersistedDataHost {
persist();
});
initialReadDone = true;
}
private void persist() {
// TODO if we persist we get a blank screen (exception in view class contrs. or circ. dependency?)
if (initialReadDone)
storage.queueUpForSave(userPayload);
storage.queueUpForSave(userPayload);
}
@ -123,9 +119,11 @@ public final class User implements PersistedDataHost {
.findFirst();
}*/
@Nullable
public Arbitrator getAcceptedArbitratorByAddress(NodeAddress nodeAddress) {
if (userPayload.getAcceptedArbitrators() != null) {
Optional<Arbitrator> arbitratorOptional = userPayload.getAcceptedArbitrators().stream()
final List<Arbitrator> acceptedArbitrators = userPayload.getAcceptedArbitrators();
if (acceptedArbitrators != null) {
Optional<Arbitrator> arbitratorOptional = acceptedArbitrators.stream()
.filter(e -> e.getNodeAddress().equals(nodeAddress))
.findFirst();
if (arbitratorOptional.isPresent())
@ -137,9 +135,11 @@ public final class User implements PersistedDataHost {
}
}
@Nullable
public Mediator getAcceptedMediatorByAddress(NodeAddress nodeAddress) {
if (userPayload.getAcceptedMediators() != null) {
Optional<Mediator> mediatorOptionalOptional = userPayload.getAcceptedMediators().stream()
final List<Mediator> acceptedMediators = userPayload.getAcceptedMediators();
if (acceptedMediators != null) {
Optional<Mediator> mediatorOptionalOptional = acceptedMediators.stream()
.filter(e -> e.getNodeAddress().equals(nodeAddress))
.findFirst();
if (mediatorOptionalOptional.isPresent())
@ -283,7 +283,6 @@ public final class User implements PersistedDataHost {
// Setters
///////////////////////////////////////////////////////////////////////////////////////////
public void setCurrentPaymentAccount(PaymentAccount paymentAccount) {
currentPaymentAccountProperty.set(paymentAccount);
persist();
@ -334,15 +333,11 @@ public final class User implements PersistedDataHost {
return userPayload.getAccountId();
}
/* public boolean isRegistered() {
return getAccountId() != null;
}*/
private PaymentAccount getCurrentPaymentAccount() {
return userPayload.getCurrentPaymentAccount();
}
public ObjectProperty<PaymentAccount> currentPaymentAccountProperty() {
public ReadOnlyObjectProperty<PaymentAccount> currentPaymentAccountProperty() {
return currentPaymentAccountProperty;
}

View File

@ -95,10 +95,10 @@ public class UserPayload implements PersistableEnvelope {
public static UserPayload fromProto(PB.UserPayload proto, CoreProtoResolver coreProtoResolver) {
return new UserPayload(
proto.getAccountId().isEmpty() ? null : proto.getAccountId(),
proto.getPaymentAccountsList().isEmpty() ? null : proto.getPaymentAccountsList().stream()
ProtoUtil.protoToNullableString(proto.getAccountId()),
proto.getPaymentAccountsList().isEmpty() ? new HashSet<>() : new HashSet<>(proto.getPaymentAccountsList().stream()
.map(e -> PaymentAccount.fromProto(e, coreProtoResolver))
.collect(Collectors.toSet()),
.collect(Collectors.toSet())),
proto.hasCurrentPaymentAccount() ? PaymentAccount.fromProto(proto.getCurrentPaymentAccount(), coreProtoResolver) : null,
proto.getAcceptedLanguageLocaleCodesList().isEmpty() ? new ArrayList<>() : new ArrayList<>(proto.getAcceptedLanguageLocaleCodesList()),
proto.hasDevelopersAlert() ? Alert.fromProto(proto.getDevelopersAlert()) : null,
@ -106,12 +106,12 @@ public class UserPayload implements PersistableEnvelope {
proto.hasDevelopersFilter() ? Filter.fromProto(proto.getDevelopersFilter()) : null,
proto.hasRegisteredArbitrator() ? Arbitrator.fromProto(proto.getRegisteredArbitrator()) : null,
proto.hasRegisteredMediator() ? Mediator.fromProto(proto.getRegisteredMediator()) : null,
proto.getAcceptedArbitratorsList().isEmpty() ? new ArrayList<>() : proto.getAcceptedArbitratorsList().stream()
proto.getAcceptedArbitratorsList().isEmpty() ? new ArrayList<>() : new ArrayList<>(proto.getAcceptedArbitratorsList().stream()
.map(Arbitrator::fromProto)
.collect(Collectors.toList()),
proto.getAcceptedMediatorsList().isEmpty() ? new ArrayList<>() : proto.getAcceptedMediatorsList().stream()
.collect(Collectors.toList())),
proto.getAcceptedMediatorsList().isEmpty() ? new ArrayList<>() : new ArrayList<>(proto.getAcceptedMediatorsList().stream()
.map(Mediator::fromProto)
.collect(Collectors.toList())
.collect(Collectors.toList()))
);
}
}

View File

@ -212,19 +212,13 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
seedNodeAddresses = seedNodesRepository.getSeedNodeAddresses(useLocalhostForP2P, networkId);
peerManager = new PeerManager(networkNode, maxConnections, seedNodeAddresses, storageDir, clock, persistenceProtoResolver);
broadcaster = new Broadcaster(networkNode, peerManager);
p2PDataStorage = new P2PDataStorage(broadcaster, networkNode, storageDir, persistenceProtoResolver);
p2PDataStorage.addHashMapChangedListener(this);
requestDataManager = new RequestDataManager(networkNode, p2PDataStorage, peerManager, seedNodeAddresses, this);
peerExchangeManager = new PeerExchangeManager(networkNode, peerManager, seedNodeAddresses);
keepAliveManager = new KeepAliveManager(networkNode, peerManager);
// We need to have both the initial data delivered and the hidden service published
networkReadyBinding = EasyBind.combine(hiddenServicePublished, preliminaryDataReceived,
(hiddenServicePublished, preliminaryDataReceived)