-
Notifications
You must be signed in to change notification settings - Fork 41
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] Global.fromBigEndianBytes implementation #1013
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but please see comments.
if (bytes.length > SBigInt.MaxSizeInBytes) { | ||
throw SerializerException(s"BigInt value doesn't not fit into ${SBigInt.MaxSizeInBytes} bytes in fromBigEndianBytes") | ||
} | ||
CBigInt(new BigInteger(bytes.toArray)).asInstanceOf[T] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also satisfy the bit size for BigInt values, to catch the potential problem early.
See multiplication operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done ,
CBigInt(new BigInteger(bytes.toArray).to256BitValueExact).asInstanceOf[T]
now
@@ -516,7 +516,7 @@ class ErgoTreeSpecification extends SigmaDslTesting with ContractsTestkit with C | |||
(SGlobal.typeId, Seq( | |||
MInfo(1, groupGeneratorMethod), MInfo(2, xorMethod) | |||
) ++ (if (isV6Activated) { | |||
Seq(MInfo(3, serializeMethod)) // methods added in v6.0 | |||
Seq(MInfo(3, serializeMethod), MInfo(5, fromBigEndianBytesMethod)) // methods added in v6.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worth making a note about id = 4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
A new Global.fromBigEndianBytes[TNum] method is implemented in this PR, which can parse big-endian two's complement binary representation of TNum type.
example:
close #993