diff --git a/core/shared/src/main/scala/sigma/util/CollectionUtil.scala b/core/shared/src/main/scala/sigma/util/CollectionUtil.scala index 357fd3b9ef..a166f48cf2 100644 --- a/core/shared/src/main/scala/sigma/util/CollectionUtil.scala +++ b/core/shared/src/main/scala/sigma/util/CollectionUtil.scala @@ -4,6 +4,7 @@ import scala.collection.{Seq, mutable, GenIterable} import scala.collection.mutable.{HashMap, ArrayBuffer} import scala.reflect.ClassTag import scala.collection.compat._ +import scorex.utils.Ints object CollectionUtil { @@ -58,14 +59,14 @@ object CollectionUtil { */ def deepHashCode[T](arr: Array[T]): Int = arr match { case arr: Array[AnyRef] => java.util.Arrays.deepHashCode(arr) - case arr: Array[Byte] => java.util.Arrays.hashCode(arr) - case arr: Array[Short] => java.util.Arrays.hashCode(arr) - case arr: Array[Int] => java.util.Arrays.hashCode(arr) - case arr: Array[Long] => java.util.Arrays.hashCode(arr) - case arr: Array[Char] => java.util.Arrays.hashCode(arr) - case arr: Array[Float] => java.util.Arrays.hashCode(arr) - case arr: Array[Double] => java.util.Arrays.hashCode(arr) - case arr: Array[Boolean] => java.util.Arrays.hashCode(arr) + case arr: Array[Byte] => Ints.fromByteArray(arr) + case arr: Array[Short] => Ints.fromByteArray(arr) + case arr: Array[Int] => Ints.fromByteArray(arr) + case arr: Array[Long] => Ints.fromByteArray(arr) + case arr: Array[Char] => Ints.fromByteArray(arr) + case arr: Array[Float] => Ints.fromByteArray(arr) + case arr: Array[Double] => Ints.fromByteArray(arr) + case arr: Array[Boolean] => Ints.fromByteArray(arr) } /** Group the given sequence of pairs by first values as keys. diff --git a/core/shared/src/main/scala/sigma/validation/RuleStatus.scala b/core/shared/src/main/scala/sigma/validation/RuleStatus.scala index 3d0451b240..43bd6ab198 100644 --- a/core/shared/src/main/scala/sigma/validation/RuleStatus.scala +++ b/core/shared/src/main/scala/sigma/validation/RuleStatus.scala @@ -1,4 +1,5 @@ package sigma.validation +import scorex.utils.Ints /** Base trait for rule status information. */ sealed trait RuleStatus { @@ -43,7 +44,7 @@ case class ReplacedRule(newRuleId: Short) extends RuleStatus { case class ChangedRule(newValue: Array[Byte]) extends RuleStatus { val statusCode: Byte = RuleStatus.ChangedRuleCode - override def hashCode(): Int = java.util.Arrays.hashCode(newValue) + override def hashCode(): Int = Ints.fromByteArray(newValue) override def canEqual(that: Any): Boolean = that.isInstanceOf[ChangedRule] diff --git a/data/shared/src/main/scala/sigma/interpreter/ProverResult.scala b/data/shared/src/main/scala/sigma/interpreter/ProverResult.scala index f04b972cb5..ea0e6b06b8 100644 --- a/data/shared/src/main/scala/sigma/interpreter/ProverResult.scala +++ b/data/shared/src/main/scala/sigma/interpreter/ProverResult.scala @@ -2,6 +2,7 @@ package sigma.interpreter import scorex.util.encode.Base16 import sigma.serialization.{SigmaByteReader, SigmaByteWriter, SigmaSerializer} +import scorex.utils.Ints /** * Proof of correctness of tx spending @@ -10,7 +11,7 @@ import sigma.serialization.{SigmaByteReader, SigmaByteWriter, SigmaSerializer} * @param extension - user-defined variables to be put into context */ class ProverResult(val proof: Array[Byte], val extension: ContextExtension) { - override def hashCode(): Int = java.util.Arrays.hashCode(proof) * 31 + extension.hashCode() + override def hashCode(): Int = Ints.fromByteArray(proof) * 31 + extension.hashCode() override def equals(obj: scala.Any): Boolean = (this eq obj.asInstanceOf[AnyRef]) || (obj match { diff --git a/interpreter/shared/src/main/scala/sigmastate/crypto/GF2_192.scala b/interpreter/shared/src/main/scala/sigmastate/crypto/GF2_192.scala index bb0ad60a84..b0323b70e3 100644 --- a/interpreter/shared/src/main/scala/sigmastate/crypto/GF2_192.scala +++ b/interpreter/shared/src/main/scala/sigmastate/crypto/GF2_192.scala @@ -29,6 +29,7 @@ package sigmastate.crypto import debox.cfor +import scorex.utils.Ints import java.util @@ -113,7 +114,7 @@ class GF2_192 extends AnyRef { } } - override def hashCode = java.util.Arrays.hashCode(word) + override def hashCode = Ints.fromByteArray(word) /** * diff --git a/interpreter/shared/src/main/scala/sigmastate/utils/Helpers.scala b/interpreter/shared/src/main/scala/sigmastate/utils/Helpers.scala index 1741531dfb..402f1cb230 100644 --- a/interpreter/shared/src/main/scala/sigmastate/utils/Helpers.scala +++ b/interpreter/shared/src/main/scala/sigmastate/utils/Helpers.scala @@ -13,6 +13,7 @@ import java.util import java.util.concurrent.locks.Lock import scala.reflect.ClassTag import scala.util.{Either, Failure, Right, Success, Try} +import scorex.utils.Ints object Helpers { @@ -64,7 +65,7 @@ object Helpers { */ @inline final def safeIdHashCode(id: Array[Byte]): Int = if (id != null && id.length >= 4) Ints.fromBytes(id(0), id(1), id(2), id(3)) - else java.util.Arrays.hashCode(id) + else Ints.fromByteArray(id) implicit class TryOps[+A](val source: Try[A]) extends AnyVal { def fold[B](onError: Throwable => B, onSuccess: A => B) = source match { diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/ErgoId.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/ErgoId.scala index 7d56b05295..f8d93ed5d3 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/ErgoId.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/ErgoId.scala @@ -19,7 +19,7 @@ class ErgoId(val _idBytes: Array[Byte]) { override def hashCode = if (_idBytes != null && _idBytes.length >= 4) Ints.fromByteArray(_idBytes) - else java.util.Arrays.hashCode(_idBytes) + else Ints.fromByteArray(_idBytes) override def equals(obj: Any): Boolean = { if (obj == null) return false diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/SecretString.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/SecretString.scala index 83ff2e0a10..772e4770dc 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/SecretString.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/SecretString.scala @@ -1,6 +1,8 @@ package org.ergoplatform.sdk import debox.cfor +import scorex.utils.Ints + import java.util @@ -73,7 +75,7 @@ final class SecretString private[sdk](val _data: Array[Char]) { override def hashCode(): Int = { checkErased() - java.util.Arrays.hashCode(_data) + Ints.fromByteArray(_data) } /** this is adapted version of java.lang.String */ diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedPublicKey.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedPublicKey.scala index 43488974b9..92e3de462f 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedPublicKey.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedPublicKey.scala @@ -5,6 +5,7 @@ import sigma.data.ProveDlog import sigmastate.crypto.DLogProtocol.DLogProverInput import sigma.serialization.{SigmaByteReader, SigmaByteWriter, SigmaSerializer} import scala.annotation.tailrec +import scorex.utils.Ints /** * Public key, its chain code and path in key tree. @@ -32,8 +33,8 @@ final class ExtendedPublicKey(/*private[secrets] */val keyBytes: Array[Byte], }) override def hashCode(): Int = { - var h = java.util.Arrays.hashCode(keyBytes) - h = 31 * h + java.util.Arrays.hashCode(chainCode) + var h = Ints.fromByteArray(keyBytes) + h = 31 * h + Ints.fromByteArray(chainCode) h = 31 * h + path.hashCode() h } diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedSecretKey.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedSecretKey.scala index 5493929ac5..732ef5ae7c 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedSecretKey.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedSecretKey.scala @@ -5,6 +5,7 @@ import sigma.data.ProveDlog import java.math.BigInteger import sigmastate.crypto.DLogProtocol.DLogProverInput import sigma.serialization.{SigmaByteReader, SigmaByteWriter, SigmaSerializer} +import scorex.utils.Ints /** * Secret, its chain code and path in key tree. @@ -40,8 +41,8 @@ final class ExtendedSecretKey(/*private[secrets]*/ val keyBytes: Array[Byte], }) override def hashCode(): Int = { - var h = java.util.Arrays.hashCode(keyBytes) - h = 31 * h + java.util.Arrays.hashCode(chainCode) + var h = Ints.fromByteArray(keyBytes) + h = 31 * h + Ints.fromByteArray(chainCode) h = 31 * h + path.hashCode() h }