-
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
AsByteArray() isn't able to convert BigInteger to ByteArray #195
Comments
Currently, the neo-devpack-dotnet/src/Neo.SmartContract.Framework/Helper.cs Lines 50 to 55 in adf9425
I think there are two options: |
we have the CONVERT opcode, we can use it |
'CONVERT', that's new for me.sounds it fit this issue. I will working on it. |
I had create a unittest, it worked. class Contract_TypeConvert : SmartContract.Framework.SmartContract
{
//Integer = 0x21,
//ByteArray = 0x28,
[OpCode(SmartContract.Framework.OpCode.CONVERT, "0x28")]
public extern static byte[] ConvertToByteArray(object from);
[OpCode(SmartContract.Framework.OpCode.CONVERT, "0x21")]
public extern static BigInteger ConvertToInteger(byte[] from);
public static object testType()
{
BigInteger int0 = 0;
var bts0 = ConvertToByteArray(int0);
BigInteger int1 = 2;
var bts1 = ConvertToByteArray(int1);
var bts2=new byte[1] { 3 };
var int2 = ConvertToInteger(bts2);
var bts3 = ConvertToByteArray(new byte[0]) ;
var int3 = ConvertToInteger(bts3);
var arrobj = new object[8];
arrobj[0] = int0;
arrobj[1] = bts0;
arrobj[2] = int1;
arrobj[3] = bts1;
arrobj[4] = bts2;
arrobj[5] = int2;
arrobj[6] = bts3;
arrobj[7] = int3;
return arrobj;
}
} |
* this unittest for #195 * Clean code * 區分push pushNumber pushBoolean pushDataArray 過去合約中所有的數值是統一的Push 小於等於16的數字 和 byte[0] 和 true false 是Integer >16的數字 和 byte[n>0] 是 ByteArray 現在在合約中使用數值將直接得到正確的類型 new byte[0] 是ByteArray true 是Boolean 17 是Integer * 1.修改了unittest null 因爲現在會返回integer類型了,不再是DataArray 2.修改了TypeConvert 應該現在 new byte[0] 直接是ByteArray類型了 * 1.Use Helper.AsByteArray() to convert to ByteArray 2.Use Helper.AsBigInteger() to convert to BigInteger 3.fix unittest * fix one small fault. * add value equal test * Clean code * Clean code * fix format Co-authored-by: Shargon <shargon@gmail.com>
When I test nep5 sc, I'd like to put 0 into account storage when balanceOf return null, so I write as below:
Then I found this
byteZero
is not a byteArray but still return BigInteger 0 which cause RPC getBalance return 0 if one of addresses in a wallet doesn't have balance.Then I tried another style, it works well. This means
AsByteArray()
here isn't work normally.Then I found
AsByteArray()
isn't able to conver BigInteger to ByteArray but just transfer it to VM. This makes me a little confused. Since native C# conversion methodToByteArray()
isn't able to be used in sc.framework, we don't have a method supportBigInteger
toByteArray
on sc framework.@erikzhang @lightszero @shargon
The text was updated successfully, but these errors were encountered: