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

Engine: Remove optionality of contract ID Seeding. #5966

Merged
merged 5 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Address Samir's review
  • Loading branch information
remyhaemmerle-da committed May 13, 2020
commit 6be351c8c7cef0f78e9e1caf464cddf9e8ecdb8e
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ object ValueGenerators {
val absCoidV0Gen: Gen[AbsoluteContractId.V0] =
Gen.alphaStr.map(t => Value.AbsoluteContractId.V0.assertFromString('#' +: t))
private val genAbsCidV1: Gen[AbsoluteContractId.V1] =
Gen.zip(genHash, genBytes.filter(_.length <= 94)) map {
Gen.zip(genHash, genBytes.filter(_.length <= AbsoluteContractId.V1.maxSuffixLength)) map {
case (h, b) => AbsoluteContractId.V1.assertBuild(h, b)
}

Expand All @@ -170,7 +170,9 @@ object ValueGenerators {
AbsoluteContractId.V1
.assertBuild(
b1.discriminator,
b1.suffix.slice(0, b1.suffix.length min 93) ++ Bytes.fromByteArray(Array(b)))
b1.suffix
.slice(0, b1.suffix.length min (AbsoluteContractId.V1.maxSuffixLength - 1)) ++ Bytes
.fromByteArray(Array(b)))
}
),
Gen.oneOf(absCoidV0Gen, genAbsCidV1 map (cid => AbsoluteContractId.V1(cid.discriminator))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,15 @@ object Value extends CidContainer1WithDefaultCidResolver[Value] {
}

object V1 {
val maxSuffixLength = 94
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just wondering: from where does that magic number come from? If you would like to follow the Scala style guide this constant should be MaxSuffixLength.


def apply(discriminator: Hash): V1 = new V1(discriminator, Bytes.Empty)

def build(discriminator: crypto.Hash, suffix: Bytes): Either[String, V1] =
Either.cond(
suffix.length <= 94,
suffix.length <= maxSuffixLength,
new V1(discriminator, suffix),
s"the suffix is too long, expected at most 94 bytes, but got ${suffix.length}"
s"the suffix is too long, expected at most ${maxSuffixLength} bytes, but got ${suffix.length}"
)

def assertBuild(discriminator: crypto.Hash, suffix: Bytes): V1 =
Expand Down