Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.0.0] Header.bytes method implementation #975

Closed
wants to merge 83 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
105bd4e
unused mapReduce removed
kushti Jan 15, 2024
8168ea0
DoubleOps removed
kushti Jan 15, 2024
c33801a
unused imports in SigmaDslImpl.scala
kushti Jan 15, 2024
bd27625
removing unused endPass; more unused imports
kushti Jan 15, 2024
d378c3b
fixing Coll.mapReduce test
kushti Jan 15, 2024
9613050
Merge pull request #949 from ScorexFoundation/unused-code
aslesarenko Feb 19, 2024
3865cd1
removing more unused arguments
kushti Mar 21, 2024
059cac1
more unused code removed
kushti Mar 29, 2024
08d6b12
unused SSymName.isImportedBy removed
kushti Apr 2, 2024
de8d3cc
unused PassConfig.withConstantPropagation removed
kushti Apr 2, 2024
11c6fe9
CoreByteReader scaladoc cleared
kushti Apr 2, 2024
e8978e3
unused LambdaOps.{>>,<<}
kushti Apr 2, 2024
4771208
v5.0.14-RC: ScalaDoc for Extensions
aslesarenko Apr 4, 2024
881ef94
Merge remote-tracking branch 'origin/v5.0.14-RC' into v5.0.14-RC
aslesarenko Apr 4, 2024
fcb7229
v5.0.14-RC: rollback potentially breaking changes
aslesarenko Apr 4, 2024
5899701
v5.0.14-RC: Added ScalaDocs for CoreXXX classes
aslesarenko Apr 4, 2024
de8c362
v5.0.14-RC: CFunc removed
aslesarenko Apr 4, 2024
6196e90
v5.0.14-RC: ScalaDoc for ReflectionData is improved
aslesarenko Apr 4, 2024
2b1e49a
RuntimeIRContext removed
kushti Apr 4, 2024
e8724b8
Merge branch 'develop' of github.com:ScorexFoundation/sigmastate-inte…
kushti Apr 4, 2024
dcec230
xor_eval rollback
kushti Apr 4, 2024
35c2a7f
Merge pull request #943 from ScorexFoundation/v5.0.14-RC
aslesarenko Apr 4, 2024
810ca16
IRContext cleared
kushti Apr 5, 2024
f2ad569
Merge pull request #957 from ScorexFoundation/unused-code
aslesarenko Apr 5, 2024
bb6224c
removing unused code from ContractsTestkit, ErgoScriptTestkit, and Me…
kushti Apr 9, 2024
9c93753
removing unused code from SigmaTestingData
kushti Apr 15, 2024
a9cf903
SigmaDsl.toBigInteger/BigInt removed
kushti Apr 17, 2024
7562e33
unused SigmaDslBuilderAdapter.groupGenerator removed
kushti Apr 23, 2024
2590bfa
bigInt predefined function
kushti Apr 24, 2024
7ada12a
big int related methods back, TestingInterpreterSpecification.soundne…
kushti Apr 27, 2024
e0795c5
implicits removed #1
kushti Apr 27, 2024
7f01f11
rolling back implicits in benchmarkCases
kushti Apr 27, 2024
691c5ee
CoreArrayByteOps removed
kushti Apr 27, 2024
9bae6dd
Merge pull request #961 from ScorexFoundation/unused-code
aslesarenko Apr 29, 2024
4532592
es-bigint: fixes in ScalaDocs
aslesarenko May 1, 2024
ad2b0f8
Merge pull request #967 from ScorexFoundation/es-bigint
aslesarenko May 1, 2024
60660f2
i956-box-in-register: moved Value to sigma-data
aslesarenko May 2, 2024
1177d09
i956-box-in-register: tests for Box Value toHex/fromHex
aslesarenko May 2, 2024
42e79d7
i956-box-in-register: cleanup
aslesarenko May 2, 2024
83a7e70
i956-box-in-register: Iso ScalaDoc + imports cleanup
aslesarenko May 3, 2024
85b1382
Merge pull request #971 from ScorexFoundation/i956-box-in-register
aslesarenko May 3, 2024
acecce0
[sigma-js]: bump version 0.4.2 + update sigma-js/README.md
aslesarenko May 3, 2024
92e2d77
close #974 : Header.bytes method implementation
kushti May 6, 2024
038afc7
Merge branch 'develop' of github.com:ScorexFoundation/sigmastate-inte…
kushti May 6, 2024
2ad11df
i966-template-compiler: use default values of parameters in compiler env
aslesarenko May 9, 2024
98fd5b7
i966-template-compiler: fix type of ContractParam field
aslesarenko May 9, 2024
232c25d
i966-template-compiler: fix for Scala 2.11
aslesarenko May 9, 2024
eb6270c
i966-template-compiler: create ConstantPlaceholder for each parameter…
aslesarenko May 12, 2024
6abf292
i966-template-compiler: added ErgoTreeUtils.explainTreeHeader
aslesarenko May 12, 2024
efabf24
i966-template-compiler: test ContractTemplate.applyTemplate method
aslesarenko May 12, 2024
dcee258
i966-template-compiler: more tests for CompilerTemplate.applyTemplate
aslesarenko May 12, 2024
ba6abad
i966-template-compiler: fix ErgoTreeUtilsSpec
aslesarenko May 12, 2024
28f7e15
i966-template-compiler: addressed review comments
aslesarenko May 12, 2024
8af5260
Merge pull request #977 from ScorexFoundation/i966-template-compiler
aslesarenko May 12, 2024
d6efd22
v6.0.0-fix-tests: necessary changes due to MaxSupportedVersion upgrade
aslesarenko May 14, 2024
302b09d
refactor-ir-cake: removed Library trait (merged with Scalan)
aslesarenko May 14, 2024
f0c34e6
Merge pull request #985 from ScorexFoundation/v6.0.0-fix-tests
kushti May 14, 2024
3ffafe7
refactor-ir-cake: removed SigmaLibrary.scala
aslesarenko May 15, 2024
30d3bd9
refactor-ir-cake: Scalan moved to sigma.compiler package
aslesarenko May 15, 2024
bd0feb0
refactor-ir-cake: IRContext moved to sigma.compiler
aslesarenko May 15, 2024
f4bd542
refactor-ir-cake: everything is assembled in Scalan cake
aslesarenko May 15, 2024
26da1fa
refactor-ir-cake: Scalan renamed to IRContext
aslesarenko May 15, 2024
9c9ddc5
refactor-ir-cake: `staged` package removed
aslesarenko May 16, 2024
291f255
refactor-ir-cake: IR classes moved to sigma.compiler.ir package
aslesarenko May 16, 2024
7247cf8
refactor-ir-cake: move classes around in sigma.compiler.ir
aslesarenko May 16, 2024
80114f1
refactor-ir-cake: SigmaCompiler moved to sigma.compiler package
aslesarenko May 16, 2024
66daf52
refactor-ir-cake: wrappers moved to sigma.compiler.ir.wrappers package
aslesarenko May 16, 2024
baab0a8
refactor-ir-cake: wrappers moved to sigma.compiler.ir.wrappers packag…
aslesarenko May 16, 2024
7c18eef
refactor-ir-cake: wrappers moved to sigma.compiler.ir.wrappers packag…
aslesarenko May 16, 2024
3dd55aa
refactor-ir-cake: SizeOf, CostOf removed from IR + more ScalaDocs
aslesarenko May 16, 2024
f56df6a
refactor-ir-cake: removed WSpecialPredefs.scala
aslesarenko May 16, 2024
318c05b
Merge branch 'refs/heads/refactor-ir-cake' into v6.0.0-refactor-ir-cake
aslesarenko May 16, 2024
12a958c
Option[T] (de)serialization
kushti May 17, 2024
4f2fb23
versioning and tests
kushti May 17, 2024
553bee8
refactor-ir-cake: add ScalaDoc
aslesarenko May 21, 2024
2b72e1a
Merge pull request #986 from ScorexFoundation/refactor-ir-cake
aslesarenko May 21, 2024
a63631f
Merge remote-tracking branch 'refs/remotes/origin/develop' into v6.0.…
aslesarenko May 21, 2024
3fe08a0
Merge pull request #987 from ScorexFoundation/v6.0.0-refactor-ir-cake
kushti May 29, 2024
b78ff7a
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Jun 3, 2024
bc71b2f
todo removed, tests improved
kushti Jun 3, 2024
ea91fae
Some(None) test
kushti Jun 3, 2024
2baf8ca
Merge pull request #990 from ScorexFoundation/i659
kushti Jun 3, 2024
7ba9858
merging v 6.0
kushti Jun 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/js/src/main/scala/sigma/js/Isos.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import scala.reflect.ClassTag
import scala.scalajs.js
import scala.scalajs.js.JSConverters.JSRichOption

/** Definitions of isomorphisms for sigma-core module.
* @see sigma.data.Iso
*/
object Isos {

implicit def isoUndefOr[A, B](implicit iso: Iso[A, B]): Iso[js.UndefOr[A], Option[B]] = new Iso[js.UndefOr[A], Option[B]] {
Expand Down
1 change: 1 addition & 0 deletions core/shared/src/main/scala/sigma/SigmaDsl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ trait Header {

def checkPow: Boolean

def bytes: Coll[Byte]
}

/** Runtime representation of Context ErgoTree type.
Expand Down
3 changes: 2 additions & 1 deletion core/shared/src/main/scala/sigma/ast/SType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,8 @@ object STypeApply {
/** Type description of optional values. Instances of `Option`
* are either constructed by `Some` or by `None` constructors. */
case class SOption[ElemType <: SType](elemType: ElemType) extends SProduct with SGenericType {
override type WrappedType = Option[ElemType#WrappedType]
type ElemWrappedType = ElemType#WrappedType
override type WrappedType = Option[ElemWrappedType]
override val typeCode: TypeCode = SOption.OptionTypeCode
override def toString = s"Option[$elemType]"
override def toTermString: String = s"Option[${elemType.toTermString}]"
Expand Down
10 changes: 8 additions & 2 deletions core/shared/src/main/scala/sigma/data/Iso.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ import sigma.{Coll, Colls}
/** Type-class of isomorphisms between types.
* Isomorphism between two types `A` and `B` essentially say that both types
* represents the same information (entity) but in a different way.
*
* Each isomorphism defined by two functions:
* - `to: A => B` - conversion from `A` to `B`
* - `from: B => A` - conversion from `B` to `A`
*
* <p>
* The information is not lost so that both are true:
* such that the information is not lost during conversion, so that both are true:
* 1) a == from(to(a))
* 2) b == to(from(b))
* <p>
* It is used to define type-full conversions:
* - different conversions between Java and Scala data types.
* - conversion between Ergo representations and generated API representations
* - conversion between internal Ergo representations and API representations
* - conversions between exported JS classes and internal Ergo representations
*/
abstract class Iso[A, B] {
def to(a: A): B
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ object ReflectionData {
},
mkMethod(clazz, "checkPow", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[Header].checkPow
},
mkMethod(clazz, "bytes", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[Header].bytes
}
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ class CoreDataSerializer {
i += 1
}

// TODO v6.0 : support Option[T] (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/659)
// TODO v6.0 : support Header
case SOption(elemType) if VersionContext.current.isV6SoftForkActivated =>
val o = v.asInstanceOf[Option[elemType.WrappedType]]
w.putOption(o){case (w, v) =>
serialize(v, elemType, w)
}

case _ =>
CheckSerializableTypeCode(tpe.typeCode)
throw new SerializerException(s"Don't know how to serialize ($v, $tpe)")
Expand Down Expand Up @@ -119,6 +123,10 @@ class CoreDataSerializer {
}.toArray[Any]
val coll = Colls.fromArray(arr)(sigma.AnyType)
Evaluation.toDslTuple(coll, tuple)
case tOption: SOption[_] if VersionContext.current.isV6SoftForkActivated =>
r.getOption[tOption.ElemWrappedType] {
deserialize(tOption.elemType, r).asInstanceOf[tOption.ElemWrappedType]
}
case t =>
CheckSerializableTypeCode(t.typeCode)
throw new SerializerException(s"Not defined DataSerializer for type $t")
Expand Down
4 changes: 1 addition & 3 deletions core/shared/src/test/scala/sigma/VersionTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ trait VersionTesting {
_ + 1) { j =>
val treeVersion = ergoTreeVers(j)
// for each tree version up to currently activated, set it up and execute block
_currErgoTreeVersion.withValue(treeVersion) {
VersionContext.withVersions(activatedVersion, treeVersion)(block)
}
_currErgoTreeVersion.withValue(treeVersion)(block)
}
}
}
Expand Down
152 changes: 152 additions & 0 deletions data/js/src/main/scala/sigma/data/js/Isos.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package sigma.data.js

import org.ergoplatform.ErgoBox._
import org.ergoplatform.{ErgoBox, ErgoBoxCandidate}
import scorex.crypto.authds.ADKey
import scorex.util.encode.Base16
import sigma.Extensions._
import sigma.ast.syntax.GroupElementConstant
import sigma.ast.{Constant, GroupElementConstant, SType}
import sigma.data.Iso.isoStringToArray
import sigma.data.{CGroupElement, Digest32Coll, Iso}
import sigma.js.GroupElement
import sigma.serialization.{ErgoTreeSerializer, ValueSerializer}
import sigma.{Coll, Colls}
import sigmastate.fleetSdkCommon.distEsmTypesCommonMod.HexString
import sigmastate.fleetSdkCommon.distEsmTypesRegistersMod.NonMandatoryRegisters
import sigmastate.fleetSdkCommon.{distEsmTypesBoxesMod => boxesMod, distEsmTypesCommonMod => commonMod, distEsmTypesRegistersMod => registersMod, distEsmTypesTokenMod => tokenMod}

import scala.scalajs.js

/** Definitions of isomorphisms for sigma-data module.
* @see sigma.data.Iso
*/
object Isos {

val isoStringToGroupElement: Iso[String, sigma.GroupElement] = new Iso[String, sigma.GroupElement] {
override def to(x: String): sigma.GroupElement = {
val bytes = Base16.decode(x).get
ValueSerializer.deserialize(bytes).asInstanceOf[GroupElementConstant].value
}
override def from(x: sigma.GroupElement): String = {
val bytes = ValueSerializer.serialize(GroupElementConstant(x))
Base16.encode(bytes)
}
}

val isoGroupElement: Iso[GroupElement, sigma.GroupElement] = new Iso[GroupElement, sigma.GroupElement] {
override def to(x: GroupElement): sigma.GroupElement = {
CGroupElement(x.point)
}
override def from(x: sigma.GroupElement): GroupElement = {
new GroupElement(x.asInstanceOf[CGroupElement].wrappedValue)
}
}

implicit val isoBoxId: Iso[boxesMod.BoxId, ErgoBox.BoxId] = new Iso[boxesMod.BoxId, ErgoBox.BoxId] {
override def to(x: boxesMod.BoxId): ErgoBox.BoxId = ADKey @@@ isoStringToArray.to(x)

override def from(x: ErgoBox.BoxId): boxesMod.BoxId = isoStringToArray.from(x)
}

implicit val isoHexStringToConstant: Iso[HexString, Constant[SType]] = new Iso[HexString, Constant[SType]] {
override def to(x: HexString): Constant[SType] = {
val bytes = isoStringToArray.to(x)
val value = ValueSerializer.deserialize(bytes)
value.asInstanceOf[Constant[SType]]
}
override def from(x: Constant[SType]): HexString = {
val bytes = ValueSerializer.serialize(x)
isoStringToArray.from(bytes)
}
}


implicit val isoAmount: Iso[commonMod.Amount, Long] = new Iso[commonMod.Amount, Long] {
override def to(x: commonMod.Amount): Long = x.asInstanceOf[Any] match {
case s: String => BigInt(s).toLong
case _ => java.lang.Long.parseLong(x.asInstanceOf[js.BigInt].toString(10))
}
override def from(x: Long): commonMod.Amount = x.toString
}

implicit val isoToken: Iso[tokenMod.TokenAmount[commonMod.Amount], Token] =
new Iso[tokenMod.TokenAmount[commonMod.Amount], Token] {
override def to(x: tokenMod.TokenAmount[commonMod.Amount]): Token =
(Digest32Coll @@@ Colls.fromArray(Base16.decode(x.tokenId).get), isoAmount.to(x.amount))

override def from(x: Token): tokenMod.TokenAmount[commonMod.Amount] =
tokenMod.TokenAmount[commonMod.Amount](isoAmount.from(x._2), x._1.toHex)
}

val isoTokenArray: Iso[js.Array[tokenMod.TokenAmount[commonMod.Amount]], Coll[Token]] =
new Iso[js.Array[tokenMod.TokenAmount[commonMod.Amount]], Coll[Token]] {
override def to(x: js.Array[tokenMod.TokenAmount[commonMod.Amount]]): Coll[Token] = {
sigma.js.Isos.isoArrayToColl(isoToken).to(x)
}
override def from(x: Coll[Token]): js.Array[tokenMod.TokenAmount[commonMod.Amount]] = {
sigma.js.Isos.isoArrayToColl(isoToken).from(x)
}
}

val isoNonMandatoryRegisters: Iso[registersMod.NonMandatoryRegisters, AdditionalRegisters] =
new Iso[registersMod.NonMandatoryRegisters, AdditionalRegisters] {
override def to(x: registersMod.NonMandatoryRegisters): AdditionalRegisters = {
val regs = Seq(
x.R4 -> R4,
x.R5 -> R5,
x.R6 -> R6,
x.R7 -> R7,
x.R8 -> R8,
x.R9 -> R9
).collect {
case (regOpt, id) if regOpt.isDefined => id -> isoHexStringToConstant.to(regOpt.get)
}
Map(regs:_*)
}
override def from(regs: AdditionalRegisters): registersMod.NonMandatoryRegisters = {
def regHexOpt(t: NonMandatoryRegisterId): Option[HexString] =
regs.get(t).map(v => isoHexStringToConstant.from(v.asInstanceOf[Constant[SType]]))

val resRegs = NonMandatoryRegisters()
regHexOpt(R4).foreach(resRegs.setR4(_))
regHexOpt(R5).foreach(resRegs.setR5(_))
regHexOpt(R6).foreach(resRegs.setR6(_))
regHexOpt(R7).foreach(resRegs.setR7(_))
regHexOpt(R8).foreach(resRegs.setR8(_))
regHexOpt(R9).foreach(resRegs.setR9(_))
resRegs
}
}

implicit val isoBoxCandidate: Iso[boxesMod.BoxCandidate[commonMod.Amount, NonMandatoryRegisters], ErgoBoxCandidate] = new Iso[boxesMod.BoxCandidate[commonMod.Amount, NonMandatoryRegisters], ErgoBoxCandidate] {
override def to(x: boxesMod.BoxCandidate[commonMod.Amount, NonMandatoryRegisters]): ErgoBoxCandidate = {
val ergoBoxCandidate = new ErgoBoxCandidate(
value = isoAmount.to(x.value),
ergoTree = {
val bytes = Base16.decode(x.ergoTree).get
ErgoTreeSerializer.DefaultSerializer.deserializeErgoTree(bytes)
},
x.creationHeight.toInt,
additionalTokens = isoTokenArray.to(x.assets),
additionalRegisters = isoNonMandatoryRegisters.to(x.additionalRegisters)
)
ergoBoxCandidate
}

override def from(x: ErgoBoxCandidate): boxesMod.BoxCandidate[commonMod.Amount, NonMandatoryRegisters] = {
val ergoTree = ErgoTreeSerializer.DefaultSerializer.serializeErgoTree(x.ergoTree)
val ergoTreeStr = Base16.encode(ergoTree)
val assets = isoTokenArray.from(x.additionalTokens)
boxesMod.BoxCandidate[commonMod.Amount, NonMandatoryRegisters](
ergoTree = ergoTreeStr,
value = isoAmount.from(x.value),
assets = assets,
creationHeight = x.creationHeight,
additionalRegisters = isoNonMandatoryRegisters.from(x.additionalRegisters)
)
}
}


}
61 changes: 61 additions & 0 deletions data/js/src/main/scala/sigma/js/Box.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package sigma.js

import org.ergoplatform.ErgoBox
import scorex.util.ModifierId
import scorex.util.encode.Base16
import sigma.data.Iso
import sigma.data.js.Isos.{isoAmount, isoNonMandatoryRegisters, isoTokenArray}
import sigma.serialization.ErgoTreeSerializer
import sigmastate.fleetSdkCommon.distEsmTypesBoxesMod.{Box => FBox}
import sigmastate.fleetSdkCommon.distEsmTypesCommonMod.Amount
import sigmastate.fleetSdkCommon.distEsmTypesRegistersMod.NonMandatoryRegisters
import sigmastate.fleetSdkCommon.{distEsmTypesCommonMod => commonMod}

import scala.scalajs.js
import scala.scalajs.js.annotation.JSExportTopLevel

/** Equivalent of [[sigma.Box]] available from JS. */
@JSExportTopLevel("Box")
class Box(val box: FBox[Amount, NonMandatoryRegisters]) extends js.Object

object Box extends js.Object {
/** Represents a box in Fleet SDK. */
type FleetBox = FBox[commonMod.Amount, NonMandatoryRegisters]

/** Converts Fleet box to ErgoBox and back. */
val isoBox: Iso[FleetBox, ErgoBox] = new Iso[FleetBox, ErgoBox] {
override def to(x: FleetBox): ErgoBox = {
val ergoBox = new ErgoBox(
value = isoAmount.to(x.value),
ergoTree = {
val bytes = Base16.decode(x.ergoTree).get
ErgoTreeSerializer.DefaultSerializer.deserializeErgoTree(bytes)
},
creationHeight = x.creationHeight.toInt,
additionalTokens = isoTokenArray.to(x.assets),
additionalRegisters = isoNonMandatoryRegisters.to(x.additionalRegisters),
transactionId = ModifierId @@ x.transactionId,
index = x.index.toShort
)
ergoBox
}

override def from(x: ErgoBox): FleetBox = {
val ergoTree = ErgoTreeSerializer.DefaultSerializer.serializeErgoTree(x.ergoTree)
val ergoTreeStr = Base16.encode(ergoTree)
val assets = isoTokenArray.from(x.additionalTokens)
FBox[commonMod.Amount, NonMandatoryRegisters](
boxId = Base16.encode(x.id),
ergoTree = ergoTreeStr,
value = isoAmount.from(x.value),
assets = assets,
creationHeight = x.creationHeight,
additionalRegisters = isoNonMandatoryRegisters.from(x.additionalRegisters),
transactionId = x.transactionId,
index = x.index
)
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import sigma.ast.SType
import sigma.crypto.Platform
import sigma.data._
import sigma.js.Value.toRuntimeData
import sigma.serialization.{CoreDataSerializer, CoreSerializer}
import sigma.serialization.{DataSerializer, SigmaSerializer}
import sigma.util.Extensions.BigIntOps
import sigma.{Coll, Colls, Evaluation}
import sigmastate.fleetSdkCommon.distEsmTypesBoxesMod.{Box => FBox}

import java.math.BigInteger
import scala.scalajs.js
Expand Down Expand Up @@ -55,9 +56,9 @@ class Value(val data: Any, val tpe: Type) extends js.Object {
def toHex(): String = {
val stype = Evaluation.rtypeToSType(tpe.rtype)
val value = runtimeData.asInstanceOf[SType#WrappedType]
val w = CoreSerializer.startWriter()
val w = SigmaSerializer.startWriter()
w.putType(stype)
CoreDataSerializer.serialize(value, stype, w)
DataSerializer.serialize(value, stype, w)
Base16.encode(w.toBytes)
}
}
Expand Down Expand Up @@ -89,6 +90,9 @@ object Value extends js.Object {
case sigma.AvlTreeRType =>
val t = data.asInstanceOf[AvlTree]
AvlTree.isoAvlTree.to(t)
case sigma.BoxRType =>
val t = data.asInstanceOf[Box]
CBox(Box.isoBox.to(t.box))
case ct: CollType[a] =>
val xs = data.asInstanceOf[js.Array[Any]]
implicit val cT = ct.tItem.classTag
Expand Down Expand Up @@ -124,6 +128,9 @@ object Value extends js.Object {
new SigmaProp(value.asInstanceOf[CSigmaProp].wrappedValue)
case sigma.AvlTreeRType =>
AvlTree.isoAvlTree.from(value.asInstanceOf[CAvlTree])
case sigma.BoxRType =>
val fleetBox = Box.isoBox.from(value.asInstanceOf[CBox].wrappedValue)
new Box(fleetBox)
case ct: CollType[a] =>
val arr = value.asInstanceOf[Coll[a]].toArray
js.Array(arr.map(x => fromRuntimeData(x, ct.tItem)):_*)
Expand Down Expand Up @@ -220,6 +227,13 @@ object Value extends js.Object {
new Value(sp, Type.SigmaProp)
}

/** Creates a Value of Box type from a [[FBox]] instance.
* @param fleetBox a Fleet box to be wrapped in a [[Value]]
*/
def ofBox(fleetBox: Box.FleetBox): Value = {
new Value(new Box(fleetBox), Type.Box)
}

/** Create Pair value from two values. */
def pairOf(l: Value, r: Value): Value = {
val data = js.Array(l.data, r.data) // the l and r data have been validated
Expand Down Expand Up @@ -251,9 +265,9 @@ object Value extends js.Object {
*/
def fromHex(hex: String): Value = {
val bytes = Base16.decode(hex).fold(t => throw t, identity)
val r = CoreSerializer.startReader(bytes)
val r = SigmaSerializer.startReader(bytes)
val stype = r.getType()
val value = CoreDataSerializer.deserialize(stype, r)
val value = DataSerializer.deserialize(stype, r)
val rtype = Evaluation.stypeToRType(stype)
val jsvalue = Value.fromRuntimeData(value, rtype)
new Value(jsvalue, new Type(rtype))
Expand Down
Loading