Skip to content

Commit

Permalink
Merge pull request #941 from ScorexFoundation/fix-tx-serializer
Browse files Browse the repository at this point in the history
Fix transaction serialization
  • Loading branch information
aslesarenko authored Nov 23, 2023
2 parents 50dce5e + 71ad171 commit 9f372c5
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 24 deletions.
4 changes: 1 addition & 3 deletions core/shared/src/main/scala/sigma/VersionContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ object VersionContext {
*/
val MaxSupportedScriptVersion: Byte = 2 // supported versions 0, 1, 2

/** The first version of ErgoTree starting from which the JIT costing interpreter must be used.
* It must also be used for all subsequent versions (3, 4, etc).
*/
/** The first version of ErgoTree starting from which the JIT costing interpreter is used. */
val JitActivationVersion: Byte = 2

private val _defaultContext = VersionContext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import sigmastate.SType
import sigmastate.Values.EvaluatedValue
import sigmastate.interpreter.ContextExtension.VarBinding
import sigmastate.serialization.SigmaSerializer
import sigmastate.utils.{SigmaByteReader, SigmaByteWriter}
import sigmastate.utils.{SigmaByteWriter, SigmaByteReader}
import sigma.AnyValue

import scala.collection.mutable

/**
* User-defined variables to be put into context.
* Each variable is identified by `id: Byte` and can be accessed from a script
Expand All @@ -35,7 +33,6 @@ object ContextExtension {
type VarBinding = (Byte, EvaluatedValue[_ <: SType])

object serializer extends SigmaSerializer[ContextExtension, ContextExtension] {

override def serialize(obj: ContextExtension, w: SigmaByteWriter): Unit = {
val size = obj.values.size
if (size > Byte.MaxValue)
Expand All @@ -48,13 +45,13 @@ object ContextExtension {
val extSize = r.getByte()
if (extSize < 0)
error(s"Negative amount of context extension values: $extSize")
val ext = (0 until extSize)
.map(_ => (r.getByte(), r.getValue().asInstanceOf[EvaluatedValue[_ <: SType]]))
ContextExtension(mutable.LinkedHashMap(ext:_*))
}

}
val values = (0 until extSize)
.map(_ => (r.getByte(), r.getValue().asInstanceOf[EvaluatedValue[_ <: SType]]))

ContextExtension(values.toMap)
}
}
}


Expand Down
13 changes: 13 additions & 0 deletions interpreter/shared/src/main/scala/sigmastate/utils/Helpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ object Helpers {
case Right(b) => Right(f(b))
case _ => this.asInstanceOf[Either[A, B1]]
}

/** Returns a `Some` containing the `Right` value
* if it exists or a `None` if this is a `Left`.
*
* {{{
* Right(12).toOption // Some(12)
* Left(12).toOption // None
* }}}
*/
def toOption: Option[B] = source match {
case Right(value) => Some(value)
case _ => None
}
}

/** Decodes the given hex string into byte array and then uses
Expand Down
Loading

0 comments on commit 9f372c5

Please sign in to comment.