Skip to content

Commit

Permalink
Merge pull request #841 from ScorexFoundation/develop
Browse files Browse the repository at this point in the history
Release Candidate v5.0.2
  • Loading branch information
aslesarenko authored Nov 11, 2022
2 parents 627e506 + 5fe2c7f commit b369faa
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## Building

Clone the repository and then run tests.

```shell
git clone git@github.com:ScorexFoundation/sigmastate-interpreter.git
cd sigmastate-interpreter
sbt test
```

## Releasing
To publish release version to Sonatype, do the following:
- make a tag with version number `vX.Y.Z` (used by `sbt-dynver` to set `version` in `build.sbt`);
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ libraryDependencies += "org.scorexfoundation" %% "sigma-state" % "4.0.3"
| sigma-library | Implementation of graph IR nodes for Sigma types |
| sigmastate | Implementation ErgoTree, Interpreter and cost estimation |

## Acknowledgments

We thank JetBrains for [supporting](https://www.jetbrains.com/buy/opensource/) this project since 2021 by providing All Products Pack subscription.

<img src="https://www.yourkit.com/images/yklogo.png"/>

We thank YourKit for support of open source projects with its full-featured Java Profiler.
YourKit, LLC is the creator of <a href="https://www.yourkit.com/java/profiler/">YourKit Java Profiler</a>
and <a href="https://www.yourkit.com/.net/profiler/">YourKit .NET Profiler</a>,
innovative and intelligent tools for profiling Java and .NET applications.

## References

- [Ergo Site](https://ergoplatform.org/en/)
Expand Down
21 changes: 13 additions & 8 deletions sigmastate/src/main/scala/org/ergoplatform/ErgoBoxCandidate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.ergoplatform
import java.util
import org.ergoplatform.ErgoBox._
import org.ergoplatform.settings.ErgoAlgos
import scorex.util.{bytesToId, ModifierId}
import scorex.util.{ModifierId, bytesToId}
import sigmastate.Values._
import sigmastate._
import sigmastate.SType.AnyOps
Expand All @@ -16,7 +16,7 @@ import sigmastate.serialization.ErgoTreeSerializer.DefaultSerializer
import sigmastate.util.safeNewArray
import spire.syntax.all.cfor

import scala.collection.immutable
import scala.collection.{immutable, mutable}
import scala.runtime.ScalaRunTime

/**
Expand Down Expand Up @@ -100,12 +100,17 @@ class ErgoBoxCandidate(val value: Long,
s"tokens: (${additionalTokens.map(t => ErgoAlgos.encode(t._1) + ":" + t._2).toArray.mkString(", ")}), " +
s"$additionalRegisters, creationHeight: $creationHeight)"

/** Additional tokens stored in the box. */
lazy val tokens: Map[ModifierId, Long] =
additionalTokens
.toArray
.map(t => bytesToId(t._1) -> t._2)
.toMap
/** Additional tokens stored in the box, merged into a Map.
* This method is not used in ErgoTree and serialization, not part of consensus.
*/
lazy val tokens: Map[ModifierId, Long] = {
val merged = new mutable.HashMap[ModifierId, Long]
additionalTokens.foreach { case (id, amount) =>
val mId = bytesToId(id)
merged.put(mId, java7.compat.Math.addExact(merged.getOrElse(mId, 0L), amount))
}
merged.toMap
}
}

object ErgoBoxCandidate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ object ErgoLikeTransactionSerializer extends SigmaSerializer[ErgoLikeTransaction
w.putBytes(input.boxId)
}
// Serialize distinct ids of tokens in transaction outputs.
// This optimization is crucial to allow up to MaxTokens (== 255) in a box.
// Without it total size of all token ids 255 * 32 = 8160,
// way beyond MaxBoxSize (== 4K)
val tokenIds = tx.outputCandidates.toColl
.flatMap(box => box.additionalTokens.map(t => t._1))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class ErgoLikeTransactionSpec extends SigmaDslTesting {
100,
Coll(
Digest32 @@ (ErgoAlgos.decodeUnsafe(token1)) -> 10000000L,
Digest32 @@ (ErgoAlgos.decodeUnsafe(token1)) -> 500L,
Digest32 @@ (ErgoAlgos.decodeUnsafe(token2)) -> 500L
)
)
Expand All @@ -70,6 +71,7 @@ class ErgoLikeTransactionSpec extends SigmaDslTesting {
b1.tokens shouldBe expectedTokens
b1_clone.tokens shouldBe expectedTokens
b3.tokens shouldBe expectedTokens
b2.tokens shouldBe Map[ModifierId, Long](ModifierId @@ token1 -> 10000500L, ModifierId @@ token2 -> 500L)

assertResult(true)(b1.hashCode() == b1.hashCode())
assertResult(true)(b1 == b1)
Expand Down

0 comments on commit b369faa

Please sign in to comment.