Skip to content

Commit f7ef53a

Browse files
authored
Merge pull request #75 from input-output-hk/scala-213
Scala 2.13
2 parents 2bb9a5b + 0459cf6 commit f7ef53a

28 files changed

+94
-82
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ language: scala
44
scala:
55
- 2.12.10
66
- 2.11.12
7+
- 2.13.1
78
jdk:
89
- oraclejdk8
910
cache:

build.sbt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ description := "Cryptographic primitives for Scala"
77

88
lazy val scala212 = "2.12.10"
99
lazy val scala211 = "2.11.12"
10-
crossScalaVersions := Seq(scala212, scala211)
11-
scalaVersion := scala212
10+
lazy val scala213 = "2.13.1"
11+
12+
crossScalaVersions := Seq(scala212, scala211, scala213)
13+
scalaVersion := scala213
1214

1315
javacOptions ++=
14-
"-source" :: "1.7" ::
15-
"-target" :: "1.7" ::
16+
"-source" :: "1.8" ::
17+
"-target" :: "1.8" ::
1618
Nil
1719

1820
lazy val commonSettings = Seq(
@@ -31,17 +33,19 @@ lazy val commonSettings = Seq(
3133
)
3234

3335
libraryDependencies ++= Seq(
34-
"org.rudogma" %% "supertagged" % "1.4",
36+
"org.rudogma" %% "supertagged" % "1.5",
3537
"com.google.guava" % "guava" % "20.0",
3638
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.2",
3739
"org.whispersystems" % "curve25519-java" % "0.5.0",
3840
"org.bouncycastle" % "bcprov-jdk15on" % "1.64",
39-
"org.scorexfoundation" %% "scorex-util" % "0.1.6"
41+
"org.scorexfoundation" %% "scorex-util" % "0.1.7"
4042
)
4143

4244
libraryDependencies ++= Seq(
43-
"org.scalatest" %% "scalatest" % "3.0.+" % "test",
44-
"org.scalacheck" %% "scalacheck" % "1.13.+" % "test"
45+
"org.scalatest" %% "scalatest" % "3.1.+" % Test,
46+
"org.scalacheck" %% "scalacheck" % "1.14.+" % Test,
47+
// https://mvnrepository.com/artifact/org.scalatestplus/scalatestplus-scalacheck
48+
"org.scalatestplus" %% "scalatestplus-scalacheck" % "3.1.0.0-RC2" % Test
4549
)
4650

4751
publishMavenStyle := true

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
sbt.version=1.2.6
1+
sbt.version=1.2.8
22

src/main/scala/scorex/crypto/authds/TwoPartyDictionary.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package scorex.crypto.authds
22

33
import scorex.crypto.authds.avltree.batch.Operation
4-
import scorex.utils.ScorexEncoding
4+
import scorex.util.ScorexEncoding
55

66
import scala.util.Try
77

src/main/scala/scorex/crypto/authds/TwoPartyProofElement.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package scorex.crypto.authds
22

33
import scorex.crypto.authds.legacy.treap.Level
4-
import scorex.utils.ScorexEncoding
4+
import scorex.util.ScorexEncoding
55

66
trait TwoPartyProofElement extends ScorexEncoding {
77
val bytes: Array[Byte]

src/main/scala/scorex/crypto/authds/avltree/batch/BatchAVLProver.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class BatchAVLProver[D <: Digest, HF <: CryptographicHash[D]](val keyLength: Int
2929
(implicit val hf: HF = Blake2b256)
3030
extends AuthenticatedTreeOps[D] with ToStringHelper with ScorexLogging {
3131

32-
protected val labelLength = hf.DigestSize
32+
protected val labelLength: Int = hf.DigestSize
3333

3434
private[batch] var topNode: ProverNodes[D] = oldRootAndHeight.map(_._1).getOrElse({
3535
val t = new ProverLeaf(NegativeInfinityKey,
@@ -230,7 +230,7 @@ class BatchAVLProver[D <: Digest, HF <: CryptographicHash[D]](val keyLength: Int
230230
}
231231
}
232232

233-
loop(topNode, false)
233+
loop(topNode, keyFound = false)
234234
}
235235

236236
/**
@@ -267,7 +267,7 @@ class BatchAVLProver[D <: Digest, HF <: CryptographicHash[D]](val keyLength: Int
267267
* that contains only this info)
268268
* - Condense the sequence of values if they are mostly not randomly distributed
269269
* */
270-
def packTree(rNode: ProverNodes[D]) {
270+
def packTree(rNode: ProverNodes[D]): Unit = {
271271
// Post order traversal to pack up the tree
272272
if (!rNode.visited) {
273273
packagedTree += LabelInPackagedProof
@@ -357,21 +357,21 @@ class BatchAVLProver[D <: Digest, HF <: CryptographicHash[D]](val keyLength: Int
357357
* @return Random leaf from the tree that is not positive or negative infinity
358358
*/
359359
def randomWalk(rand: Random = new Random): Option[(ADKey, ADValue)] = {
360-
def internalNodeFn(r: InternalProverNode[D], dummy: Unit.type) =
360+
def internalNodeFn(r: InternalProverNode[D], dummy: Unit): (ProverNodes[D], Unit) =
361361
rand.nextBoolean() match {
362362
case true =>
363-
(r.right, Unit)
363+
(r.right, ())
364364
case false =>
365-
(r.left, Unit)
365+
(r.left, ())
366366
}
367367

368-
def leafFn(leaf: ProverLeaf[D], dummy: Unit.type): Option[(ADKey, ADValue)] = {
368+
def leafFn(leaf: ProverLeaf[D], dummy: Unit): Option[(ADKey, ADValue)] = {
369369
if (leaf.key sameElements PositiveInfinityKey) None
370370
else if (leaf.key sameElements NegativeInfinityKey) None
371371
else Some(leaf.key -> leaf.value)
372372
}
373373

374-
treeWalk(internalNodeFn, leafFn, Unit)
374+
treeWalk(internalNodeFn, leafFn, ())
375375
}
376376

377377
/**
@@ -442,7 +442,7 @@ class BatchAVLProver[D <: Digest, HF <: CryptographicHash[D]](val keyLength: Int
442442
var fail: Boolean = false
443443

444444
def checkTreeHelper(rNode: ProverNodes[D]): (ProverLeaf[D], ProverLeaf[D], Int) = {
445-
def myRequire(t: Boolean, s: String) = {
445+
def myRequire(t: Boolean, s: String): Unit = {
446446
if (!t) {
447447
var x = rNode.key(0).toInt
448448
if (x < 0) x = x + 256

src/main/scala/scorex/crypto/authds/avltree/batch/BatchAVLVerifier.scala

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import scorex.crypto.authds._
55
import scorex.crypto.hash._
66
import scorex.utils.ByteArray
77

8-
import scala.collection.mutable
98
import scala.util.{Failure, Try}
109

1110
/**
@@ -33,7 +32,7 @@ class BatchAVLVerifier[D <: Digest, HF <: CryptographicHash[D]](startingDigest:
3332

3433
override val collectChangedNodes: Boolean = false
3534

36-
protected val labelLength = hf.DigestSize
35+
protected val labelLength: Int = hf.DigestSize
3736

3837
/**
3938
* Returns Some[the current digest of the authenticated data structure],
@@ -169,7 +168,7 @@ class BatchAVLVerifier[D <: Digest, HF <: CryptographicHash[D]](startingDigest:
169168
// Now reconstruct the tree from the proof, which has the post order traversal
170169
// of the tree
171170
var numNodes = 0
172-
val s = new mutable.Stack[VerifierNodes[D]] // Nodes and depths
171+
var s = List.empty[VerifierNodes[D]] // Nodes and depths
173172
var i = 0
174173
var previousLeaf: Option[Leaf[D]] = None
175174
while (proof(i) != EndOfTreeInPackagedProof) {
@@ -181,7 +180,7 @@ class BatchAVLVerifier[D <: Digest, HF <: CryptographicHash[D]](startingDigest:
181180
case LabelInPackagedProof =>
182181
val label = proof.slice(i, i + labelLength).asInstanceOf[D]
183182
i += labelLength
184-
s.push(new LabelOnlyNode[D](label))
183+
s = new LabelOnlyNode[D](label) +: s
185184
previousLeaf = None
186185
case LeafInPackagedProof =>
187186
val key = if (previousLeaf.nonEmpty) {
@@ -202,17 +201,21 @@ class BatchAVLVerifier[D <: Digest, HF <: CryptographicHash[D]](startingDigest:
202201
val value = ADValue @@ proof.slice(i, i + valueLength)
203202
i += valueLength
204203
val leaf = new VerifierLeaf[D](key, value, nextLeafKey)
205-
s.push(leaf)
204+
s = leaf +: s
205+
206206
previousLeaf = Some(leaf)
207207
case _ =>
208-
val right = s.pop
209-
val left = s.pop
210-
s.push(new InternalVerifierNode(left, right, Balance @@ n))
208+
val right = s.head
209+
s = s.tail
210+
val left = s.head
211+
s = s.tail
212+
s = new InternalVerifierNode(left, right, Balance @@ n) +: s
213+
211214
}
212215
}
213216

214217
require(s.size == 1)
215-
val root = s.pop
218+
val root = s.head
216219
require(startingDigest startsWith root.label)
217220
directionsIndex = (i + 1) * 8 // Directions start right after the packed tree, which we just finished
218221
Some(root)

src/main/scala/scorex/crypto/authds/avltree/batch/Operation.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package scorex.crypto.authds.avltree.batch
22

33
import com.google.common.primitives.Longs
44
import scorex.crypto.authds.{ADKey, ADValue}
5-
import scorex.utils.ScorexEncoding
5+
import scorex.util.ScorexEncoding
66

77
import scala.util.{Failure, Success, Try}
88

src/main/scala/scorex/crypto/authds/avltree/batch/ToStringHelper.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package scorex.crypto.authds.avltree.batch
22

3-
import scorex.utils.ScorexEncoding
3+
import scorex.util.ScorexEncoding
44

55
trait ToStringHelper extends ScorexEncoding {
66
//Needed for debug (toString) only

src/main/scala/scorex/crypto/authds/legacy/avltree/AVLTree.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,6 @@ class AVLTree[HF <: CryptographicHash[_ <: Digest]](keyLength: Int,
263263

264264
val (newTopNode, changeHappened, childHeightIncreased) = modifyHelper(topNode, foundAbove = false)
265265
if (changeHappened) topNode = newTopNode
266-
AVLModifyProof(key, proofStream)
266+
AVLModifyProof(key, proofStream.toSeq) //toSeq required for 2.13
267267
}
268268
}

0 commit comments

Comments
 (0)