Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
nevgeny committed Oct 23, 2018
1 parent bc79474 commit b1ab0e3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions evm/src/main/scala/pravda/evm/translate/Translator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ object Translator {
}

def translateActualContract(ops: List[(Int,EVM.Op)]): Either[String, List[asm.Operation]] = {
val offset = ops.takeWhile({case (_,CodeCopy) => false case _ => true}).reverse.tail.headOption match {
case Some((_,Push(address))) => BigInt(1,address.toArray).intValue()
case _ => throw new Exception("Parse error")
val offsetEither = ops.takeWhile({case (_,CodeCopy) => false case _ => true}).reverse.tail.headOption match {
case Some((_,Push(address))) => Right(BigInt(1,address.toArray).intValue())
case _ => Left("Parse error")
}
ops.flatMap({case(ind,op) => if (ind - offset < 0) None else Some((ind - offset,op)) })

offsetEither.flatMap({offset =>
val filteredOps = ops.map({ case (ind, op) => ind - offset -> op }).filterNot(_._1 < 0).map(_._2)
Translator(filteredOps)
})
}

}

0 comments on commit b1ab0e3

Please sign in to comment.