-
Notifications
You must be signed in to change notification settings - Fork 102
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
Add Type Convert #196
Add Type Convert #196
Conversation
|
||
|
||
[OpCode(SmartContract.Framework.OpCode.CONVERT, "0x21")] | ||
public extern static BigInteger ConvertToInteger(byte[] from); |
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.
Could we still use the AsByteArray
as the function name?
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.
Maybe we should move these to SmartContract.Framework
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.
if we do not care about old contract code,we can direct change AsByteArray.
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.
Just ignore the old contract, as the previous version could not invoke contract successful. 😂
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.
ok,let us add more convert code in framework and compiler
因爲現在會返回integer類型了,不再是DataArray 2.修改了TypeConvert 應該現在 new byte[0] 直接是ByteArray類型了
…ect/neo-devpack-dotnet into Branch_lights_utconvert
I had do some fix now const value will got right type without convert. |
2.Use Helper.AsBigInteger() to convert to BigInteger 3.fix unittest
Helper.AsByteArray() fixed. |
I'll review it today. |
|
||
/// <summary> | ||
/// Converts BigInteger to byte[]. No guarantees are assumed regarding BigInteger working range. | ||
/// Examples: 10 -> [0x0a]; 10 -> [0x0a00]; -128 -> [0x80]; -128 -> [0x80ff]; 0 -> []; 0 -> [0x00]; 255 -> [0xff00] | ||
/// </summary> | ||
[Script] | ||
[OpCode(OpCode.CONVERT, StackItemType_ByteArray)] | ||
public extern static byte[] AsByteArray(this BigInteger source); |
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.
Maybe we need to update the comments later.
var int3 = bts3.AsBigInteger(); | ||
|
||
var arrobj = new object[8]; | ||
arrobj[0] = int0; |
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.
I think we should add a test case for _ConvertPushBoolean
.
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.
That's hard,in IL sometimes bool is int too.
/// <summary> | ||
/// Converts byte to byte[] considering the byte as a BigInteger (0x00 at the end) | ||
/// </summary> | ||
[Script] | ||
[OpCode(OpCode.CONVERT, StackItemType_ByteArray)] | ||
public extern static byte[] AsByteArray(this byte source); |
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.
If we use CONVERT
, we should rename the methods from As***
to To***
. Because "As" implies the meaning of not performing the actual type conversion.
#196 because Insert a Opcode Convert but newarr still get last opcode for a PushNumber 2.add some unittest for it.
#196 because Insert a Opcode Convert but newarr still get last opcode for a PushNumber 2.add some unittest for it.
fixed #195