-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core-serializers: Value moved to core.js
- Loading branch information
1 parent
5695687
commit 4fcd2a7
Showing
24 changed files
with
197 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package sigma.js | ||
|
||
import sigma.Extensions.ArrayOps | ||
import sigma.data.Iso.{isoStringToArray, isoStringToColl} | ||
import sigma.data.{AvlTreeData, AvlTreeFlags, CAvlTree, Iso} | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.UndefOr | ||
import scala.scalajs.js.annotation.JSExportTopLevel | ||
|
||
/** Equivalent of [[sigma.AvlTree]] available from JS. */ | ||
@JSExportTopLevel("AvlTree") | ||
class AvlTree( | ||
val digest: String, | ||
val insertAllowed: Boolean, | ||
val updateAllowed: Boolean, | ||
val removeAllowed: Boolean, | ||
val keyLength: Int, | ||
val valueLengthOpt: UndefOr[Int] | ||
) extends js.Object | ||
|
||
object AvlTree { | ||
|
||
implicit val isoAvlTree: Iso[AvlTree, sigma.AvlTree] = new Iso[AvlTree, sigma.AvlTree] { | ||
override def to(x: AvlTree): sigma.AvlTree = { | ||
CAvlTree( | ||
AvlTreeData( | ||
digest = isoStringToArray.to(x.digest).toColl, | ||
treeFlags = AvlTreeFlags(x.insertAllowed, x.updateAllowed, x.removeAllowed), | ||
x.keyLength, | ||
valueLengthOpt = sigma.js.Isos.isoUndefOr(Iso.identityIso[Int]).to(x.valueLengthOpt), | ||
), | ||
) | ||
} | ||
|
||
override def from(x: sigma.AvlTree): AvlTree = { | ||
val tree = x.asInstanceOf[CAvlTree] | ||
val data = tree.treeData | ||
new AvlTree( | ||
digest = isoStringToColl.from(tree.digest), | ||
insertAllowed = data.treeFlags.insertAllowed, | ||
updateAllowed = data.treeFlags.updateAllowed, | ||
removeAllowed = data.treeFlags.removeAllowed, | ||
keyLength = data.keyLength, | ||
valueLengthOpt = sigma.js.Isos.isoUndefOr(Iso.identityIso[Int]).from(data.valueLengthOpt), | ||
) | ||
} | ||
} | ||
|
||
} |
4 changes: 2 additions & 2 deletions
4
...rg/ergoplatform/sdk/js/GroupElement.scala → ...rc/main/scala/sigma/js/GroupElement.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package sigma.js | ||
|
||
import sigma.{Coll, Colls} | ||
import sigma.data.{Iso, RType} | ||
|
||
import scala.reflect.ClassTag | ||
import scala.scalajs.js | ||
import scala.scalajs.js.JSConverters.JSRichOption | ||
|
||
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]] { | ||
override def to(x: js.UndefOr[A]): Option[B] = x.toOption.map(iso.to) | ||
override def from(x: Option[B]): js.UndefOr[A] = x.map(iso.from).orUndefined | ||
} | ||
|
||
implicit def isoArrayToColl[A, B](iso: Iso[A, B]) | ||
(implicit ctA: ClassTag[A], tB: RType[B]): Iso[js.Array[A], Coll[B]] = new Iso[js.Array[A], Coll[B]] { | ||
override def to(x: js.Array[A]): Coll[B] = Colls.fromArray(x.map(iso.to).toArray(tB.classTag)) | ||
override def from(x: Coll[B]): js.Array[A] = js.Array(x.toArray.map(iso.from): _*) | ||
} | ||
|
||
implicit def isoArrayToIndexed[A, B](iso: Iso[A, B]) | ||
(implicit cB: ClassTag[B]): Iso[js.Array[A], IndexedSeq[B]] = new Iso[js.Array[A], IndexedSeq[B]] { | ||
override def to(x: js.Array[A]): IndexedSeq[B] = x.map(iso.to).toArray(cB).toIndexedSeq | ||
override def from(x: IndexedSeq[B]): js.Array[A] = js.Array(x.map(iso.from): _*) | ||
} | ||
|
||
} |
3 changes: 2 additions & 1 deletion
3
...a/org/ergoplatform/sdk/js/SigmaProp.scala → ...s/src/main/scala/sigma/js/SigmaProp.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
sdk/js/src/main/scala/org/ergoplatform/sdk/js/AvlTree.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package org.ergoplatform.sdk.js | ||
|
||
import sigma.js.Value | ||
import sigmastate.Values | ||
|
||
import scala.scalajs.js | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.