-
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.
Merge pull request #917 from ScorexFoundation/core-serializers2
Move TypeSerializer and DataSerializer to core module (part 2)
- Loading branch information
Showing
271 changed files
with
3,476 additions
and
3,089 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
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
2 changes: 1 addition & 1 deletion
2
...gmastate/crypto/SigmaJsCryptoFacade.scala → ...la/sigma/crypto/SigmaJsCryptoFacade.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package sigmastate.crypto | ||
package sigma.crypto | ||
|
||
import debox.cfor | ||
|
||
|
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), | ||
) | ||
} | ||
} | ||
|
||
} |
6 changes: 3 additions & 3 deletions
6
...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): _*) | ||
} | ||
|
||
} |
5 changes: 2 additions & 3 deletions
5
...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
Oops, something went wrong.