mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-20 10:22:18 +01:00
Add missing contractHash from PB.Trade.
Dont set nullable trade objects if PB is not set. Remove Serializable form Proto interface Remove LookAheadObjectInputStream
This commit is contained in:
parent
b64457e869
commit
677f6c81c6
@ -19,11 +19,9 @@ package io.bisq.common;
|
||||
|
||||
import com.google.protobuf.Message;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Base interface for Envelope and Payload.
|
||||
*/
|
||||
public interface Proto extends Serializable {
|
||||
public interface Proto {
|
||||
Message toProtoMessage();
|
||||
}
|
||||
|
@ -1,184 +0,0 @@
|
||||
/*
|
||||
* This file is part of bisq.
|
||||
*
|
||||
* bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.bisq.common.io;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
//TODO remove once protobuffer is applied everywhere
|
||||
|
||||
/**
|
||||
* Based on https://github.com/ikkisoft/SerialKiller but we removed the support for a config file as
|
||||
* that introduced many dependencies (like the vulnerable commons collections).
|
||||
*/
|
||||
public class LookAheadObjectInputStream extends ObjectInputStream {
|
||||
private static final Logger log = LoggerFactory.getLogger(LookAheadObjectInputStream.class);
|
||||
|
||||
// Covers classes used in the objects sent over the P2P network.
|
||||
// We don't add all particular classes as the risk to miss one (specially at updates) is too high and a package
|
||||
// based filter gives us sufficient security.
|
||||
// This white list is not sufficient for the objects used for local persistence! We don't use any white list for those.
|
||||
private static final Pattern[] whiteListP2PNetwork = {
|
||||
Pattern.compile("io\\.bisq\\..*$"),
|
||||
Pattern.compile("org\\.bitcoinj\\..*$"),
|
||||
|
||||
Pattern.compile("java\\.lang\\.Boolean$"),
|
||||
Pattern.compile("java\\.lang\\.Enum$"),
|
||||
Pattern.compile("java\\.lang\\.Integer$"),
|
||||
Pattern.compile("java\\.lang\\.Long$"),
|
||||
Pattern.compile("java\\.lang\\.Double$"),
|
||||
Pattern.compile("java\\.lang\\.Number$"),
|
||||
|
||||
Pattern.compile("java\\.util\\.ArrayList$"),
|
||||
Pattern.compile("java\\.util\\.LinkedList$"),
|
||||
Pattern.compile("java\\.util\\.Date$"),
|
||||
Pattern.compile("java\\.util\\.HashSet$"),
|
||||
Pattern.compile("java\\.util\\.HashMap$"),
|
||||
Pattern.compile("java\\.util\\.concurrent\\..*$"),
|
||||
|
||||
Pattern.compile("org\\.bouncycastle\\.jcajce\\.provider\\.asymmetric\\.dsa\\.BCDSAPublicKey$"),
|
||||
Pattern.compile("java\\.math\\.BigInteger$"),
|
||||
|
||||
Pattern.compile("com\\.google\\.common\\.collect\\..*$"),
|
||||
|
||||
// Type Signatures
|
||||
// https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/types.html
|
||||
Pattern.compile("\\[B$"), // byte array
|
||||
Pattern.compile("\\[Ljava.lang.Object;") //long ?
|
||||
};
|
||||
|
||||
private final static Pattern[] blackList = {
|
||||
Pattern.compile("bsh\\.XThis$"),
|
||||
Pattern.compile("bsh\\.Interpreter$"),
|
||||
Pattern.compile("com\\.mchange\\.v2\\.c3p0\\.impl\\.PoolBackedDataSourceBase$"),
|
||||
Pattern.compile("org\\.apache\\.commons\\.beanutils\\.BeanComparator$"),
|
||||
Pattern.compile("org\\.apache\\.commons\\.collections\\.Transformer$"),
|
||||
Pattern.compile("org\\.apache\\.commons\\.collections\\.functors\\.InvokerTransformer$"),
|
||||
Pattern.compile("org\\.apache\\.commons\\.collections\\.functors\\.ChainedTransformer$"),
|
||||
Pattern.compile("org\\.apache\\.commons\\.collections\\.functors\\.ConstantTransformer$"),
|
||||
Pattern.compile("org\\.apache\\.commons\\.collections\\.functors\\.InstantiateTransformer$"),
|
||||
Pattern.compile("org\\.apache\\.commons\\.collections4\\.functors\\.InvokerTransformer$"),
|
||||
Pattern.compile("org\\.apache\\.commons\\.collections4\\.functors\\.ChainedTransformer$"),
|
||||
Pattern.compile("org\\.apache\\.commons\\.collections4\\.functors\\.ConstantTransformer$"),
|
||||
Pattern.compile("org\\.apache\\.commons\\.collections4\\.functors\\.InstantiateTransformer$"),
|
||||
Pattern.compile("org\\.apache\\.commons\\.collections4\\.comparators\\.TransformingComparator$"),
|
||||
Pattern.compile("org\\.apache\\.commons\\.fileupload\\.disk\\.DiskFileItem$"),
|
||||
Pattern.compile("org\\.apache\\.wicket\\.util\\.upload\\.DiskFileItem$"),
|
||||
Pattern.compile("org\\.codehaus\\.groovy\\.runtime\\.ConvertedClosure$"),
|
||||
Pattern.compile("org\\.codehaus\\.groovy\\.runtime\\.MethodClosure$"),
|
||||
Pattern.compile("org\\.hibernate\\.engine\\.spi\\.TypedValue$"),
|
||||
Pattern.compile("org\\.hibernate\\.tuple\\.component\\.AbstractComponentTuplizer$"),
|
||||
Pattern.compile("org\\.hibernate\\.tuple\\.component\\.PojoComponentTuplizer$"),
|
||||
Pattern.compile("org\\.hibernate\\.type\\.AbstractType$"),
|
||||
Pattern.compile("org\\.hibernate\\.type\\.ComponentType$"),
|
||||
Pattern.compile("org\\.hibernate\\.type\\.Type$"),
|
||||
Pattern.compile("com\\.sun\\.rowset\\.JdbcRowSetImpl$"),
|
||||
Pattern.compile("org\\.jboss\\.(weld\\.)?interceptor\\.builder\\.InterceptionModelBuilder$"),
|
||||
Pattern.compile("org\\.jboss\\.(weld\\.)?interceptor\\.builder\\.MethodReference$"),
|
||||
Pattern.compile("org\\.jboss\\.(weld\\.)?interceptor\\.proxy\\.DefaultInvocationContextFactory$"),
|
||||
Pattern.compile("org\\.jboss\\.(weld\\.)?interceptor\\.proxy\\.InterceptorMethodHandler$"),
|
||||
Pattern.compile("org\\.jboss\\.(weld\\.)?interceptor\\.reader\\.ClassMetadataInterceptorReference$"),
|
||||
Pattern.compile("org\\.jboss\\.(weld\\.)?interceptor\\.reader\\.DefaultMethodMetadata$"),
|
||||
Pattern.compile("org\\.jboss\\.(weld\\.)?interceptor\\.reader\\.ReflectiveClassMetadata$"),
|
||||
Pattern.compile("org\\.jboss\\.(weld\\.)?interceptor\\.reader\\.SimpleInterceptorMetadata$"),
|
||||
Pattern.compile("org\\.jboss\\.(weld\\.)?interceptor\\.spi\\.instance\\.InterceptorInstantiator$"),
|
||||
Pattern.compile("org\\.jboss\\.(weld\\.)?interceptor\\.spi\\.metadata\\.InterceptorReference$"),
|
||||
Pattern.compile("org\\.jboss\\.(weld\\.)?interceptor\\.spi\\.metadata\\.MethodMetadata$"),
|
||||
Pattern.compile("org\\.jboss\\.(weld\\.)?interceptor\\.spi\\.model\\.InterceptionModel$"),
|
||||
Pattern.compile("org\\.jboss\\.(weld\\.)?interceptor\\.spi\\.model\\.InterceptionType$"),
|
||||
Pattern.compile("java\\.rmi\\.registry\\.Registry$"),
|
||||
Pattern.compile("java\\.rmi\\.server\\.ObjID$"),
|
||||
Pattern.compile("java\\.rmi\\.server\\.RemoteObjectInvocationHandler$"),
|
||||
Pattern.compile("net\\.sf\\.json\\.JSONObject$"),
|
||||
Pattern.compile("javax\\.xml\\.transform\\.Templates$"),
|
||||
Pattern.compile("org\\.python\\.core\\.PyObject$"),
|
||||
Pattern.compile("org\\.python\\.core\\.PyBytecode$"),
|
||||
Pattern.compile("org\\.python\\.core\\.PyFunction$"),
|
||||
Pattern.compile("org\\.mozilla\\.javascript\\..*$"),
|
||||
Pattern.compile("org\\.apache\\.myfaces\\.context\\.servlet\\.FacesContextImpl$"),
|
||||
Pattern.compile("org\\.apache\\.myfaces\\.context\\.servlet\\.FacesContextImplBase$"),
|
||||
Pattern.compile("org\\.apache\\.myfaces\\.el\\.CompositeELResolver$"),
|
||||
Pattern.compile("org\\.apache\\.myfaces\\.el\\.unified\\.FacesELContext$"),
|
||||
Pattern.compile("org\\.apache\\.myfaces\\.view\\.facelets\\.el\\.ValueExpressionMethodExpression$"),
|
||||
Pattern.compile("com\\.sun\\.syndication\\.feed\\.impl\\.ObjectBean$"),
|
||||
Pattern.compile("org\\.springframework\\.beans\\.factory\\.ObjectFactory$"),
|
||||
Pattern.compile("org\\.springframework\\.core\\.SerializableTypeWrapper\\$MethodInvokeTypeProvider$"),
|
||||
Pattern.compile("org\\.springframework\\.aop\\.framework\\.AdvisedSupport$"),
|
||||
Pattern.compile("org\\.springframework\\.aop\\.target\\.SingletonTargetSource$"),
|
||||
Pattern.compile("org\\.springframework\\.aop\\.framework\\.JdkDynamicAopProxy$"),
|
||||
Pattern.compile("org\\.springframework\\.core\\.SerializableTypeWrapper\\$TypeProvider$"),
|
||||
Pattern.compile("java\\.util\\.PriorityQueue$"),
|
||||
Pattern.compile("java\\.lang\\.reflect\\.Proxy$"),
|
||||
Pattern.compile("java\\.util\\.Comparator$"),
|
||||
Pattern.compile("org\\.reflections\\.Reflections$"),
|
||||
|
||||
Pattern.compile("com\\.sun\\.org\\.apache\\.xalan\\.internal\\.xsltc\\.trax\\.TemplatesImpl$"),
|
||||
};
|
||||
private boolean useWhiteList;
|
||||
|
||||
|
||||
/**
|
||||
* @param inputStream The original inputStream
|
||||
* @throws IOException
|
||||
*/
|
||||
public LookAheadObjectInputStream(InputStream inputStream) throws IOException {
|
||||
this(inputStream, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param inputStream The original inputStream
|
||||
* @throws IOException
|
||||
*/
|
||||
public LookAheadObjectInputStream(InputStream inputStream, boolean useWhiteList) throws IOException {
|
||||
super(inputStream);
|
||||
|
||||
this.useWhiteList = useWhiteList;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
|
||||
String name = desc.getName();
|
||||
// log.error("resolveClass " + name);
|
||||
|
||||
for (Pattern pattern : blackList) {
|
||||
if (pattern.matcher(name).find()) {
|
||||
String msg = "We received a blacklisted class at Java deserialization: '" + name + "'" + "(regex pattern: " + pattern.toString() + ")";
|
||||
log.error(msg);
|
||||
throw new InvalidClassException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
if (useWhiteList) {
|
||||
boolean whiteListed = false;
|
||||
for (Pattern pattern : whiteListP2PNetwork) {
|
||||
if (pattern.matcher(name).find())
|
||||
whiteListed = true;
|
||||
}
|
||||
if (!whiteListed) {
|
||||
String msg = "We received a non-whitelisted class at Java deserialization: '" + name + "'";
|
||||
log.error(msg);
|
||||
throw new InvalidClassException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
return super.resolveClass(desc);
|
||||
}
|
||||
}
|
@ -17,12 +17,7 @@
|
||||
|
||||
package io.bisq.common.locale;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
//TODO
|
||||
public class CurrencyTuple implements Serializable {
|
||||
// That object is used for serializing to a Json file.
|
||||
|
||||
public class CurrencyTuple {
|
||||
public final String code;
|
||||
public final String name;
|
||||
public final int precision; // precision 4 is 1/10000 -> 0.0001 is smallest unit
|
||||
|
@ -4,10 +4,7 @@ import com.google.common.math.LongMath;
|
||||
import org.bitcoinj.core.Monetary;
|
||||
import org.bitcoinj.utils.MonetaryFormat;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
@ -20,9 +17,7 @@ import static com.google.common.base.Preconditions.checkArgument;
|
||||
* <p>
|
||||
* This class is immutable.
|
||||
*/
|
||||
public final class Altcoin implements Monetary, Comparable<Altcoin>, Serializable {
|
||||
private static final Logger log = LoggerFactory.getLogger(Altcoin.class);
|
||||
|
||||
public final class Altcoin implements Monetary, Comparable<Altcoin> {
|
||||
/**
|
||||
* The absolute value of exponent of the value of a "smallest unit" in scientific notation. We picked 4 rather than
|
||||
* 2, because in financial applications it's common to use sub-cent precision.
|
||||
|
@ -1,18 +1,13 @@
|
||||
package io.bisq.common.monetary;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
// Cloned from ExchangeRate. Use Altcoin instead of Fiat.
|
||||
public class AltcoinExchangeRate implements Serializable {
|
||||
private static final Logger log = LoggerFactory.getLogger(AltcoinExchangeRate.class);
|
||||
|
||||
public class AltcoinExchangeRate {
|
||||
/**
|
||||
* An exchange rate is expressed as a ratio of a {@link Coin} and a {@link Altcoin} amount.
|
||||
*/
|
||||
|
@ -20,8 +20,6 @@ package io.bisq.common.proto;
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.Message;
|
||||
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;
|
||||
@ -34,25 +32,21 @@ import java.util.stream.Collectors;
|
||||
@Slf4j
|
||||
public class ProtoUtil {
|
||||
|
||||
public static Set<byte[]> getByteSet(List<ByteString> byteStringList) {
|
||||
public static Set<byte[]> byteSetFromProtoByteStringList(List<ByteString> byteStringList) {
|
||||
return byteStringList.stream().map(ByteString::toByteArray).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public static String getCurrencyCode(PB.OfferPayload pbOffer) {
|
||||
return CurrencyUtil.isCryptoCurrency(pbOffer.getBaseCurrencyCode()) ? pbOffer.getBaseCurrencyCode() : pbOffer.getCounterCurrencyCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@Nullable
|
||||
public static String protoToNullableString(String proto) {
|
||||
public static String stringOrNullFromProto(String proto) {
|
||||
return "".equals(proto) ? null : proto;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static byte[] protoToToNullableByteArray(ByteString proto) {
|
||||
public static byte[] byteArrayOrNullFromProto(ByteString proto) {
|
||||
return proto.isEmpty() ? null : proto.toByteArray();
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,7 @@ public class FileManager<T extends PersistableEnvelope> {
|
||||
if (protoPersistable != null) {
|
||||
fileOutputStream = new FileOutputStream(tempFile);
|
||||
|
||||
log.info("Writing protobuffer class:{} to file:{}", persistable.getClass(), storageFile.getName());
|
||||
log.debug("Writing protobuffer class:{} to file:{}", persistable.getClass(), storageFile.getName());
|
||||
writeLock.lock();
|
||||
protoPersistable.writeDelimitedTo(fileOutputStream);
|
||||
|
||||
|
@ -1,95 +0,0 @@
|
||||
/*
|
||||
* This file is part of bisq.
|
||||
*
|
||||
* bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.bisq.common.util;
|
||||
|
||||
import io.bisq.common.io.LookAheadObjectInputStream;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class ByteArrayUtils {
|
||||
private static final Logger log = LoggerFactory.getLogger(ByteArrayUtils.class);
|
||||
private static long lastTimeStamp = System.currentTimeMillis();
|
||||
|
||||
public static <T> T byteArrayToObject(byte[] data) throws IOException, ClassNotFoundException {
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(data);
|
||||
ObjectInput in = null;
|
||||
Object result = null;
|
||||
try {
|
||||
in = new LookAheadObjectInputStream(bis, true);
|
||||
result = in.readObject();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
} finally {
|
||||
try {
|
||||
bis.close();
|
||||
} catch (IOException ex) {
|
||||
// ignore close exception
|
||||
}
|
||||
try {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
// ignore close exception
|
||||
}
|
||||
}
|
||||
//noinspection unchecked
|
||||
return (T) result;
|
||||
}
|
||||
|
||||
public static byte[] objectToByteArray(Object object) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
ObjectOutput out = null;
|
||||
byte[] result = null;
|
||||
try {
|
||||
out = new ObjectOutputStream(bos);
|
||||
out.writeObject(object);
|
||||
result = bos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
// ignore close exception
|
||||
}
|
||||
try {
|
||||
bos.close();
|
||||
} catch (IOException ex) {
|
||||
// ignore close exception
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static byte[] integerToBytes(int i) {
|
||||
byte[] result = new byte[4];
|
||||
|
||||
result[0] = (byte) (i >> 24);
|
||||
result[1] = (byte) (i >> 16);
|
||||
result[2] = (byte) (i >> 8);
|
||||
result[3] = (byte) (i /*>> 0*/);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@ -17,9 +17,7 @@
|
||||
|
||||
package io.bisq.common.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Tuple2<A, B> implements Serializable {
|
||||
public class Tuple2<A, B> {
|
||||
final public A first;
|
||||
final public B second;
|
||||
|
||||
|
@ -17,9 +17,7 @@
|
||||
|
||||
package io.bisq.common.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Tuple3<A, B, C> implements Serializable {
|
||||
public class Tuple3<A, B, C> {
|
||||
final public A first;
|
||||
final public B second;
|
||||
final public C third;
|
||||
|
@ -17,9 +17,7 @@
|
||||
|
||||
package io.bisq.common.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Tuple4<A, B, C, D> implements Serializable {
|
||||
public class Tuple4<A, B, C, D> {
|
||||
final public A first;
|
||||
final public B second;
|
||||
final public C third;
|
||||
|
@ -17,32 +17,26 @@
|
||||
|
||||
package io.bisq.common.util;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.CharStreams;
|
||||
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import com.google.gson.*;
|
||||
import io.bisq.common.crypto.LimitedKeyStrengthException;
|
||||
import io.bisq.common.io.LookAheadObjectInputStream;
|
||||
import javafx.scene.input.Clipboard;
|
||||
import javafx.scene.input.ClipboardContent;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bitcoinj.core.Utils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.crypto.Cipher;
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.net.URLConnection;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.stream.Collectors;
|
||||
@ -50,11 +44,8 @@ import java.util.stream.Collectors;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
|
||||
/**
|
||||
* General utilities
|
||||
*/
|
||||
@Slf4j
|
||||
public class Utilities {
|
||||
private static final Logger log = LoggerFactory.getLogger(Utilities.class);
|
||||
private static long lastTimeStamp = System.currentTimeMillis();
|
||||
public static final String LB = System.getProperty("line.separator");
|
||||
|
||||
@ -253,53 +244,12 @@ public class Utilities {
|
||||
return gson.fromJson(jsonString, classOfT);
|
||||
}
|
||||
|
||||
|
||||
/* public static Object deserializeHexStringToObject(String serializedHexString) {
|
||||
Object result = null;
|
||||
try {
|
||||
ByteArrayInputStream byteInputStream =
|
||||
new ByteArrayInputStream(org.bitcoinj.core.Utils.parseAsHexOrBase58(serializedHexString));
|
||||
|
||||
try (ObjectInputStream objectInputStream = new LookAheadObjectInputStream(byteInputStream)) {
|
||||
result = objectInputStream.readObject();
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
byteInputStream.close();
|
||||
|
||||
}
|
||||
|
||||
} catch (IOException i) {
|
||||
i.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static String serializeObjectToHexString(Serializable serializable) {
|
||||
String result = null;
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
try {
|
||||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
|
||||
objectOutputStream.writeObject(serializable);
|
||||
|
||||
result = org.bitcoinj.core.Utils.HEX.encode(byteArrayOutputStream.toByteArray());
|
||||
byteArrayOutputStream.close();
|
||||
objectOutputStream.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}*/
|
||||
|
||||
public static <T extends Serializable> T deserialize(byte[] data) {
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(data);
|
||||
ObjectInput in = null;
|
||||
Object result = null;
|
||||
try {
|
||||
in = new LookAheadObjectInputStream(bis, true);
|
||||
//in = new ObjectInputStream(bis);
|
||||
in = new ObjectInputStream(bis);
|
||||
result = in.readObject();
|
||||
if (!(result instanceof Serializable))
|
||||
throw new RuntimeException("Object not of type Serializable");
|
||||
@ -349,6 +299,10 @@ public class Utilities {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T extends Serializable> T cloneObject(Serializable object) {
|
||||
return deserialize(serialize(object));
|
||||
}
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private static void printElapsedTime(String msg) {
|
||||
if (!msg.isEmpty()) {
|
||||
@ -363,41 +317,6 @@ public class Utilities {
|
||||
printElapsedTime("");
|
||||
}
|
||||
|
||||
|
||||
public static Object copy(Serializable orig) throws IOException, ClassNotFoundException {
|
||||
try {
|
||||
// Write the object out to a byte array
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream out = new ObjectOutputStream(bos);
|
||||
out.writeObject(orig);
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
// Make an input stream from the byte array and read
|
||||
// a copy of the object back in.
|
||||
ObjectInputStream in = new LookAheadObjectInputStream(new ByteArrayInputStream(bos.toByteArray()), true);
|
||||
return in.readObject();
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static String readTextFileFromServer(String url, String userAgent) throws IOException {
|
||||
URLConnection connection = URI.create(url).toURL().openConnection();
|
||||
connection.setDoOutput(true);
|
||||
connection.setUseCaches(false);
|
||||
connection.setConnectTimeout((int) TimeUnit.SECONDS.toMillis(10));
|
||||
connection.addRequestProperty("User-Agent", userAgent);
|
||||
connection.connect();
|
||||
try (InputStream inputStream = connection.getInputStream()) {
|
||||
return CharStreams.toString(new InputStreamReader(inputStream, Charsets.UTF_8));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setThreadName(String name) {
|
||||
Thread.currentThread().setName(name + "-" + new Random().nextInt(10000));
|
||||
}
|
||||
@ -449,10 +368,10 @@ public class Utilities {
|
||||
}
|
||||
|
||||
public static String toTruncatedString(Object message, int maxLength) {
|
||||
if (Objects.nonNull(message)) {
|
||||
if (message != null) {
|
||||
return StringUtils.abbreviate(message.toString(), maxLength).replace("\n", "");
|
||||
}
|
||||
return "NULL";
|
||||
return "null";
|
||||
}
|
||||
|
||||
public static String toTruncatedString(Object message) {
|
||||
@ -501,7 +420,7 @@ public class Utilities {
|
||||
return id.substring(0, Math.min(8, id.length()));
|
||||
}
|
||||
|
||||
public static String collectionToString(Collection collection) {
|
||||
public static String collectionToCSV(Collection collection) {
|
||||
return collection.stream().map(i -> i.toString()).collect(Collectors.joining(",")).toString();
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,8 @@ import java.util.stream.Collectors;
|
||||
@ToString
|
||||
@Getter
|
||||
public final class Arbitrator implements StoragePayload {
|
||||
public static final long TTL = TimeUnit.DAYS.toMillis(10);
|
||||
|
||||
private final NodeAddress nodeAddress;
|
||||
private final byte[] btcPubKey;
|
||||
private final String btcAddress;
|
||||
@ -115,8 +117,8 @@ public final class Arbitrator implements StoragePayload {
|
||||
proto.getRegistrationDate(),
|
||||
proto.getRegistrationPubKey().toByteArray(),
|
||||
proto.getRegistrationSignature(),
|
||||
ProtoUtil.protoToNullableString(proto.getEmailAddress()),
|
||||
ProtoUtil.protoToNullableString(proto.getInfo()),
|
||||
ProtoUtil.stringOrNullFromProto(proto.getEmailAddress()),
|
||||
ProtoUtil.stringOrNullFromProto(proto.getInfo()),
|
||||
CollectionUtils.isEmpty(proto.getExtraDataMap()) ? null : proto.getExtraDataMap());
|
||||
}
|
||||
|
||||
@ -127,9 +129,9 @@ public final class Arbitrator implements StoragePayload {
|
||||
|
||||
@Override
|
||||
public long getTTL() {
|
||||
return TimeUnit.DAYS.toMillis(10);
|
||||
return TTL;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PublicKey getOwnerPubKey() {
|
||||
return pubKeyRing.getSignaturePubKey();
|
||||
|
@ -206,14 +206,14 @@ public final class Dispute implements NetworkPayload {
|
||||
PubKeyRing.fromProto(proto.getTraderPubKeyRing()),
|
||||
proto.getTradeDate(),
|
||||
Contract.fromProto(proto.getContract(), coreProtoResolver),
|
||||
ProtoUtil.protoToToNullableByteArray(proto.getContractHash()),
|
||||
ProtoUtil.protoToToNullableByteArray(proto.getDepositTxSerialized()),
|
||||
ProtoUtil.protoToToNullableByteArray(proto.getPayoutTxSerialized()),
|
||||
ProtoUtil.protoToNullableString(proto.getDepositTxId()),
|
||||
ProtoUtil.protoToNullableString(proto.getPayoutTxId()),
|
||||
ProtoUtil.byteArrayOrNullFromProto(proto.getContractHash()),
|
||||
ProtoUtil.byteArrayOrNullFromProto(proto.getDepositTxSerialized()),
|
||||
ProtoUtil.byteArrayOrNullFromProto(proto.getPayoutTxSerialized()),
|
||||
ProtoUtil.stringOrNullFromProto(proto.getDepositTxId()),
|
||||
ProtoUtil.stringOrNullFromProto(proto.getPayoutTxId()),
|
||||
proto.getContractAsJson(),
|
||||
ProtoUtil.protoToNullableString(proto.getMakerContractSignature()),
|
||||
ProtoUtil.protoToNullableString(proto.getTakerContractSignature()),
|
||||
ProtoUtil.stringOrNullFromProto(proto.getMakerContractSignature()),
|
||||
ProtoUtil.stringOrNullFromProto(proto.getTakerContractSignature()),
|
||||
PubKeyRing.fromProto(proto.getArbitratorPubKeyRing()),
|
||||
proto.getIsSupportTicket());
|
||||
|
||||
@ -225,7 +225,7 @@ public final class Dispute implements NetworkPayload {
|
||||
dispute.isClosedProperty.set(proto.getIsClosed());
|
||||
if (proto.hasDisputeResult())
|
||||
dispute.disputeResultProperty.set(DisputeResult.fromProto(proto.getDisputeResult()));
|
||||
dispute.disputePayoutTxId = ProtoUtil.protoToNullableString(proto.getDisputePayoutTxId());
|
||||
dispute.disputePayoutTxId = ProtoUtil.stringOrNullFromProto(proto.getDisputePayoutTxId());
|
||||
return dispute;
|
||||
}
|
||||
|
||||
|
@ -106,8 +106,8 @@ public final class Mediator implements StoragePayload {
|
||||
proto.getRegistrationDate(),
|
||||
proto.getRegistrationPubKey().toByteArray(),
|
||||
proto.getRegistrationSignature(),
|
||||
ProtoUtil.protoToNullableString(proto.getEmailAddress()),
|
||||
ProtoUtil.protoToNullableString(proto.getInfo()),
|
||||
ProtoUtil.stringOrNullFromProto(proto.getEmailAddress()),
|
||||
ProtoUtil.stringOrNullFromProto(proto.getInfo()),
|
||||
CollectionUtils.isEmpty(proto.getExtraDataMap()) ? null : proto.getExtraDataMap());
|
||||
}
|
||||
|
||||
|
@ -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()),
|
||||
ProtoUtil.protoToNullableString(proto.getOfferId()),
|
||||
ProtoUtil.stringOrNullFromProto(proto.getOfferId()),
|
||||
Coin.valueOf(proto.getCoinLockedInMultiSig()));
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -44,7 +45,8 @@ import static com.google.common.base.Preconditions.checkArgument;
|
||||
// Represents mutable state of BSQ chain data
|
||||
// We get accessed the data from different threads so we need to make sure it is thread safe.
|
||||
@Slf4j
|
||||
public class BsqChainState implements PersistableEnvelope {
|
||||
public class BsqChainState implements PersistableEnvelope, Serializable {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Static
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -273,8 +275,7 @@ public class BsqChainState implements PersistableEnvelope {
|
||||
|
||||
public BsqChainState getClone() {
|
||||
return lock.read(() -> {
|
||||
final byte[] serialize = Utilities.serialize(this);
|
||||
return Utilities.<BsqChainState>deserialize(serialize);
|
||||
return Utilities.<BsqChainState>cloneObject(this);
|
||||
});
|
||||
}
|
||||
|
||||
@ -447,15 +448,13 @@ public class BsqChainState implements PersistableEnvelope {
|
||||
// At trigger event we store the latest snapshotCandidate to disc
|
||||
if (snapshotCandidate != null) {
|
||||
// We clone because storage is in a threaded context
|
||||
final byte[] serialize = Utilities.serialize(snapshotCandidate);
|
||||
final BsqChainState cloned = Utilities.<BsqChainState>deserialize(serialize);
|
||||
final BsqChainState cloned = Utilities.<BsqChainState>cloneObject(snapshotCandidate);
|
||||
snapshotBsqChainStateStorage.queueUpForSave(cloned);
|
||||
// dont access cloned anymore with methods as locks are transient!
|
||||
log.info("Saved snapshotCandidate to Disc at height " + cloned.chainHeadHeight);
|
||||
}
|
||||
// Now we clone and keep it in memory for the next trigger
|
||||
final byte[] serialize = Utilities.serialize(this);
|
||||
snapshotCandidate = Utilities.<BsqChainState>deserialize(serialize);
|
||||
snapshotCandidate = Utilities.<BsqChainState>cloneObject(this);
|
||||
// dont access cloned anymore with methods as locks are transient!
|
||||
log.debug("Cloned new snapshotCandidate at height " + snapshotCandidate.chainHeadHeight);
|
||||
}
|
||||
|
@ -21,10 +21,11 @@ import io.bisq.common.proto.persistable.PersistablePayload;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Delegate;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class BsqBlock implements PersistablePayload {
|
||||
public class BsqBlock implements PersistablePayload, Serializable {
|
||||
@Delegate
|
||||
private final BsqBlockVo bsqBlockVo;
|
||||
|
||||
|
@ -22,10 +22,11 @@ import io.bisq.common.proto.persistable.PersistablePayload;
|
||||
import lombok.Value;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Value
|
||||
@Immutable
|
||||
public class BsqBlockVo implements PersistablePayload {
|
||||
public class BsqBlockVo implements PersistablePayload, Serializable {
|
||||
private final int height;
|
||||
private final String hash;
|
||||
private String previousBlockHash;
|
||||
|
@ -22,10 +22,11 @@ import io.bisq.common.proto.persistable.PersistablePayload;
|
||||
import lombok.Value;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Value
|
||||
@Immutable
|
||||
public class SpentInfo implements PersistablePayload {
|
||||
public class SpentInfo implements PersistablePayload, Serializable {
|
||||
private final long blockHeight;
|
||||
private final String txId;
|
||||
private final int inputIndex; // TODO not impl yet
|
||||
|
@ -21,12 +21,13 @@ import io.bisq.common.proto.persistable.PersistablePayload;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Delegate;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Data
|
||||
public class Tx implements PersistablePayload {
|
||||
public class Tx implements PersistablePayload, Serializable {
|
||||
@Delegate
|
||||
private final TxVo txVo;
|
||||
|
||||
|
@ -22,10 +22,11 @@ import io.bisq.common.proto.persistable.PersistablePayload;
|
||||
import lombok.Value;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Value
|
||||
@Immutable
|
||||
public class TxIdIndexTuple implements PersistablePayload {
|
||||
public class TxIdIndexTuple implements PersistablePayload, Serializable {
|
||||
private final String txId;
|
||||
private final int index;
|
||||
|
||||
|
@ -21,8 +21,10 @@ import io.bisq.common.proto.persistable.PersistablePayload;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Delegate;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class TxInput implements PersistablePayload {
|
||||
public class TxInput implements PersistablePayload, Serializable {
|
||||
@Delegate
|
||||
private final TxInputVo txInputVo;
|
||||
|
||||
|
@ -22,10 +22,11 @@ import io.bisq.common.proto.persistable.PersistablePayload;
|
||||
import lombok.Value;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Value
|
||||
@Immutable
|
||||
public class TxInputVo implements PersistablePayload {
|
||||
public class TxInputVo implements PersistablePayload, Serializable {
|
||||
private final String txId;
|
||||
private final int txOutputIndex;
|
||||
|
||||
|
@ -22,8 +22,10 @@ import lombok.Data;
|
||||
import lombok.experimental.Delegate;
|
||||
import org.bitcoinj.core.Utils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class TxOutput implements PersistablePayload {
|
||||
public class TxOutput implements PersistablePayload, Serializable {
|
||||
@Delegate
|
||||
private final TxOutputVo txOutputVo;
|
||||
|
||||
|
@ -26,11 +26,12 @@ import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Slf4j
|
||||
@Value
|
||||
@Immutable
|
||||
public class TxOutputVo implements PersistablePayload {
|
||||
public class TxOutputVo implements PersistablePayload, Serializable {
|
||||
private final int index;
|
||||
private final long value;
|
||||
private final String txId;
|
||||
|
@ -23,10 +23,11 @@ import io.bisq.common.proto.persistable.PersistablePayload;
|
||||
import lombok.Value;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Value
|
||||
@Immutable
|
||||
public class TxVo implements PersistablePayload {
|
||||
public class TxVo implements PersistablePayload, Serializable {
|
||||
private final String txVersion = Version.BSQ_TX_VERSION;
|
||||
private final String id;
|
||||
private final int blockHeight;
|
||||
|
@ -311,11 +311,11 @@ public class VotingManager {
|
||||
//TODO check equals code
|
||||
if (!voteItemsLists.contains(voteItemsList)) {
|
||||
voteItemsLists.add(voteItemsList);
|
||||
PersistableList<VoteItemsList> serializable = new PersistableList<>(voteItemsLists);
|
||||
serializable.setToProto((list) -> PB.PersistableEnvelope.newBuilder()
|
||||
PersistableList<VoteItemsList> list = new PersistableList<>(voteItemsLists);
|
||||
list.setToProto(e -> PB.PersistableEnvelope.newBuilder()
|
||||
.setVoteItemsList(PB.VoteItemsList.newBuilder()
|
||||
.addAllVoteItem(ProtoUtil.collectionToProto(voteItemsList.getAllVoteItemList()))).build());
|
||||
voteItemCollectionsStorage.queueUpForSave(serializable, 500);
|
||||
voteItemCollectionsStorage.queueUpForSave(list, 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -280,7 +280,7 @@ public final class OfferPayload implements StoragePayload, RequiresOwnerIsOnline
|
||||
null : proto.getAcceptedBankIdsList().stream().collect(Collectors.toList());
|
||||
List<String> acceptedCountryCodes = proto.getAcceptedCountryCodesList().isEmpty() ?
|
||||
null : proto.getAcceptedCountryCodesList().stream().collect(Collectors.toList());
|
||||
String hashOfChallenge = ProtoUtil.protoToNullableString(proto.getHashOfChallenge());
|
||||
String hashOfChallenge = ProtoUtil.stringOrNullFromProto(proto.getHashOfChallenge());
|
||||
Map<String, String> extraDataMapMap = CollectionUtils.isEmpty(proto.getExtraDataMap()) ?
|
||||
null : proto.getExtraDataMap();
|
||||
return new OfferPayload(proto.getId(),
|
||||
@ -304,9 +304,9 @@ public final class OfferPayload implements StoragePayload, RequiresOwnerIsOnline
|
||||
proto.getPaymentMethodId(),
|
||||
proto.getMakerPaymentAccountId(),
|
||||
proto.getOfferFeePaymentTxId(),
|
||||
ProtoUtil.protoToNullableString(proto.getCountryCode()),
|
||||
ProtoUtil.stringOrNullFromProto(proto.getCountryCode()),
|
||||
acceptedCountryCodes,
|
||||
ProtoUtil.protoToNullableString(proto.getBankId()),
|
||||
ProtoUtil.stringOrNullFromProto(proto.getBankId()),
|
||||
acceptedBankIds,
|
||||
proto.getVersionNr(),
|
||||
proto.getBlockHeightAtOfferCreation(),
|
||||
|
@ -2,9 +2,7 @@ package io.bisq.core.provider;
|
||||
|
||||
import io.bisq.network.http.HttpClient;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public abstract class HttpClientProvider implements Serializable {
|
||||
public abstract class HttpClientProvider {
|
||||
protected final HttpClient httpClient;
|
||||
|
||||
public HttpClientProvider(HttpClient httpClient, String baseUrl) {
|
||||
|
@ -46,12 +46,6 @@ public final class BuyerAsMakerTrade extends BuyerTrade implements MakerTrade {
|
||||
storage, btcWalletService);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createTradeProtocol() {
|
||||
tradeProtocol = new BuyerAsMakerProtocol(this);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PROTO BUFFER
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -59,7 +53,9 @@ public final class BuyerAsMakerTrade extends BuyerTrade implements MakerTrade {
|
||||
@Override
|
||||
public PB.Tradable toProtoMessage() {
|
||||
return PB.Tradable.newBuilder()
|
||||
.setBuyerAsMakerTrade(PB.BuyerAsMakerTrade.newBuilder().setTrade((PB.Trade) super.toProtoMessage())).build();
|
||||
.setBuyerAsMakerTrade(PB.BuyerAsMakerTrade.newBuilder()
|
||||
.setTrade((PB.Trade) super.toProtoMessage()))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Tradable fromProto(PB.BuyerAsMakerTrade buyerAsMakerTradeProto,
|
||||
@ -67,7 +63,8 @@ public final class BuyerAsMakerTrade extends BuyerTrade implements MakerTrade {
|
||||
BtcWalletService btcWalletService,
|
||||
CoreProtoResolver coreProtoResolver) {
|
||||
PB.Trade proto = buyerAsMakerTradeProto.getTrade();
|
||||
final BuyerAsMakerTrade trade = new BuyerAsMakerTrade(Offer.fromProto(proto.getOffer()),
|
||||
final BuyerAsMakerTrade trade = new BuyerAsMakerTrade(
|
||||
Offer.fromProto(proto.getOffer()),
|
||||
Coin.valueOf(proto.getTxFeeAsLong()),
|
||||
Coin.valueOf(proto.getTakerFeeAsLong()),
|
||||
proto.getIsCurrencyForTakerFeeBtc(),
|
||||
@ -76,7 +73,7 @@ public final class BuyerAsMakerTrade extends BuyerTrade implements MakerTrade {
|
||||
|
||||
trade.setTradeAmountAsLong(proto.getTradeAmountAsLong());
|
||||
trade.setTradePrice(proto.getTradePrice());
|
||||
trade.setTradingPeerNodeAddress(NodeAddress.fromProto(proto.getTradingPeerNodeAddress()));
|
||||
trade.setTradingPeerNodeAddress(proto.hasTradingPeerNodeAddress() ? NodeAddress.fromProto(proto.getTradingPeerNodeAddress()) : null);
|
||||
|
||||
return Trade.fromProto(trade,
|
||||
proto,
|
||||
@ -88,6 +85,11 @@ public final class BuyerAsMakerTrade extends BuyerTrade implements MakerTrade {
|
||||
// API
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
protected void createTradeProtocol() {
|
||||
tradeProtocol = new BuyerAsMakerProtocol(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleTakeOfferRequest(TradeMessage message, NodeAddress taker) {
|
||||
((MakerProtocol) tradeProtocol).handleTakeOfferRequest(message, taker);
|
||||
|
@ -50,11 +50,6 @@ public final class BuyerAsTakerTrade extends BuyerTrade implements TakerTrade {
|
||||
tradingPeerNodeAddress, storage, btcWalletService);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createTradeProtocol() {
|
||||
tradeProtocol = new BuyerAsTakerProtocol(this);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PROTO BUFFER
|
||||
@ -63,7 +58,9 @@ public final class BuyerAsTakerTrade extends BuyerTrade implements TakerTrade {
|
||||
@Override
|
||||
public PB.Tradable toProtoMessage() {
|
||||
return PB.Tradable.newBuilder()
|
||||
.setBuyerAsTakerTrade(PB.BuyerAsTakerTrade.newBuilder().setTrade((PB.Trade) super.toProtoMessage())).build();
|
||||
.setBuyerAsTakerTrade(PB.BuyerAsTakerTrade.newBuilder()
|
||||
.setTrade((PB.Trade) super.toProtoMessage()))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Tradable fromProto(PB.BuyerAsTakerTrade buyerAsTakerTradeProto,
|
||||
@ -71,13 +68,14 @@ public final class BuyerAsTakerTrade extends BuyerTrade implements TakerTrade {
|
||||
BtcWalletService btcWalletService,
|
||||
CoreProtoResolver coreProtoResolver) {
|
||||
PB.Trade proto = buyerAsTakerTradeProto.getTrade();
|
||||
return Trade.fromProto(new BuyerAsTakerTrade(Offer.fromProto(proto.getOffer()),
|
||||
return Trade.fromProto(new BuyerAsTakerTrade(
|
||||
Offer.fromProto(proto.getOffer()),
|
||||
Coin.valueOf(proto.getTradeAmountAsLong()),
|
||||
Coin.valueOf(proto.getTxFeeAsLong()),
|
||||
Coin.valueOf(proto.getTakerFeeAsLong()),
|
||||
proto.getIsCurrencyForTakerFeeBtc(),
|
||||
proto.getTradePrice(),
|
||||
NodeAddress.fromProto(proto.getTradingPeerNodeAddress()),
|
||||
proto.hasTradingPeerNodeAddress() ? NodeAddress.fromProto(proto.getTradingPeerNodeAddress()) : null,
|
||||
storage,
|
||||
btcWalletService),
|
||||
proto,
|
||||
@ -89,6 +87,11 @@ public final class BuyerAsTakerTrade extends BuyerTrade implements TakerTrade {
|
||||
// API
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
protected void createTradeProtocol() {
|
||||
tradeProtocol = new BuyerAsTakerProtocol(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void takeAvailableOffer() {
|
||||
checkArgument(tradeProtocol instanceof TakerProtocol, "tradeProtocol NOT instanceof TakerProtocol");
|
||||
|
@ -31,6 +31,8 @@ import io.bisq.network.p2p.NodeAddress;
|
||||
import lombok.Value;
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
@Value
|
||||
@ -111,26 +113,27 @@ public final class Contract implements NetworkPayload {
|
||||
// PROTO BUFFER
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static Contract fromProto(PB.Contract contract, CoreProtoResolver coreProtoResolver) {
|
||||
return new Contract(OfferPayload.fromProto(contract.getOfferPayload()),
|
||||
contract.getTradeAmount(),
|
||||
contract.getTradePrice(),
|
||||
contract.getTakerFeeTxId(),
|
||||
NodeAddress.fromProto(contract.getBuyerNodeAddress()),
|
||||
NodeAddress.fromProto(contract.getSellerNodeAddress()),
|
||||
NodeAddress.fromProto(contract.getArbitratorNodeAddress()),
|
||||
NodeAddress.fromProto(contract.getMediatorNodeAddress()),
|
||||
contract.getIsBuyerMakerAndSellerTaker(),
|
||||
contract.getMakerAccountId(),
|
||||
contract.getTakerAccountId(),
|
||||
coreProtoResolver.fromProto(contract.getMakerPaymentAccountPayload()),
|
||||
coreProtoResolver.fromProto(contract.getTakerPaymentAccountPayload()),
|
||||
PubKeyRing.fromProto(contract.getMakerPubKeyRing()),
|
||||
PubKeyRing.fromProto(contract.getTakerPubKeyRing()),
|
||||
contract.getMakerPayoutAddressString(),
|
||||
contract.getTakerPayoutAddressString(),
|
||||
contract.getMakerMultiSigPubKey().toByteArray(),
|
||||
contract.getTakerMultiSigPubKey().toByteArray());
|
||||
@Nullable
|
||||
public static Contract fromProto(PB.Contract proto, CoreProtoResolver coreProtoResolver) {
|
||||
return new Contract(OfferPayload.fromProto(proto.getOfferPayload()),
|
||||
proto.getTradeAmount(),
|
||||
proto.getTradePrice(),
|
||||
proto.getTakerFeeTxId(),
|
||||
NodeAddress.fromProto(proto.getBuyerNodeAddress()),
|
||||
NodeAddress.fromProto(proto.getSellerNodeAddress()),
|
||||
NodeAddress.fromProto(proto.getArbitratorNodeAddress()),
|
||||
NodeAddress.fromProto(proto.getMediatorNodeAddress()),
|
||||
proto.getIsBuyerMakerAndSellerTaker(),
|
||||
proto.getMakerAccountId(),
|
||||
proto.getTakerAccountId(),
|
||||
coreProtoResolver.fromProto(proto.getMakerPaymentAccountPayload()),
|
||||
coreProtoResolver.fromProto(proto.getTakerPaymentAccountPayload()),
|
||||
PubKeyRing.fromProto(proto.getMakerPubKeyRing()),
|
||||
PubKeyRing.fromProto(proto.getTakerPubKeyRing()),
|
||||
proto.getMakerPayoutAddressString(),
|
||||
proto.getTakerPayoutAddressString(),
|
||||
proto.getMakerMultiSigPubKey().toByteArray(),
|
||||
proto.getTakerMultiSigPubKey().toByteArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,11 +45,6 @@ public final class SellerAsMakerTrade extends SellerTrade implements MakerTrade
|
||||
super(offer, txFee, takerFee, isCurrencyForTakerFeeBtc, storage, btcWalletService);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createTradeProtocol() {
|
||||
tradeProtocol = new SellerAsMakerProtocol(this);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PROTO BUFFER
|
||||
@ -58,7 +53,9 @@ public final class SellerAsMakerTrade extends SellerTrade implements MakerTrade
|
||||
@Override
|
||||
public PB.Tradable toProtoMessage() {
|
||||
return PB.Tradable.newBuilder()
|
||||
.setSellerAsMakerTrade(PB.SellerAsMakerTrade.newBuilder().setTrade((PB.Trade) super.toProtoMessage())).build();
|
||||
.setSellerAsMakerTrade(PB.SellerAsMakerTrade.newBuilder()
|
||||
.setTrade((PB.Trade) super.toProtoMessage()))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Tradable fromProto(PB.SellerAsMakerTrade sellerAsMakerTradeProto,
|
||||
@ -66,7 +63,8 @@ public final class SellerAsMakerTrade extends SellerTrade implements MakerTrade
|
||||
BtcWalletService btcWalletService,
|
||||
CoreProtoResolver coreProtoResolver) {
|
||||
PB.Trade proto = sellerAsMakerTradeProto.getTrade();
|
||||
final SellerAsMakerTrade trade = new SellerAsMakerTrade(Offer.fromProto(proto.getOffer()),
|
||||
final SellerAsMakerTrade trade = new SellerAsMakerTrade(
|
||||
Offer.fromProto(proto.getOffer()),
|
||||
Coin.valueOf(proto.getTxFeeAsLong()),
|
||||
Coin.valueOf(proto.getTakerFeeAsLong()),
|
||||
proto.getIsCurrencyForTakerFeeBtc(),
|
||||
@ -75,7 +73,7 @@ public final class SellerAsMakerTrade extends SellerTrade implements MakerTrade
|
||||
|
||||
trade.setTradeAmountAsLong(proto.getTradeAmountAsLong());
|
||||
trade.setTradePrice(proto.getTradePrice());
|
||||
trade.setTradingPeerNodeAddress(NodeAddress.fromProto(proto.getTradingPeerNodeAddress()));
|
||||
trade.setTradingPeerNodeAddress(proto.hasTradingPeerNodeAddress() ? NodeAddress.fromProto(proto.getTradingPeerNodeAddress()) : null);
|
||||
|
||||
return Trade.fromProto(trade,
|
||||
proto,
|
||||
@ -87,6 +85,11 @@ public final class SellerAsMakerTrade extends SellerTrade implements MakerTrade
|
||||
// API
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
protected void createTradeProtocol() {
|
||||
tradeProtocol = new SellerAsMakerProtocol(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleTakeOfferRequest(TradeMessage message, NodeAddress taker) {
|
||||
((MakerProtocol) tradeProtocol).handleTakeOfferRequest(message, taker);
|
||||
|
@ -50,11 +50,6 @@ public final class SellerAsTakerTrade extends SellerTrade implements TakerTrade
|
||||
tradingPeerNodeAddress, storage, btcWalletService);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createTradeProtocol() {
|
||||
tradeProtocol = new SellerAsTakerProtocol(this);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PROTO BUFFER
|
||||
@ -63,7 +58,9 @@ public final class SellerAsTakerTrade extends SellerTrade implements TakerTrade
|
||||
@Override
|
||||
public PB.Tradable toProtoMessage() {
|
||||
return PB.Tradable.newBuilder()
|
||||
.setSellerAsTakerTrade(PB.SellerAsTakerTrade.newBuilder().setTrade((PB.Trade) super.toProtoMessage())).build();
|
||||
.setSellerAsTakerTrade(PB.SellerAsTakerTrade.newBuilder()
|
||||
.setTrade((PB.Trade) super.toProtoMessage()))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Tradable fromProto(PB.SellerAsTakerTrade sellerAsTakerTradeProto,
|
||||
@ -71,13 +68,14 @@ public final class SellerAsTakerTrade extends SellerTrade implements TakerTrade
|
||||
BtcWalletService btcWalletService,
|
||||
CoreProtoResolver coreProtoResolver) {
|
||||
PB.Trade proto = sellerAsTakerTradeProto.getTrade();
|
||||
return Trade.fromProto(new SellerAsTakerTrade(Offer.fromProto(proto.getOffer()),
|
||||
return Trade.fromProto(new SellerAsTakerTrade(
|
||||
Offer.fromProto(proto.getOffer()),
|
||||
Coin.valueOf(proto.getTradeAmountAsLong()),
|
||||
Coin.valueOf(proto.getTxFeeAsLong()),
|
||||
Coin.valueOf(proto.getTakerFeeAsLong()),
|
||||
proto.getIsCurrencyForTakerFeeBtc(),
|
||||
proto.getTradePrice(),
|
||||
NodeAddress.fromProto(proto.getTradingPeerNodeAddress()),
|
||||
proto.hasTradingPeerNodeAddress() ? NodeAddress.fromProto(proto.getTradingPeerNodeAddress()) : null,
|
||||
storage,
|
||||
btcWalletService),
|
||||
proto,
|
||||
@ -89,6 +87,11 @@ public final class SellerAsTakerTrade extends SellerTrade implements TakerTrade
|
||||
// API
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
protected void createTradeProtocol() {
|
||||
tradeProtocol = new SellerAsTakerProtocol(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void takeAvailableOffer() {
|
||||
checkArgument(tradeProtocol instanceof TakerProtocol, "tradeProtocol NOT instanceof TakerProtocol");
|
||||
|
@ -368,9 +368,9 @@ public abstract class Trade implements Tradable, Model {
|
||||
.setTxFeeAsLong(txFeeAsLong)
|
||||
.setTakerFeeAsLong(takerFeeAsLong)
|
||||
.setTakeOfferDate(takeOfferDate)
|
||||
.setProcessModel(processModel.toProtoMessage())
|
||||
.setTradeAmountAsLong(tradeAmountAsLong)
|
||||
.setTradePrice(tradePrice)
|
||||
.setProcessModel(processModel.toProtoMessage())
|
||||
.setState(PB.Trade.State.valueOf(state.name()))
|
||||
.setDisputeState(PB.Trade.DisputeState.valueOf(disputeState.name()))
|
||||
.setTradePeriodState(PB.Trade.TradePeriodState.valueOf(tradePeriodState.name()));
|
||||
@ -399,21 +399,19 @@ public abstract class Trade implements Tradable, Model {
|
||||
trade.setState(State.fromProto(proto.getState()));
|
||||
trade.setDisputeState(DisputeState.fromProto(proto.getDisputeState()));
|
||||
trade.setTradePeriodState(TradePeriodState.fromProto(proto.getTradePeriodState()));
|
||||
|
||||
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(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(ProtoUtil.protoToNullableString(proto.getTakerPaymentAccountId()));
|
||||
trade.setErrorMessage(ProtoUtil.protoToNullableString(proto.getErrorMessage()));
|
||||
|
||||
trade.setTakerFeeTxId(ProtoUtil.stringOrNullFromProto(proto.getTakerFeeTxId()));
|
||||
trade.setDepositTxId(ProtoUtil.stringOrNullFromProto(proto.getDepositTxId()));
|
||||
trade.setPayoutTxId(ProtoUtil.stringOrNullFromProto(proto.getPayoutTxId()));
|
||||
trade.setContract(proto.hasContract() ? Contract.fromProto(proto.getContract(), coreProtoResolver) : null);
|
||||
trade.setContractAsJson(ProtoUtil.stringOrNullFromProto(proto.getContractAsJson()));
|
||||
trade.setContractHash(ProtoUtil.byteArrayOrNullFromProto(proto.getContractHash()));
|
||||
trade.setTakerContractSignature(ProtoUtil.stringOrNullFromProto(proto.getTakerContractSignature()));
|
||||
trade.setMakerContractSignature(ProtoUtil.stringOrNullFromProto(proto.getMakerContractSignature()));
|
||||
trade.setArbitratorNodeAddress(proto.hasArbitratorNodeAddress() ? NodeAddress.fromProto(proto.getArbitratorNodeAddress()) : null);
|
||||
trade.setMediatorNodeAddress(proto.hasMediatorNodeAddress() ? NodeAddress.fromProto(proto.getMediatorNodeAddress()) : null);
|
||||
trade.setArbitratorBtcPubKey(ProtoUtil.byteArrayOrNullFromProto(proto.getArbitratorBtcPubKey()));
|
||||
trade.setTakerPaymentAccountId(ProtoUtil.stringOrNullFromProto(proto.getTakerPaymentAccountId()));
|
||||
trade.setErrorMessage(ProtoUtil.stringOrNullFromProto(proto.getErrorMessage()));
|
||||
return trade;
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ public final class PayDepositRequest extends TradeMessage {
|
||||
proto.getIsCurrencyForTakerFeeBtc(),
|
||||
rawTransactionInputs,
|
||||
proto.getChangeOutputValue(),
|
||||
ProtoUtil.protoToNullableString(proto.getChangeOutputAddress()),
|
||||
ProtoUtil.stringOrNullFromProto(proto.getChangeOutputAddress()),
|
||||
proto.getTakerMultiSigPubKey().toByteArray(),
|
||||
proto.getTakerPayoutAddressString(),
|
||||
PubKeyRing.fromProto(proto.getTakerPubKeyRing()),
|
||||
|
@ -135,8 +135,8 @@ public class ProcessModel implements Model, PersistablePayload {
|
||||
.setAccountId(accountId)
|
||||
.setPubKeyRing(pubKeyRing.toProtoMessage())
|
||||
.setChangeOutputValue(changeOutputValue)
|
||||
.setFundsNeededForTradeAsLong(fundsNeededForTradeAsLong)
|
||||
.setUseSavingsWallet(useSavingsWallet);
|
||||
.setUseSavingsWallet(useSavingsWallet)
|
||||
.setFundsNeededForTradeAsLong(fundsNeededForTradeAsLong);
|
||||
|
||||
Optional.ofNullable(takeOfferFeeTxId).ifPresent(builder::setTakeOfferFeeTxId);
|
||||
Optional.ofNullable(payoutTxSignature).ifPresent(e -> builder.setPayoutTxSignature(ByteString.copyFrom(payoutTxSignature)));
|
||||
@ -150,20 +150,19 @@ public class ProcessModel implements Model, PersistablePayload {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
public static ProcessModel fromProto(PB.ProcessModel proto, CoreProtoResolver coreProtoResolver) {
|
||||
ProcessModel processModel = new ProcessModel();
|
||||
processModel.setTradingPeer(TradingPeer.fromProto(proto.getTradingPeer(), coreProtoResolver));
|
||||
processModel.setTradingPeer(proto.hasTradingPeer() ? TradingPeer.fromProto(proto.getTradingPeer(), coreProtoResolver) : null);
|
||||
processModel.setOfferId(proto.getOfferId());
|
||||
processModel.setAccountId(proto.getAccountId());
|
||||
processModel.setPubKeyRing(PubKeyRing.fromProto(proto.getPubKeyRing()));
|
||||
processModel.setChangeOutputValue(proto.getChangeOutputValue());
|
||||
processModel.setFundsNeededForTradeAsLong(proto.getFundsNeededForTradeAsLong());
|
||||
processModel.setUseSavingsWallet(proto.getUseSavingsWallet());
|
||||
processModel.setFundsNeededForTradeAsLong(proto.getFundsNeededForTradeAsLong());
|
||||
|
||||
// nullable
|
||||
processModel.setTakeOfferFeeTxId(ProtoUtil.protoToNullableString(proto.getTakeOfferFeeTxId()));
|
||||
processModel.setPayoutTxSignature(ProtoUtil.protoToToNullableByteArray(proto.getPayoutTxSignature()));
|
||||
processModel.setTakeOfferFeeTxId(ProtoUtil.stringOrNullFromProto(proto.getTakeOfferFeeTxId()));
|
||||
processModel.setPayoutTxSignature(ProtoUtil.byteArrayOrNullFromProto(proto.getPayoutTxSignature()));
|
||||
List<NodeAddress> takerAcceptedArbitratorNodeAddresses = proto.getTakerAcceptedArbitratorNodeAddressesList().isEmpty() ?
|
||||
null : proto.getTakerAcceptedArbitratorNodeAddressesList().stream()
|
||||
.map(NodeAddress::fromProto).collect(Collectors.toList());
|
||||
@ -172,14 +171,14 @@ public class ProcessModel implements Model, PersistablePayload {
|
||||
.map(NodeAddress::fromProto).collect(Collectors.toList());
|
||||
processModel.setTakerAcceptedArbitratorNodeAddresses(takerAcceptedArbitratorNodeAddresses);
|
||||
processModel.setTakerAcceptedMediatorNodeAddresses(takerAcceptedMediatorNodeAddresses);
|
||||
processModel.setPreparedDepositTx(ProtoUtil.protoToToNullableByteArray(proto.getPreparedDepositTx()));
|
||||
processModel.setPreparedDepositTx(ProtoUtil.byteArrayOrNullFromProto(proto.getPreparedDepositTx()));
|
||||
List<RawTransactionInput> rawTransactionInputs = proto.getRawTransactionInputsList().isEmpty() ?
|
||||
null : proto.getRawTransactionInputsList().stream()
|
||||
.map(RawTransactionInput::fromProto).collect(Collectors.toList());
|
||||
processModel.setRawTransactionInputs(rawTransactionInputs);
|
||||
processModel.setChangeOutputAddress(ProtoUtil.protoToNullableString(proto.getChangeOutputAddress()));
|
||||
processModel.setMyMultiSigPubKey(ProtoUtil.protoToToNullableByteArray(proto.getMyMultiSigPubKey()));
|
||||
processModel.setTempTradingPeerNodeAddress(NodeAddress.fromProto(proto.getTempTradingPeerNodeAddress()));
|
||||
processModel.setChangeOutputAddress(ProtoUtil.stringOrNullFromProto(proto.getChangeOutputAddress()));
|
||||
processModel.setMyMultiSigPubKey(ProtoUtil.byteArrayOrNullFromProto(proto.getMyMultiSigPubKey()));
|
||||
processModel.setTempTradingPeerNodeAddress(proto.hasTempTradingPeerNodeAddress() ? NodeAddress.fromProto(proto.getTempTradingPeerNodeAddress()) : null);
|
||||
return processModel;
|
||||
}
|
||||
|
||||
|
@ -82,21 +82,27 @@ 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(ProtoUtil.protoToNullableString(proto.getAccountId()));
|
||||
tradingPeer.setPaymentAccountPayload(coreProtoResolver.fromProto(proto.getPaymentAccountPayload()));
|
||||
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(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(ProtoUtil.protoToNullableString(proto.getChangeOutputAddress()));
|
||||
return tradingPeer;
|
||||
if (proto.getDefaultInstanceForType().equals(proto)) {
|
||||
return null;
|
||||
} else {
|
||||
TradingPeer tradingPeer = new TradingPeer();
|
||||
tradingPeer.setChangeOutputValue(proto.getChangeOutputValue());
|
||||
tradingPeer.setAccountId(ProtoUtil.stringOrNullFromProto(proto.getAccountId()));
|
||||
tradingPeer.setPaymentAccountPayload(proto.hasPaymentAccountPayload() ? coreProtoResolver.fromProto(proto.getPaymentAccountPayload()) : null);
|
||||
tradingPeer.setPayoutAddressString(ProtoUtil.stringOrNullFromProto(proto.getPayoutAddressString()));
|
||||
tradingPeer.setContractAsJson(ProtoUtil.stringOrNullFromProto(proto.getContractAsJson()));
|
||||
tradingPeer.setContractSignature(ProtoUtil.stringOrNullFromProto(proto.getContractSignature()));
|
||||
tradingPeer.setSignature(ProtoUtil.byteArrayOrNullFromProto(proto.getSignature()));
|
||||
tradingPeer.setPubKeyRing(proto.hasPubKeyRing() ? PubKeyRing.fromProto(proto.getPubKeyRing()) : null);
|
||||
tradingPeer.setMultiSigPubKey(ProtoUtil.byteArrayOrNullFromProto(proto.getMultiSigPubKey()));
|
||||
List<RawTransactionInput> rawTransactionInputs = proto.getRawTransactionInputsList().isEmpty() ?
|
||||
null :
|
||||
proto.getRawTransactionInputsList().stream()
|
||||
.map(RawTransactionInput::fromProto)
|
||||
.collect(Collectors.toList());
|
||||
tradingPeer.setRawTransactionInputs(rawTransactionInputs);
|
||||
tradingPeer.setChangeOutputAddress(ProtoUtil.stringOrNullFromProto(proto.getChangeOutputAddress()));
|
||||
return tradingPeer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ public final class PreferencesPayload implements PersistableEnvelope {
|
||||
BlockChainExplorer.fromProto(proto.getBlockChainExplorerMainNet()),
|
||||
BlockChainExplorer.fromProto(proto.getBlockChainExplorerTestNet()),
|
||||
BlockChainExplorer.fromProto(proto.getBsqBlockChainExplorer()),
|
||||
ProtoUtil.protoToNullableString(proto.getBackupDirectory()),
|
||||
ProtoUtil.stringOrNullFromProto(proto.getBackupDirectory()),
|
||||
proto.getAutoSelectArbitrators(),
|
||||
Maps.newHashMap(proto.getDontShowAgainMapMap()),
|
||||
proto.getTacAccepted(),
|
||||
@ -156,10 +156,10 @@ public final class PreferencesPayload implements PersistableEnvelope {
|
||||
proto.getWithdrawalTxFeeInBytes(),
|
||||
proto.getUseCustomWithdrawalTxFee(),
|
||||
proto.getMaxPriceDistanceInPercent(),
|
||||
ProtoUtil.protoToNullableString(proto.getOfferBookChartScreenCurrencyCode()),
|
||||
ProtoUtil.protoToNullableString(proto.getTradeChartsScreenCurrencyCode()),
|
||||
ProtoUtil.protoToNullableString(proto.getBuyScreenCurrencyCode()),
|
||||
ProtoUtil.protoToNullableString(proto.getSellScreenCurrencyCode()),
|
||||
ProtoUtil.stringOrNullFromProto(proto.getOfferBookChartScreenCurrencyCode()),
|
||||
ProtoUtil.stringOrNullFromProto(proto.getTradeChartsScreenCurrencyCode()),
|
||||
ProtoUtil.stringOrNullFromProto(proto.getBuyScreenCurrencyCode()),
|
||||
ProtoUtil.stringOrNullFromProto(proto.getSellScreenCurrencyCode()),
|
||||
proto.getTradeStatisticsTickUnitIndex(),
|
||||
proto.getResyncSpvRequested(),
|
||||
proto.getSortMarketCurrenciesNumerically(),
|
||||
|
@ -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));
|
||||
persist();
|
||||
|
@ -95,7 +95,7 @@ public class UserPayload implements PersistableEnvelope {
|
||||
|
||||
public static UserPayload fromProto(PB.UserPayload proto, CoreProtoResolver coreProtoResolver) {
|
||||
return new UserPayload(
|
||||
ProtoUtil.protoToNullableString(proto.getAccountId()),
|
||||
ProtoUtil.stringOrNullFromProto(proto.getAccountId()),
|
||||
proto.getPaymentAccountsList().isEmpty() ? new HashSet<>() : new HashSet<>(proto.getPaymentAccountsList().stream()
|
||||
.map(e -> PaymentAccount.fromProto(e, coreProtoResolver))
|
||||
.collect(Collectors.toSet())),
|
||||
|
@ -114,7 +114,7 @@ public class EncryptionService {
|
||||
|
||||
|
||||
/**
|
||||
* @param data Any serializable object. Will be converted into a byte array using Java serialisation.
|
||||
* @param data
|
||||
* @return Hash of data
|
||||
*/
|
||||
public static byte[] getHash(NetworkPayload data) {
|
||||
|
@ -38,14 +38,14 @@ public final class NodeAddress implements PersistablePayload, NetworkPayload {
|
||||
// PROTO BUFFER
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static NodeAddress fromProto(PB.NodeAddress proto) {
|
||||
return new NodeAddress(proto.getHostName(), proto.getPort());
|
||||
}
|
||||
|
||||
public PB.NodeAddress toProtoMessage() {
|
||||
return PB.NodeAddress.newBuilder().setHostName(hostName).setPort(port).build();
|
||||
}
|
||||
|
||||
public static NodeAddress fromProto(PB.NodeAddress proto) {
|
||||
return new NodeAddress(proto.getHostName(), proto.getPort());
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// API
|
||||
|
@ -1,20 +1,10 @@
|
||||
package io.bisq.network.p2p;
|
||||
|
||||
import io.bisq.common.util.ByteArrayUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.Random;
|
||||
import java.util.zip.DataFormatException;
|
||||
import java.util.zip.Deflater;
|
||||
import java.util.zip.Inflater;
|
||||
|
||||
@Slf4j
|
||||
public class Utils {
|
||||
|
||||
public static int findFreeSystemPort() {
|
||||
try {
|
||||
ServerSocket server = new ServerSocket(0);
|
||||
@ -25,56 +15,4 @@ public class Utils {
|
||||
return new Random().nextInt(10000) + 50000;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] compress(Serializable input) {
|
||||
return compress(ByteArrayUtils.objectToByteArray(input));
|
||||
}
|
||||
|
||||
private static byte[] compress(byte[] input) {
|
||||
Deflater compressor = new Deflater();
|
||||
compressor.setLevel(Deflater.BEST_SPEED);
|
||||
compressor.setInput(input);
|
||||
compressor.finish();
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);
|
||||
byte[] buf = new byte[8192];
|
||||
while (!compressor.finished()) {
|
||||
int count = compressor.deflate(buf);
|
||||
bos.write(buf, 0, count);
|
||||
}
|
||||
try {
|
||||
bos.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
return bos.toByteArray();
|
||||
}
|
||||
|
||||
private static byte[] decompress(byte[] compressedData, int length) {
|
||||
Inflater inflater = new Inflater();
|
||||
inflater.setInput(compressedData, 0, length);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(length);
|
||||
byte[] buf = new byte[8192];
|
||||
while (!inflater.finished()) {
|
||||
try {
|
||||
int count = inflater.inflate(buf);
|
||||
bos.write(buf, 0, count);
|
||||
} catch (DataFormatException e) {
|
||||
log.error(e.toString());
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
bos.close();
|
||||
} catch (IOException e) {
|
||||
log.error(e.toString());
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return bos.toByteArray();
|
||||
}
|
||||
|
||||
public static Serializable decompress(byte[] compressedData) throws IOException, ClassNotFoundException {
|
||||
return (Serializable) ByteArrayUtils.byteArrayToObject(decompress(compressedData, compressedData.length));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ public class Connection implements MessageListener {
|
||||
private volatile boolean stopped;
|
||||
private PeerType peerType;
|
||||
private final ObjectProperty<NodeAddress> peersNodeAddressProperty = new SimpleObjectProperty<>();
|
||||
private final List<Tuple2<Long, Serializable>> messageTimeStamps = new ArrayList<>();
|
||||
private final List<Tuple2<Long, NetworkEnvelope>> messageTimeStamps = new ArrayList<>();
|
||||
private final CopyOnWriteArraySet<MessageListener> messageListeners = new CopyOnWriteArraySet<>();
|
||||
private volatile long lastSendTimeStamp = 0;
|
||||
|
||||
@ -815,8 +815,6 @@ public class Connection implements MessageListener {
|
||||
return;
|
||||
}
|
||||
|
||||
// Then check data throttle limit. Do that for non-message type objects as well,
|
||||
// so that's why we use serializable here.
|
||||
if (connection.violatesThrottleLimit(networkEnvelope)
|
||||
&& reportInvalidRequest(RuleViolation.THROTTLE_LIMIT_EXCEEDED))
|
||||
return;
|
||||
|
@ -41,6 +41,6 @@ public final class GetUpdatedDataRequest implements SendersNodeAddressMessage, G
|
||||
public static GetUpdatedDataRequest fromProto(PB.GetUpdatedDataRequest proto) {
|
||||
return new GetUpdatedDataRequest(NodeAddress.fromProto(proto.getSenderNodeAddress()),
|
||||
proto.getNonce(),
|
||||
ProtoUtil.getByteSet(proto.getExcludedKeysList()));
|
||||
ProtoUtil.byteSetFromProtoByteStringList(proto.getExcludedKeysList()));
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,6 @@ public final class PreliminaryGetDataRequest implements AnonymousMessage, GetDat
|
||||
|
||||
public static PreliminaryGetDataRequest fromProto(PB.PreliminaryGetDataRequest proto) {
|
||||
return new PreliminaryGetDataRequest(proto.getNonce(),
|
||||
ProtoUtil.getByteSet(proto.getExcludedKeysList()));
|
||||
ProtoUtil.byteSetFromProtoByteStringList(proto.getExcludedKeysList()));
|
||||
}
|
||||
}
|
||||
|
@ -711,8 +711,6 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
|
||||
|
||||
/**
|
||||
* Used as container for calculating cryptographic hash of data and sequenceNumber.
|
||||
* Needs to be Serializable because we convert the object to a byte array via java serialization
|
||||
* before calculating the hash.
|
||||
*/
|
||||
@ToString
|
||||
public static final class DataAndSeqNrPair implements NetworkPayload {
|
||||
|
@ -18,7 +18,6 @@
|
||||
package io.bisq.network.p2p.storage;
|
||||
|
||||
import io.bisq.common.proto.persistable.PersistableEnvelope;
|
||||
import io.bisq.common.util.Utilities;
|
||||
import io.bisq.generated.protobuffer.PB;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@ -40,7 +39,7 @@ public class SequenceNumberMap implements PersistableEnvelope {
|
||||
}
|
||||
|
||||
public static SequenceNumberMap clone(SequenceNumberMap map) {
|
||||
return new SequenceNumberMap(Utilities.deserialize(Utilities.serialize(map.getHashMap())));
|
||||
return new SequenceNumberMap(map.getHashMap());
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,8 +14,10 @@ import io.bisq.network.p2p.seed.SeedNodesRepository;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.security.*;
|
||||
import java.io.File;
|
||||
import java.security.KeyPair;
|
||||
import java.security.KeyPairGenerator;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
@ -34,42 +36,6 @@ public class TestUtils {
|
||||
return keyPair;
|
||||
}
|
||||
|
||||
|
||||
public static byte[] sign(PrivateKey privateKey, Serializable data)
|
||||
throws SignatureException, NoSuchAlgorithmException, InvalidKeyException {
|
||||
Signature sig = Signature.getInstance("SHA1withDSA");
|
||||
sig.initSign(privateKey);
|
||||
sig.update(objectToByteArray(data));
|
||||
return sig.sign();
|
||||
}
|
||||
|
||||
public static byte[] objectToByteArray(Object object) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
ObjectOutput out = null;
|
||||
byte[] result = null;
|
||||
try {
|
||||
out = new ObjectOutputStream(bos);
|
||||
out.writeObject(object);
|
||||
result = bos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
// ignore close exception
|
||||
}
|
||||
try {
|
||||
bos.close();
|
||||
} catch (IOException ex) {
|
||||
// ignore close exception
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static DummySeedNode getAndStartSeedNode(int port, boolean useLocalhostForP2P, Set<NodeAddress> seedNodes) throws InterruptedException {
|
||||
DummySeedNode seedNode;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user