Skip to content

Commit 0136e19

Browse files
I-176: Enable and Apply wartremover Recursion
1 parent 25689ed commit 0136e19

File tree

7 files changed

+11
-1
lines changed

7 files changed

+11
-1
lines changed

build.sbt

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name := "scorex-core"
33

44
lazy val commonSettings = Seq(
5+
wartremoverErrors ++= Seq(Wart.Recursion),
56
scalaVersion := "2.12.3",
67
organization := "org.scorexfoundation",
78
licenses := Seq("CC0" -> url("https://creativecommons.org/publicdomain/zero/1.0/legalcode")),

examples/src/main/scala/examples/spv/Header.scala

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ case class Header(parentId: BlockId,
4949

5050
object HeaderSerializer extends Serializer[Header] {
5151
override def toBytes(h: Header): Array[Byte] = {
52+
@tailrec
5253
def interlinkBytes(links: Seq[Array[Byte]], acc: Array[Byte]): Array[Byte] = {
5354
if (links.isEmpty) {
5455
acc

examples/src/main/scala/examples/spv/KLS16Proof.scala

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package examples.spv
33
import com.google.common.primitives.{Bytes, Shorts}
44
import scorex.core.serialization.Serializer
55

6+
import scala.annotation.tailrec
67
import scala.util.Try
78

89
case class KLS16Proof(m: Int,
@@ -83,6 +84,7 @@ object KLS16ProofSerializer extends Serializer[KLS16Proof] {
8384
val i = bytes(2)
8485
val headSuffixLength = Shorts.fromByteArray(bytes.slice(3, 5))
8586
val headSuffix = HeaderSerializer.parseBytes(bytes.slice(5, 5 + headSuffixLength)).get
87+
@tailrec
8688
def parseSuffixes(index: Int, acc: Seq[Header]): (Int, Seq[Header]) = {
8789
if (acc.length == k) (index, acc.reverse)
8890
else {

examples/src/main/scala/examples/spv/KMZProof.scala

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.google.common.primitives.{Bytes, Shorts}
44
import scorex.core.serialization.Serializer
55
import scorex.crypto.encode.Base58
66

7+
import scala.annotation.tailrec
78
import scala.util.Try
89

910
case class KMZProof(m: Int, k: Int, prefixProofs: Seq[Seq[Header]], suffix: Seq[Header]) {
@@ -52,6 +53,7 @@ object KMZProofSerializer extends Serializer[KMZProof] {
5253
val headSuffix = HeaderSerializer.parseBytes(bytes.slice(4, 4 + headSuffixLength)).get
5354
val l = HeaderSerializer.BytesWithoutInterlinksLength
5455

56+
@tailrec
5557
def parseSuffixes(index: Int, acc: Seq[Header]): (Int, Seq[Header]) = {
5658
if (acc.length == k) (index, acc.reverse)
5759
else {

examples/src/main/scala/examples/spv/SpvAlgos.scala

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ object SpvAlgos {
1717
def constructInterlinkVector(parent: Header): Seq[Array[Byte]] = {
1818
val genesisId = parent.interlinks.head
1919

20+
@tailrec
2021
def generateInnerchain(curDifficulty: BigInt, acc: Seq[Array[Byte]]): Seq[Array[Byte]] = {
2122
if (parent.realDifficulty >= curDifficulty) {
2223
generateInnerchain(curDifficulty * 2, acc :+ parent.id)
@@ -42,6 +43,7 @@ object SpvAlgos {
4243
def headerById(id: Array[Byte]): Header = blockchainMap(ByteArrayWrapper(id))
4344

4445
//Algorithm 3 from the KMZ paper
46+
@tailrec
4547
def prove(boundary: Header, i: Int, acc: Seq[Seq[Header]]): Seq[Seq[Header]] = {
4648
if (i == 0) {
4749
acc

lock.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ dependencyOverrides in ThisBuild ++= Seq(
4242
"org.typelevel" % "macro-compat_2.12" % "1.1.1",
4343
"org.whispersystems" % "curve25519-java" % "0.4.1"
4444
)
45-
// LIBRARY_DEPENDENCIES_HASH d01222b74993e3faa18d4bfecf4714b9688a287d
45+
// LIBRARY_DEPENDENCIES_HASH e7ba0232e9c21b5b9111a127fc992f8784af3365

project/plugins.sbt

+2
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.2.2")
2323
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.0")
2424

2525
addSbtPlugin("com.github.sbt" % "sbt-findbugs" % "2.0.0")
26+
27+
addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.2.1")

0 commit comments

Comments
 (0)