Apply Lombok annotations, cleanup, check hashcode and equals methods

This commit is contained in:
Manfred Karrer 2017-03-20 22:10:10 -05:00
parent fbf6668ced
commit 93531c76d0
18 changed files with 189 additions and 645 deletions

View File

@ -19,10 +19,14 @@ package io.bisq.common.locale;
import io.bisq.common.app.Version;
import io.bisq.common.persistance.Persistable;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.annotation.concurrent.Immutable;
@Immutable
@EqualsAndHashCode
@ToString
public final class Country implements Persistable {
// That object is saved to disc. We need to take care of changes to not break deserialization.
private static final long serialVersionUID = Version.LOCAL_DB_VERSION;
@ -36,35 +40,4 @@ public final class Country implements Persistable {
this.name = name;
this.region = region;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Country country = (Country) o;
if (code != null ? !code.equals(country.code) : country.code != null) return false;
//noinspection SimplifiableIfStatement
if (name != null ? !name.equals(country.name) : country.name != null) return false;
return !(region != null ? !region.equals(country.region) : country.region != null);
}
@Override
public int hashCode() {
int result = code != null ? code.hashCode() : 0;
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (region != null ? region.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Country{" +
"code='" + code + '\'' +
", name='" + name + '\'' +
", region=" + region +
'}';
}
}

View File

@ -18,17 +18,22 @@
package io.bisq.common.locale;
import io.bisq.common.app.Version;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import java.util.Currency;
import java.util.Locale;
@EqualsAndHashCode
@ToString
@Getter
public final class FiatCurrency extends TradeCurrency {
// That object is saved to disc. We need to take care of changes to not break deserialization.
private static final long serialVersionUID = Version.LOCAL_DB_VERSION;
// http://boschista.deviantart.com/journal/Cool-ASCII-Symbols-214218618
private final static String PREFIX = "";
private static Locale defaultLocale;
public static void setDefaultLocale(Locale defaultLocale) {
@ -56,22 +61,8 @@ public final class FiatCurrency extends TradeCurrency {
this.currency = currency;
}
public Currency getCurrency() {
return currency;
}
@Override
public String getDisplayPrefix() {
return PREFIX;
}
@Override
public String toString() {
return "FiatCurrency{" +
"currency=" + currency +
", code='" + code + '\'' +
", name='" + name + '\'' +
", symbol='" + symbol + '\'' +
'}';
}
}

View File

@ -19,10 +19,14 @@ package io.bisq.common.locale;
import io.bisq.common.app.Version;
import io.bisq.common.persistance.Persistable;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.annotation.concurrent.Immutable;
@Immutable
@EqualsAndHashCode
@ToString
public final class Region implements Persistable {
// That object is saved to disc. We need to take care of changes to not break deserialization.
private static final long serialVersionUID = Version.LOCAL_DB_VERSION;
@ -34,32 +38,4 @@ public final class Region implements Persistable {
this.code = code;
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Region region = (Region) o;
//noinspection SimplifiableIfStatement
if (code != null ? !code.equals(region.code) : region.code != null) return false;
return !(name != null ? !name.equals(region.name) : region.name != null);
}
@Override
public int hashCode() {
int result = code != null ? code.hashCode() : 0;
result = 31 * result + (name != null ? name.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Region{" +
"code='" + code + '\'' +
", name='" + name + '\'' +
'}';
}
}

View File

@ -19,39 +19,35 @@ package io.bisq.common.locale;
import io.bisq.common.app.Version;
import io.bisq.common.persistance.Persistable;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
@EqualsAndHashCode
@ToString
@Getter
public abstract class TradeCurrency implements Persistable, Comparable<TradeCurrency> {
// That object is saved to disc. We need to take care of changes to not break deserialization.
private static final long serialVersionUID = Version.LOCAL_DB_VERSION;
protected final String code;
protected final String name;
@Nullable
protected String symbol;
protected TradeCurrency(String code, String name) {
this.code = code;
this.name = name;
this(code, name, null);
}
public TradeCurrency(String code, String name, String symbol) {
public TradeCurrency(String code, String name, @Nullable String symbol) {
this.code = code;
this.name = name;
this.symbol = symbol;
}
public String getCode() {
return code;
}
public String getName() {
return name;
}
public String getSymbol() {
return symbol;
}
public String getDisplayPrefix() {
return "";
}
@ -66,31 +62,6 @@ public abstract class TradeCurrency implements Persistable, Comparable<TradeCurr
@Override
public int compareTo(@NotNull TradeCurrency other) {
return this.getName().compareTo(other.getName());
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof TradeCurrency)) return false;
TradeCurrency that = (TradeCurrency) o;
return !(getCode() != null ? !getCode().equals(that.getCode()) : that.getCode() != null);
}
@Override
public int hashCode() {
return getCode() != null ? getCode().hashCode() : 0;
}
@Override
public String toString() {
return "TradeCurrency{" +
"code='" + code + '\'' +
", name='" + name + '\'' +
", symbol='" + symbol + '\'' +
'}';
return this.code.compareTo(other.code);
}
}

View File

@ -20,6 +20,9 @@ package io.bisq.core.btc;
import io.bisq.common.app.Version;
import io.bisq.common.persistance.Persistable;
import io.bisq.common.util.Utilities;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.bitcoinj.core.Address;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.NetworkParameters;
@ -27,34 +30,29 @@ import org.bitcoinj.crypto.DeterministicKey;
import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.params.RegTestParams;
import org.bitcoinj.params.TestNet3Params;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.io.IOException;
import java.io.ObjectInputStream;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Every trade use a addressEntry with a dedicated address for all transactions related to the trade.
* That way we have a kind of separated trade wallet, isolated from other transactions and avoiding coin merge.
* If we would not avoid coin merge the user would lose privacy between trades.
*/
@EqualsAndHashCode
@Slf4j
@Getter
public final class AddressEntry implements Persistable {
// That object is saved to disc. We need to take care of changes to not break deserialization.
private static final long serialVersionUID = Version.LOCAL_DB_VERSION;
private static final Logger log = LoggerFactory.getLogger(AddressEntry.class);
public enum Context {
ARBITRATOR,
AVAILABLE,
OFFER_FUNDING,
RESERVED_FOR_TRADE, //reserved
MULTI_SIG, //locked
RESERVED_FOR_TRADE,
MULTI_SIG,
TRADE_PAYOUT
}
@ -63,11 +61,8 @@ public final class AddressEntry implements Persistable {
// So after startup it never must be null
@Nullable
transient private DeterministicKey keyPair;
// Only set if its a TRADE Context
@Nullable
private final String offerId;
private final Context context;
private final byte[] pubKey;
private final byte[] pubKeyHash;
@ -81,21 +76,16 @@ public final class AddressEntry implements Persistable {
// Constructor, initialization
///////////////////////////////////////////////////////////////////////////////////////////
// If created without offerId (arbitrator)
public AddressEntry(DeterministicKey keyPair, NetworkParameters params, Context context) {
this(keyPair, params, context, null);
}
// If created with offerId
public AddressEntry(@Nullable DeterministicKey keyPair, NetworkParameters params, Context context, @Nullable String offerId) {
public AddressEntry(DeterministicKey keyPair, NetworkParameters params, Context context, @Nullable String offerId) {
this.keyPair = keyPair;
this.params = params;
this.context = context;
this.offerId = offerId;
paramId = params.getId();
checkNotNull(keyPair);
pubKey = keyPair.getPubKey();
pubKeyHash = keyPair.getPubKeyHash();
}
@ -121,49 +111,31 @@ public final class AddressEntry implements Persistable {
this.keyPair = deterministicKey;
}
public void setCoinLockedInMultiSig(Coin coinLockedInMultiSig) {
this.coinLockedInMultiSig = coinLockedInMultiSig;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Getters
///////////////////////////////////////////////////////////////////////////////////////////
@Nullable
public String getOfferId() {
return offerId;
}
// For display we usually only display the first 8 characters.
@Nullable
public String getShortOfferId() {
return offerId != null ? Utilities.getShortId(offerId) : null;
}
public Context getContext() {
return context;
}
@Nullable
public String getAddressString() {
return getAddress() != null ? getAddress().toString() : null;
}
@Nullable
public DeterministicKey getKeyPair() {
return keyPair != null ? keyPair : null;
}
@Nullable
public Address getAddress() {
return keyPair != null ? keyPair.toAddress(params) : null;
}
public byte[] getPubKeyHash() {
return pubKeyHash;
}
public byte[] getPubKey() {
return pubKey;
}
public boolean isOpenOffer() {
return context == Context.OFFER_FUNDING || context == Context.RESERVED_FOR_TRADE;
}
@ -176,10 +148,6 @@ public final class AddressEntry implements Persistable {
return isOpenOffer() || isTrade();
}
public void setCoinLockedInMultiSig(Coin coinLockedInMultiSig) {
this.coinLockedInMultiSig = coinLockedInMultiSig;
}
@Nullable
public Coin getCoinLockedInMultiSig() {
return coinLockedInMultiSig;

View File

@ -22,6 +22,8 @@ import io.bisq.wire.payload.arbitration.Arbitrator;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import java.util.Date;
public class ArbitratorListItem {
public final Arbitrator arbitrator;
private final BSFormatter formatter;
@ -37,11 +39,12 @@ public class ArbitratorListItem {
}
public String getLanguageCodes() {
return arbitrator != null && arbitrator.getLanguageCodes() != null ? formatter.languageCodesToString(arbitrator.getLanguageCodes()) : "";
return arbitrator != null && arbitrator.getLanguageCodes() != null ?
formatter.languageCodesToString(arbitrator.getLanguageCodes()) : "";
}
public String getRegistrationDate() {
return arbitrator != null ? formatter.formatDate(arbitrator.getRegistrationDate()) : "";
return arbitrator != null ? formatter.formatDate(new Date(arbitrator.getRegistrationDate())) : "";
}
public boolean getIsSelected() {

View File

@ -717,7 +717,6 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
if (!(o instanceof ByteArray)) return false;
ByteArray byteArray = (ByteArray) o;
return Arrays.equals(bytes, byteArray.bytes);
}
@ -734,7 +733,6 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
}
}
/**
* Used as value in map
*/

View File

@ -24,8 +24,10 @@ import io.bisq.common.app.Version;
import io.bisq.common.crypto.Sig;
import io.bisq.wire.payload.StoragePayload;
import io.bisq.wire.proto.Messages;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.util.encoders.Hex;
import javax.annotation.Nullable;
import java.io.IOException;
@ -35,26 +37,28 @@ import java.security.NoSuchProviderException;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
@EqualsAndHashCode
@Slf4j
public final class Alert implements StoragePayload {
// That object is sent over the wire, so we need to take care of version compatibility.
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
private static final Logger log = LoggerFactory.getLogger(Alert.class);
private static final long TTL = TimeUnit.DAYS.toMillis(30);
// Payload
public final String message;
public final String version;
public final boolean isUpdateInfo;
@Getter
private String signatureAsBase64;
private byte[] storagePublicKeyBytes;
// Should be only used in emergency case if we need to add data but do not want to break backward compatibility
// at the P2P network storage checks. The hash of the object will be used to verify if the data is valid. Any new
// field in a class would break that hash and therefore break the storage mechanism.
@Getter
@Nullable
private Map<String, String> extraDataMap;
@ -144,11 +148,6 @@ public final class Alert implements StoragePayload {
return storagePublicKey;
}
@Nullable
@Override
public Map<String, String> getExtraDataMap() {
return extraDataMap;
}
@Override
public Messages.StoragePayload toProtoBuf() {
@ -163,33 +162,6 @@ public final class Alert implements StoragePayload {
return Messages.StoragePayload.newBuilder().setAlert(builder).build();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Alert)) return false;
Alert alert = (Alert) o;
if (isUpdateInfo != alert.isUpdateInfo) return false;
if (message != null ? !message.equals(alert.message) : alert.message != null) return false;
if (version != null ? !version.equals(alert.version) : alert.version != null) return false;
if (signatureAsBase64 != null ? !signatureAsBase64.equals(alert.signatureAsBase64) : alert.signatureAsBase64 != null)
return false;
return Arrays.equals(storagePublicKeyBytes, alert.storagePublicKeyBytes);
}
@Override
public int hashCode() {
int result = message != null ? message.hashCode() : 0;
result = 31 * result + (version != null ? version.hashCode() : 0);
result = 31 * result + (isUpdateInfo ? 1 : 0);
result = 31 * result + (signatureAsBase64 != null ? signatureAsBase64.hashCode() : 0);
result = 31 * result + (storagePublicKeyBytes != null ? Arrays.hashCode(storagePublicKeyBytes) : 0);
return result;
}
@Override
public String toString() {
return "Alert{" +
@ -197,7 +169,9 @@ public final class Alert implements StoragePayload {
", version='" + version + '\'' +
", isUpdateInfo=" + isUpdateInfo +
", signatureAsBase64='" + signatureAsBase64 + '\'' +
", storagePublicKeyBytes=" + Arrays.toString(storagePublicKeyBytes) +
", storagePublicKeyBytes=" + Hex.toHexString(storagePublicKeyBytes) +
", storagePublicKey=" + Hex.toHexString(storagePublicKey.getEncoded()) +
", extraDataMap=" + extraDataMap +
'}';
}
}

View File

@ -24,12 +24,23 @@ import io.bisq.wire.payload.StoragePayload;
import io.bisq.wire.payload.crypto.PubKeyRing;
import io.bisq.wire.payload.p2p.NodeAddress;
import io.bisq.wire.proto.Messages;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Nullable;
import java.security.PublicKey;
import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
@EqualsAndHashCode
@Slf4j
@ToString
@Getter
public final class Arbitrator implements StoragePayload {
// That object is sent over the wire, so we need to take care of version compatibility.
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
@ -72,12 +83,6 @@ public final class Arbitrator implements StoragePayload {
this.extraDataMap = Optional.ofNullable(extraDataMap).orElse(Maps.newHashMap());
}
///////////////////////////////////////////////////////////////////////////////////////////
// Getters
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public long getTTL() {
return TTL;
@ -88,46 +93,6 @@ public final class Arbitrator implements StoragePayload {
return pubKeyRing.getSignaturePubKey();
}
@Nullable
@Override
public Map<String, String> getExtraDataMap() {
return extraDataMap;
}
public byte[] getBtcPubKey() {
return btcPubKey;
}
public PubKeyRing getPubKeyRing() {
return pubKeyRing;
}
public NodeAddress getArbitratorNodeAddress() {
return arbitratorNodeAddress;
}
public Date getRegistrationDate() {
return new Date(registrationDate);
}
public String getBtcAddress() {
return btcAddress;
}
public List<String> getLanguageCodes() {
return languageCodes;
}
public String getRegistrationSignature() {
return registrationSignature;
}
public byte[] getRegistrationPubKey() {
return registrationPubKey;
}
@Override
public Messages.StoragePayload toProtoBuf() {
final Messages.Arbitrator.Builder builder = Messages.Arbitrator.newBuilder()
@ -144,52 +109,4 @@ public final class Arbitrator implements StoragePayload {
return Messages.StoragePayload.newBuilder().setArbitrator(builder).build();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Arbitrator)) return false;
Arbitrator that = (Arbitrator) o;
if (registrationDate != that.registrationDate) return false;
if (!Arrays.equals(btcPubKey, that.btcPubKey)) return false;
if (pubKeyRing != null ? !pubKeyRing.equals(that.pubKeyRing) : that.pubKeyRing != null) return false;
if (arbitratorNodeAddress != null ? !arbitratorNodeAddress.equals(that.arbitratorNodeAddress) : that.arbitratorNodeAddress != null)
return false;
if (languageCodes != null ? !languageCodes.equals(that.languageCodes) : that.languageCodes != null)
return false;
if (btcAddress != null ? !btcAddress.equals(that.btcAddress) : that.btcAddress != null) return false;
if (registrationSignature != null ? !registrationSignature.equals(that.registrationSignature) : that.registrationSignature != null)
return false;
return Arrays.equals(registrationPubKey, that.registrationPubKey);
}
@Override
public int hashCode() {
int result = btcPubKey != null ? Arrays.hashCode(btcPubKey) : 0;
result = 31 * result + (pubKeyRing != null ? pubKeyRing.hashCode() : 0);
result = 31 * result + (arbitratorNodeAddress != null ? arbitratorNodeAddress.hashCode() : 0);
result = 31 * result + (languageCodes != null ? languageCodes.hashCode() : 0);
result = 31 * result + (btcAddress != null ? btcAddress.hashCode() : 0);
result = 31 * result + (int) (registrationDate ^ (registrationDate >>> 32));
result = 31 * result + (registrationSignature != null ? registrationSignature.hashCode() : 0);
result = 31 * result + (registrationPubKey != null ? Arrays.hashCode(registrationPubKey) : 0);
return result;
}
@Override
public String toString() {
return "Arbitrator{" +
"\n\tarbitratorAddress=" + arbitratorNodeAddress +
"\n\tlanguageCodes=" + languageCodes +
"\n\tbtcAddress='" + btcAddress + '\'' +
"\n\tregistrationDate=" + registrationDate +
"\n\tbtcPubKey.hashCode()=" + Arrays.toString(btcPubKey).hashCode() +
"\n\tpubKeyRing.hashCode()=" + pubKeyRing.hashCode() +
"\n\tregistrationSignature.hashCode()='" + registrationSignature.hashCode() + '\'' +
"\n\tregistrationPubKey.hashCode()=" + Arrays.toString(registrationPubKey).hashCode() +
'}';
}
}

View File

@ -23,8 +23,10 @@ import io.bisq.common.crypto.Sig;
import io.bisq.wire.crypto.Encryption;
import io.bisq.wire.payload.Payload;
import io.bisq.wire.proto.Messages;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.util.encoders.Hex;
import java.io.IOException;
import java.io.ObjectInputStream;
@ -39,18 +41,21 @@ import java.security.spec.X509EncodedKeySpec;
* Same as KeyRing but with public keys only.
* Used to send public keys over the wire to other peer.
*/
@EqualsAndHashCode
@Slf4j
public final class PubKeyRing implements Payload {
// That object is sent over the wire, so we need to take care of version compatibility.
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
private static final Logger log = LoggerFactory.getLogger(PubKeyRing.class);
// Payload
private final byte[] signaturePubKeyBytes;
private final byte[] encryptionPubKeyBytes;
// Domain
@Getter
transient private PublicKey signaturePubKey;
@Getter
transient private PublicKey encryptionPubKey;
public PubKeyRing(PublicKey signaturePubKey, PublicKey encryptionPubKey) {
@ -77,53 +82,27 @@ public final class PubKeyRing implements Payload {
private void init() {
try {
signaturePubKey = KeyFactory.getInstance(Sig.KEY_ALGO, "BC").generatePublic(new X509EncodedKeySpec(signaturePubKeyBytes));
encryptionPubKey = KeyFactory.getInstance(Encryption.ASYM_KEY_ALGO, "BC").generatePublic(new X509EncodedKeySpec(encryptionPubKeyBytes));
signaturePubKey = KeyFactory.getInstance(Sig.KEY_ALGO, "BC")
.generatePublic(new X509EncodedKeySpec(signaturePubKeyBytes));
encryptionPubKey = KeyFactory.getInstance(Encryption.ASYM_KEY_ALGO, "BC")
.generatePublic(new X509EncodedKeySpec(encryptionPubKeyBytes));
} catch (InvalidKeySpecException | NoSuchAlgorithmException | NoSuchProviderException e) {
e.printStackTrace();
log.error(e.getMessage());
}
}
public PublicKey getSignaturePubKey() {
return signaturePubKey;
}
public PublicKey getEncryptionPubKey() {
return encryptionPubKey;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof PubKeyRing)) return false;
PubKeyRing that = (PubKeyRing) o;
if (signaturePubKey != null ? !signaturePubKey.equals(that.signaturePubKey) : that.signaturePubKey != null)
return false;
return !(encryptionPubKey != null ? !encryptionPubKey.equals(that.encryptionPubKey) : that.encryptionPubKey != null);
}
@Override
public int hashCode() {
int result = signaturePubKey != null ? signaturePubKey.hashCode() : 0;
result = 31 * result + (encryptionPubKey != null ? encryptionPubKey.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "PubKeyRing{" +
"signaturePubKey.hashCode()=" + (signaturePubKey != null ? signaturePubKey.hashCode() : "") +
", encryptionPubKey.hashCode()=" + (encryptionPubKey != null ? encryptionPubKey.hashCode() : "") +
'}';
}
@Override
public Messages.PubKeyRing toProtoBuf() {
return Messages.PubKeyRing.newBuilder().setSignaturePubKeyBytes(ByteString.copyFrom(signaturePubKeyBytes))
.setEncryptionPubKeyBytes(ByteString.copyFrom(encryptionPubKeyBytes)).build();
}
@Override
public String toString() {
return "PubKeyRing{" +
"signaturePubKey=" + Hex.toHexString(signaturePubKey.getEncoded()) +
", encryptionPubKey=" + Hex.toHexString(encryptionPubKey.getEncoded()) +
'}';
}
}

View File

@ -25,10 +25,11 @@ import io.bisq.wire.payload.LazyProcessedStoragePayload;
import io.bisq.wire.payload.PersistedStoragePayload;
import io.bisq.wire.payload.p2p.NodeAddress;
import io.bisq.wire.proto.Messages;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.bouncycastle.util.encoders.Hex;
import javax.annotation.Nullable;
import java.io.IOException;
@ -44,12 +45,11 @@ import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
@EqualsAndHashCode
@Slf4j
public final class CompensationRequestPayload implements LazyProcessedStoragePayload, PersistedStoragePayload {
// That object is sent over the wire, so we need to take care of version compatibility.
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
private static final Logger log = LoggerFactory.getLogger(CompensationRequestPayload.class);
public static final long TTL = TimeUnit.DAYS.toMillis(30);
// Payload
@ -246,62 +246,11 @@ public final class CompensationRequestPayload implements LazyProcessedStoragePay
return Messages.StoragePayload.newBuilder().setCompensationRequestPayload(builder).build();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CompensationRequestPayload that = (CompensationRequestPayload) o;
if (version != that.version) return false;
if (startDate != that.startDate) return false;
if (endDate != that.endDate) return false;
if (requestedBtc != that.requestedBtc) return false;
if (creationDate != that.creationDate) return false;
if (uid != null ? !uid.equals(that.uid) : that.uid != null) return false;
if (name != null ? !name.equals(that.name) : that.name != null) return false;
if (title != null ? !title.equals(that.title) : that.title != null) return false;
if (category != null ? !category.equals(that.category) : that.category != null) return false;
if (description != null ? !description.equals(that.description) : that.description != null) return false;
if (link != null ? !link.equals(that.link) : that.link != null) return false;
if (btcAddress != null ? !btcAddress.equals(that.btcAddress) : that.btcAddress != null) return false;
if (nodeAddress != null ? !nodeAddress.equals(that.nodeAddress) : that.nodeAddress != null) return false;
if (p2pStorageSignaturePubKey != null ? !p2pStorageSignaturePubKey.equals(that.p2pStorageSignaturePubKey) : that.p2pStorageSignaturePubKey != null)
return false;
if (p2pStorageSignaturePubKeyAsHex != null ? !p2pStorageSignaturePubKeyAsHex.equals(that.p2pStorageSignaturePubKeyAsHex) : that.p2pStorageSignaturePubKeyAsHex != null)
return false;
if (signature != null ? !signature.equals(that.signature) : that.signature != null) return false;
return !(feeTxId != null ? !feeTxId.equals(that.feeTxId) : that.feeTxId != null);
}
@Override
public int hashCode() {
int result = (int) version;
result = 31 * result + (uid != null ? uid.hashCode() : 0);
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (title != null ? title.hashCode() : 0);
result = 31 * result + (category != null ? category.hashCode() : 0);
result = 31 * result + (description != null ? description.hashCode() : 0);
result = 31 * result + (link != null ? link.hashCode() : 0);
result = 31 * result + (int) (startDate ^ (startDate >>> 32));
result = 31 * result + (int) (endDate ^ (endDate >>> 32));
result = 31 * result + (int) (requestedBtc ^ (requestedBtc >>> 32));
result = 31 * result + (btcAddress != null ? btcAddress.hashCode() : 0);
result = 31 * result + (nodeAddress != null ? nodeAddress.hashCode() : 0);
result = 31 * result + (int) (creationDate ^ (creationDate >>> 32));
result = 31 * result + (p2pStorageSignaturePubKey != null ? p2pStorageSignaturePubKey.hashCode() : 0);
result = 31 * result + (p2pStorageSignaturePubKeyAsHex != null ? p2pStorageSignaturePubKeyAsHex.hashCode() : 0);
result = 31 * result + (signature != null ? signature.hashCode() : 0);
result = 31 * result + (feeTxId != null ? feeTxId.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "CompensationRequestPayload{" +
"version=" + version +
", creationDate=" + getCreationDate() +
", uid='" + uid + '\'' +
", name='" + name + '\'' +
", title='" + title + '\'' +
@ -313,10 +262,11 @@ public final class CompensationRequestPayload implements LazyProcessedStoragePay
", requestedBtc=" + requestedBtc +
", btcAddress='" + btcAddress + '\'' +
", nodeAddress='" + getNodeAddress() + '\'' +
", creationDate=" + getCreationDate() +
", p2pStorageSignaturePubKeyBytes=" + Hex.toHexString(p2pStorageSignaturePubKeyBytes) +
", p2pStorageSignaturePubKeyAsHex='" + p2pStorageSignaturePubKeyAsHex + '\'' +
", signature='" + signature + '\'' +
", feeTxId='" + feeTxId + '\'' +
", extraDataMap=" + extraDataMap +
'}';
}
}

View File

@ -23,8 +23,10 @@ import io.bisq.common.app.Version;
import io.bisq.common.crypto.Sig;
import io.bisq.wire.payload.StoragePayload;
import io.bisq.wire.proto.Messages;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.util.encoders.Hex;
import javax.annotation.Nullable;
import java.io.IOException;
@ -34,28 +36,30 @@ import java.security.NoSuchProviderException;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@EqualsAndHashCode
@Slf4j
public final class Filter implements StoragePayload {
// That object is sent over the wire, so we need to take care of version compatibility.
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
private static final Logger log = LoggerFactory.getLogger(Filter.class);
private static final long TTL = TimeUnit.DAYS.toMillis(21);
// Payload
public final List<String> bannedNodeAddress;
public final List<String> bannedOfferIds;
public final List<PaymentAccountFilter> bannedPaymentAccounts;
@Getter
private String signatureAsBase64;
private byte[] publicKeyBytes;
// Should be only used in emergency case if we need to add data but do not want to break backward compatibility
// at the P2P network storage checks. The hash of the object will be used to verify if the data is valid. Any new
// field in a class would break that hash and therefore break the storage mechanism.
@Getter
@Nullable
private Map<String, String> extraDataMap;
@ -83,7 +87,7 @@ public final class Filter implements StoragePayload {
this.signatureAsBase64 = signatureAsBase64;
this.publicKeyBytes = publicKeyBytes;
this.extraDataMap = Optional.ofNullable(extraDataMap).orElse(Maps.newHashMap());
init();
}
@ -110,10 +114,6 @@ public final class Filter implements StoragePayload {
this.publicKeyBytes = new X509EncodedKeySpec(this.publicKey.getEncoded()).getEncoded();
}
public String getSignatureAsBase64() {
return signatureAsBase64;
}
@Override
public long getTTL() {
return TTL;
@ -124,13 +124,6 @@ public final class Filter implements StoragePayload {
return publicKey;
}
@Nullable
@Override
public Map<String, String> getExtraDataMap() {
return extraDataMap;
}
@Override
public Messages.StoragePayload toProtoBuf() {
List<Messages.PaymentAccountFilter> paymentAccountFilterList;
@ -147,34 +140,6 @@ public final class Filter implements StoragePayload {
return Messages.StoragePayload.newBuilder().setFilter(builder).build();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Filter)) return false;
Filter filter = (Filter) o;
if (bannedNodeAddress != null ? !bannedNodeAddress.equals(filter.bannedNodeAddress) : filter.bannedNodeAddress != null)
return false;
if (bannedOfferIds != null ? !bannedOfferIds.equals(filter.bannedOfferIds) : filter.bannedOfferIds != null)
return false;
if (bannedPaymentAccounts != null ? !bannedPaymentAccounts.equals(filter.bannedPaymentAccounts) : filter.bannedPaymentAccounts != null)
return false;
if (signatureAsBase64 != null ? !signatureAsBase64.equals(filter.signatureAsBase64) : filter.signatureAsBase64 != null)
return false;
return Arrays.equals(publicKeyBytes, filter.publicKeyBytes);
}
@Override
public int hashCode() {
int result = bannedNodeAddress != null ? bannedNodeAddress.hashCode() : 0;
result = 31 * result + (bannedOfferIds != null ? bannedOfferIds.hashCode() : 0);
result = 31 * result + (bannedPaymentAccounts != null ? bannedPaymentAccounts.hashCode() : 0);
result = 31 * result + (signatureAsBase64 != null ? signatureAsBase64.hashCode() : 0);
result = 31 * result + (publicKeyBytes != null ? Arrays.hashCode(publicKeyBytes) : 0);
return result;
}
@Override
public String toString() {
@ -182,6 +147,9 @@ public final class Filter implements StoragePayload {
"bannedNodeAddress=" + bannedNodeAddress +
", bannedOfferIds=" + bannedOfferIds +
", bannedPaymentAccounts=" + bannedPaymentAccounts +
", signatureAsBase64='" + signatureAsBase64 + '\'' +
", publicKey=" + Hex.toHexString(publicKey.getEncoded()) +
", extraDataMap=" + extraDataMap +
'}';
}
}

View File

@ -73,10 +73,8 @@ public final class OfferPayload implements StoragePayload, RequiresOwnerIsOnline
///////////////////////////////////////////////////////////////////////////////////////////
private final Direction direction;
private final String baseCurrencyCode;
private final String counterCurrencyCode;
private final String paymentMethodId;
@Nullable
private final String countryCode;
@ -101,7 +99,6 @@ public final class OfferPayload implements StoragePayload, RequiresOwnerIsOnline
// Positive values is always the usual case where you want a better price as the market.
// E.g. Buy offer with market price 400.- leads to a 360.- price.
// Sell offer with market price 400.- leads to a 440.- price.
private final double marketPriceMargin;
private final long amount;
private final long minAmount;

View File

@ -6,9 +6,11 @@ import io.bisq.wire.crypto.Hash;
import io.bisq.wire.payload.Payload;
import io.bisq.wire.proto.Messages;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import java.util.regex.Pattern;
@Slf4j
public final class NodeAddress implements Persistable, Payload {
// That object is sent over the wire, so we need to take care of version compatibility.
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
@ -48,7 +50,6 @@ public final class NodeAddress implements Persistable, Payload {
return hostName.replace(".onion", "");
}
public Messages.NodeAddress toProtoBuf() {
return Messages.NodeAddress.newBuilder().setHostName(hostName).setPort(port).build();
}

View File

@ -5,9 +5,13 @@ import io.bisq.common.persistance.Persistable;
import io.bisq.wire.payload.Payload;
import io.bisq.wire.payload.p2p.NodeAddress;
import io.bisq.wire.proto.Messages;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import java.util.Date;
@ToString
@Slf4j
public final class Peer implements Payload, Persistable {
// That object is sent over the wire, so we need to take care of version compatibility.
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
@ -50,14 +54,6 @@ public final class Peer implements Payload, Persistable {
return nodeAddress != null ? nodeAddress.hashCode() : 0;
}
@Override
public String toString() {
return "ReportedPeer{" +
"address=" + nodeAddress +
", date=" + date +
'}';
}
@Override
public Messages.Peer toProtoBuf() {
return Messages.Peer.newBuilder().setNodeAddress(nodeAddress.toProtoBuf())

View File

@ -7,8 +7,10 @@ import io.bisq.common.crypto.Sig;
import io.bisq.wire.message.p2p.PrefixedSealedAndSignedMessage;
import io.bisq.wire.payload.StoragePayload;
import io.bisq.wire.proto.Messages;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.util.encoders.Hex;
import javax.annotation.Nullable;
import java.io.IOException;
@ -30,10 +32,11 @@ import java.util.concurrent.TimeUnit;
* <p>
* Typical payloads are trade or dispute network_messages to be stored when the peer is offline.
*/
@EqualsAndHashCode
@Slf4j
public final class MailboxStoragePayload implements StoragePayload {
// That object is sent over the wire, so we need to take care of version compatibility.
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
private static final Logger log = LoggerFactory.getLogger(MailboxStoragePayload.class);
private static final long TTL = TimeUnit.DAYS.toMillis(10);
@ -57,6 +60,7 @@ public final class MailboxStoragePayload implements StoragePayload {
// Should be only used in emergency case if we need to add data but do not want to break backward compatibility
// at the P2P network storage checks. The hash of the object will be used to verify if the data is valid. Any new
// field in a class would break that hash and therefore break the storage mechanism.
@Getter
@Nullable
private Map<String, String> extraDataMap;
@ -79,7 +83,7 @@ public final class MailboxStoragePayload implements StoragePayload {
this.senderPubKeyForAddOperationBytes = senderPubKeyForAddOperationBytes;
this.receiverPubKeyForRemoveOperationBytes = receiverPubKeyForRemoveOperationBytes;
this.extraDataMap = Optional.ofNullable(extraDataMap).orElse(Maps.newHashMap());
init();
}
@ -122,37 +126,13 @@ public final class MailboxStoragePayload implements StoragePayload {
return Messages.StoragePayload.newBuilder().setMailboxStoragePayload(builder).build();
}
@Nullable
@Override
public Map<String, String> getExtraDataMap() {
return extraDataMap;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof MailboxStoragePayload)) return false;
MailboxStoragePayload that = (MailboxStoragePayload) o;
return !(prefixedSealedAndSignedMessage != null ?
!prefixedSealedAndSignedMessage.equals(that.prefixedSealedAndSignedMessage) :
that.prefixedSealedAndSignedMessage != null);
}
@Override
public int hashCode() {
return prefixedSealedAndSignedMessage != null ? prefixedSealedAndSignedMessage.hashCode() : 0;
}
@Override
public String toString() {
return "MailboxStoragePayload{" +
"prefixedSealedAndSignedMessage=" + prefixedSealedAndSignedMessage +
", senderPubKeyForAddOperation.hashCode()=" + (senderPubKeyForAddOperation != null ? senderPubKeyForAddOperation.hashCode() : "null") +
", receiverPubKeyForRemoveOperation.hashCode()=" + (receiverPubKeyForRemoveOperation != null ? receiverPubKeyForRemoveOperation.hashCode() : "null") +
", senderPubKeyForAddOperation=" + Hex.toHexString(senderPubKeyForAddOperation.getEncoded()) +
", receiverPubKeyForRemoveOperation=" + Hex.toHexString(receiverPubKeyForRemoveOperation.getEncoded()) +
", extraDataMap=" + extraDataMap +
'}';
}
}

View File

@ -28,12 +28,16 @@ import io.bisq.wire.payload.offer.OfferPayload;
import io.bisq.wire.payload.p2p.NodeAddress;
import io.bisq.wire.payload.payment.PaymentAccountPayload;
import io.bisq.wire.proto.Messages;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Utils;
import org.bouncycastle.util.encoders.Hex;
import javax.annotation.concurrent.Immutable;
import java.util.Arrays;
@EqualsAndHashCode
@Slf4j
@SuppressWarnings("WeakerAccess")
@Immutable
public final class Contract implements Payload {
@ -56,7 +60,9 @@ public final class Contract implements Payload {
private final PubKeyRing offererPubKeyRing;
@JsonExclude
private final PubKeyRing takerPubKeyRing;
@Getter
private final NodeAddress buyerNodeAddress;
@Getter
private final NodeAddress sellerNodeAddress;
private final String offererPayoutAddressString;
private final String takerPayoutAddressString;
@ -166,103 +172,6 @@ public final class Contract implements Payload {
return Price.valueOf(offerPayload.getCurrencyCode(), tradePrice);
}
public NodeAddress getBuyerNodeAddress() {
return buyerNodeAddress;
}
public NodeAddress getSellerNodeAddress() {
return sellerNodeAddress;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Contract)) return false;
Contract contract = (Contract) o;
if (tradeAmount != contract.tradeAmount) return false;
if (tradePrice != contract.tradePrice) return false;
if (isBuyerOffererAndSellerTaker != contract.isBuyerOffererAndSellerTaker) return false;
if (offerPayload != null ? !offerPayload.equals(contract.offerPayload) : contract.offerPayload != null)
return false;
if (takeOfferFeeTxID != null ? !takeOfferFeeTxID.equals(contract.takeOfferFeeTxID) : contract.takeOfferFeeTxID != null)
return false;
if (arbitratorNodeAddress != null ? !arbitratorNodeAddress.equals(contract.arbitratorNodeAddress) : contract.arbitratorNodeAddress != null)
return false;
if (offererAccountId != null ? !offererAccountId.equals(contract.offererAccountId) : contract.offererAccountId != null)
return false;
if (takerAccountId != null ? !takerAccountId.equals(contract.takerAccountId) : contract.takerAccountId != null)
return false;
if (!offererPaymentAccountPayload.equals(contract.offererPaymentAccountPayload))
return false;
if (!takerPaymentAccountPayload.equals(contract.takerPaymentAccountPayload))
return false;
if (offererPubKeyRing != null ? !offererPubKeyRing.equals(contract.offererPubKeyRing) : contract.offererPubKeyRing != null)
return false;
if (takerPubKeyRing != null ? !takerPubKeyRing.equals(contract.takerPubKeyRing) : contract.takerPubKeyRing != null)
return false;
if (buyerNodeAddress != null ? !buyerNodeAddress.equals(contract.buyerNodeAddress) : contract.buyerNodeAddress != null)
return false;
if (sellerNodeAddress != null ? !sellerNodeAddress.equals(contract.sellerNodeAddress) : contract.sellerNodeAddress != null)
return false;
if (offererPayoutAddressString != null ? !offererPayoutAddressString.equals(contract.offererPayoutAddressString) : contract.offererPayoutAddressString != null)
return false;
if (takerPayoutAddressString != null ? !takerPayoutAddressString.equals(contract.takerPayoutAddressString) : contract.takerPayoutAddressString != null)
return false;
if (!Arrays.equals(offererMultiSigPubKey, contract.offererMultiSigPubKey)) return false;
return Arrays.equals(takerMultiSigPubKey, contract.takerMultiSigPubKey);
}
@Override
public int hashCode() {
int result = offerPayload != null ? offerPayload.hashCode() : 0;
result = 31 * result + (int) (tradeAmount ^ (tradeAmount >>> 32));
result = 31 * result + (int) (tradePrice ^ (tradePrice >>> 32));
result = 31 * result + (takeOfferFeeTxID != null ? takeOfferFeeTxID.hashCode() : 0);
result = 31 * result + (arbitratorNodeAddress != null ? arbitratorNodeAddress.hashCode() : 0);
result = 31 * result + (isBuyerOffererAndSellerTaker ? 1 : 0);
result = 31 * result + (offererAccountId != null ? offererAccountId.hashCode() : 0);
result = 31 * result + (takerAccountId != null ? takerAccountId.hashCode() : 0);
result = 31 * result + (offererPaymentAccountPayload.hashCode());
result = 31 * result + (takerPaymentAccountPayload.hashCode());
result = 31 * result + (offererPubKeyRing != null ? offererPubKeyRing.hashCode() : 0);
result = 31 * result + (takerPubKeyRing != null ? takerPubKeyRing.hashCode() : 0);
result = 31 * result + (buyerNodeAddress != null ? buyerNodeAddress.hashCode() : 0);
result = 31 * result + (sellerNodeAddress != null ? sellerNodeAddress.hashCode() : 0);
result = 31 * result + (offererPayoutAddressString != null ? offererPayoutAddressString.hashCode() : 0);
result = 31 * result + (takerPayoutAddressString != null ? takerPayoutAddressString.hashCode() : 0);
result = 31 * result + (offererMultiSigPubKey != null ? Arrays.hashCode(offererMultiSigPubKey) : 0);
result = 31 * result + (takerMultiSigPubKey != null ? Arrays.hashCode(takerMultiSigPubKey) : 0);
return result;
}
@Override
public String toString() {
return "Contract{" +
"\n\toffer=" + offerPayload +
"\n\ttradeAmount=" + tradeAmount +
"\n\ttradePrice=" + tradePrice +
"\n\ttakeOfferFeeTxID='" + takeOfferFeeTxID + '\'' +
"\n\tarbitratorAddress=" + arbitratorNodeAddress +
"\n\tisBuyerOffererAndSellerTaker=" + isBuyerOffererAndSellerTaker +
"\n\toffererAccountId='" + offererAccountId + '\'' +
"\n\ttakerAccountId='" + takerAccountId + '\'' +
"\n\toffererPaymentAccountPayload=" + offererPaymentAccountPayload +
"\n\ttakerPaymentAccountPayload=" + takerPaymentAccountPayload +
"\n\toffererPubKeyRing=" + offererPubKeyRing +
"\n\ttakerPubKeyRing=" + takerPubKeyRing +
"\n\tbuyerAddress=" + buyerNodeAddress +
"\n\tsellerAddress=" + sellerNodeAddress +
"\n\toffererPayoutAddressString='" + offererPayoutAddressString + '\'' +
"\n\ttakerPayoutAddressString='" + takerPayoutAddressString + '\'' +
"\n\toffererMultiSigPubKey=" + Utils.HEX.encode(offererMultiSigPubKey) +
"\n\ttakerMultiSigPubKey=" + Utils.HEX.encode(takerMultiSigPubKey) +
"\n\tBuyerMultiSigPubKey=" + Utils.HEX.encode(getBuyerMultiSigPubKey()) +
"\n\tSellerMultiSigPubKey=" + Utils.HEX.encode(getSellerMultiSigPubKey()) +
'}';
}
@Override
public Messages.Contract toProtoBuf() {
@ -286,4 +195,30 @@ public final class Contract implements Payload {
.setOffererBtcPubKey(ByteString.copyFrom(offererMultiSigPubKey))
.setTakerBtcPubKey(ByteString.copyFrom(takerMultiSigPubKey)).build();
}
@Override
public String toString() {
return "Contract{" +
"\n\toffer=" + offerPayload +
"\n\ttradeAmount=" + tradeAmount +
"\n\ttradePrice=" + tradePrice +
"\n\ttakeOfferFeeTxID='" + takeOfferFeeTxID + '\'' +
"\n\tarbitratorAddress=" + arbitratorNodeAddress +
"\n\tisBuyerOffererAndSellerTaker=" + isBuyerOffererAndSellerTaker +
"\n\toffererAccountId='" + offererAccountId + '\'' +
"\n\ttakerAccountId='" + takerAccountId + '\'' +
"\n\toffererPaymentAccountPayload=" + offererPaymentAccountPayload +
"\n\ttakerPaymentAccountPayload=" + takerPaymentAccountPayload +
"\n\toffererPubKeyRing=" + offererPubKeyRing +
"\n\ttakerPubKeyRing=" + takerPubKeyRing +
"\n\tbuyerAddress=" + buyerNodeAddress +
"\n\tsellerAddress=" + sellerNodeAddress +
"\n\toffererPayoutAddressString='" + offererPayoutAddressString + '\'' +
"\n\ttakerPayoutAddressString='" + takerPayoutAddressString + '\'' +
"\n\toffererMultiSigPubKey=" + Hex.toHexString(offererMultiSigPubKey) +
"\n\ttakerMultiSigPubKey=" + Hex.toHexString(takerMultiSigPubKey) +
"\n\tBuyerMultiSigPubKey=" + Hex.toHexString(getBuyerMultiSigPubKey()) +
"\n\tSellerMultiSigPubKey=" + Hex.toHexString(getSellerMultiSigPubKey()) +
'}';
}
}

View File

@ -15,11 +15,12 @@ import io.bisq.wire.payload.PersistedStoragePayload;
import io.bisq.wire.payload.crypto.PubKeyRing;
import io.bisq.wire.payload.offer.OfferPayload;
import io.bisq.wire.proto.Messages;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.bitcoinj.core.Coin;
import org.bitcoinj.utils.ExchangeRate;
import org.bitcoinj.utils.Fiat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
@ -27,10 +28,10 @@ import java.security.PublicKey;
import java.util.*;
import java.util.concurrent.TimeUnit;
@ToString
@Slf4j
@Immutable
public final class TradeStatistics implements LazyProcessedStoragePayload, CapabilityRequiringPayload, PersistedStoragePayload {
private static final Logger log = LoggerFactory.getLogger(TradeStatistics.class);
@JsonExclude
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
@JsonExclude
@ -49,6 +50,7 @@ public final class TradeStatistics implements LazyProcessedStoragePayload, Capab
public final double marketPriceMargin;
public final long offerAmount;
public final long offerMinAmount;
@Getter
public final String offerId;
public final String depositTxId;
@JsonExclude
@ -56,6 +58,7 @@ public final class TradeStatistics implements LazyProcessedStoragePayload, Capab
// Should be only used in emergency case if we need to add data but do not want to break backward compatibility
// at the P2P network storage checks. The hash of the object will be used to verify if the data is valid. Any new
// field in a class would break that hash and therefore break the storage mechanism.
@Getter
@Nullable
private Map<String, String> extraDataMap;
@ -119,7 +122,6 @@ public final class TradeStatistics implements LazyProcessedStoragePayload, Capab
this.extraDataMap = Optional.ofNullable(extraDataMap).orElse(Maps.newHashMap());
}
@Override
public long getTTL() {
return TTL;
@ -137,13 +139,6 @@ public final class TradeStatistics implements LazyProcessedStoragePayload, Capab
);
}
@Nullable
@Override
public Map<String, String> getExtraDataMap() {
return extraDataMap;
}
public Date getTradeDate() {
return new Date(tradeDate);
}
@ -167,10 +162,6 @@ public final class TradeStatistics implements LazyProcessedStoragePayload, Capab
return new Volume(new ExchangeRate((Fiat) getTradePrice().getMonetary()).coinToFiat(getTradeAmount()));
}
public String getOfferId() {
return offerId;
}
@Override
public Messages.StoragePayload toProtoBuf() {
final Messages.TradeStatistics.Builder builder = Messages.TradeStatistics.newBuilder()
@ -198,35 +189,6 @@ public final class TradeStatistics implements LazyProcessedStoragePayload, Capab
// We don't include the pubKeyRing as both traders might publish it if the offerer uses an old
// version and update later (taker publishes first, then later offerer)
// We also don't include the trade date as that is set locally and different for offerer and taker
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof TradeStatistics)) return false;
TradeStatistics that = (TradeStatistics) o;
if (tradePrice != that.tradePrice) return false;
if (tradeAmount != that.tradeAmount) return false;
if (offerDate != that.offerDate) return false;
if (useMarketBasedPrice != that.useMarketBasedPrice) return false;
if (Double.compare(that.marketPriceMargin, marketPriceMargin) != 0) return false;
if (offerAmount != that.offerAmount) return false;
if (offerMinAmount != that.offerMinAmount) return false;
if (baseCurrency != null ? !baseCurrency.equals(that.baseCurrency) : that.baseCurrency != null) return false;
if (counterCurrency != null ? !counterCurrency.equals(that.counterCurrency) : that.counterCurrency != null)
return false;
if (direction != null && that.direction != null && direction.ordinal() != that.direction.ordinal())
return false;
else if ((direction == null && that.direction != null) || (direction != null && that.direction == null))
return false;
if (paymentMethodId != null ? !paymentMethodId.equals(that.paymentMethodId) : that.paymentMethodId != null)
return false;
if (getOfferId() != null ? !getOfferId().equals(that.getOfferId()) : that.getOfferId() != null) return false;
return !(depositTxId != null ? !depositTxId.equals(that.depositTxId) : that.depositTxId != null);
}
@Override
public int hashCode() {
int result;
@ -245,28 +207,33 @@ public final class TradeStatistics implements LazyProcessedStoragePayload, Capab
result = 31 * result + (int) (offerMinAmount ^ (offerMinAmount >>> 32));
result = 31 * result + (offerId != null ? offerId.hashCode() : 0);
result = 31 * result + (depositTxId != null ? depositTxId.hashCode() : 0);
result = 31 * result + (extraDataMap != null ? extraDataMap.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "TradeStatistics{" +
"baseCurrency='" + baseCurrency + '\'' +
", counterCurrency=" + counterCurrency +
", direction=" + direction +
", tradePrice=" + tradePrice +
", tradeAmount=" + tradeAmount +
", tradeDate=" + tradeDate +
", paymentMethod='" + paymentMethodId + '\'' +
", offerDate=" + offerDate +
", useMarketBasedPrice=" + useMarketBasedPrice +
", marketPriceMargin=" + marketPriceMargin +
", offerAmount=" + offerAmount +
", offerMinAmount=" + offerMinAmount +
", offerId='" + getOfferId() + '\'' +
", depositTxId='" + depositTxId + '\'' +
", pubKeyRing=" + pubKeyRing +
", hashCode=" + hashCode() +
'}';
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TradeStatistics that = (TradeStatistics) o;
if (tradePrice != that.tradePrice) return false;
if (tradeAmount != that.tradeAmount) return false;
if (offerDate != that.offerDate) return false;
if (useMarketBasedPrice != that.useMarketBasedPrice) return false;
if (Double.compare(that.marketPriceMargin, marketPriceMargin) != 0) return false;
if (offerAmount != that.offerAmount) return false;
if (offerMinAmount != that.offerMinAmount) return false;
if (baseCurrency != null ? !baseCurrency.equals(that.baseCurrency) : that.baseCurrency != null) return false;
if (counterCurrency != null ? !counterCurrency.equals(that.counterCurrency) : that.counterCurrency != null)
return false;
if (direction != that.direction) return false;
if (paymentMethodId != null ? !paymentMethodId.equals(that.paymentMethodId) : that.paymentMethodId != null)
return false;
if (offerId != null ? !offerId.equals(that.offerId) : that.offerId != null) return false;
if (depositTxId != null ? !depositTxId.equals(that.depositTxId) : that.depositTxId != null) return false;
return !(extraDataMap != null ? !extraDataMap.equals(that.extraDataMap) : that.extraDataMap != null);
}
}