diff --git a/src/Neo.Compiler.MSIL/MSIL/Conv_Multi.cs b/src/Neo.Compiler.MSIL/MSIL/Conv_Multi.cs
index 20c57d4c2..e7aba1b0f 100644
--- a/src/Neo.Compiler.MSIL/MSIL/Conv_Multi.cs
+++ b/src/Neo.Compiler.MSIL/MSIL/Conv_Multi.cs
@@ -654,6 +654,7 @@ private int _ConvertCall(OpCode src, NeoMethod to)
}
else if (src.tokenMethod == "System.Byte[] System.Numerics.BigInteger::ToByteArray()")
{
+ _Convert1by1(VM.OpCode.CONVERT, src, to, new byte[] { 0x28 });
return 0;
}
else if (src.tokenMethod == "System.Void System.Numerics.BigInteger::.ctor(System.Byte[])")
diff --git a/src/Neo.SmartContract.Framework/Helper.cs b/src/Neo.SmartContract.Framework/Helper.cs
index e3630d53b..7d2810dec 100644
--- a/src/Neo.SmartContract.Framework/Helper.cs
+++ b/src/Neo.SmartContract.Framework/Helper.cs
@@ -20,48 +20,40 @@ public static class Helper
///
/// Converts byte to byte[] considering the byte as a BigInteger (0x00 at the end)
///
- [OpCode(OpCode.CONVERT, StackItemType_ByteArray)]
- public extern static byte[] AsByteArray(this byte source);
+ [OpCode(OpCode.PUSH1)]
+ [OpCode(OpCode.LEFT)]
+ public extern static byte[] ToByteArray(this byte source);
///
/// Converts sbyte to byte[].
///
[OpCode(OpCode.CONVERT, StackItemType_ByteArray)]
- public extern static byte[] AsByteArray(this sbyte source);
+ public extern static byte[] ToByteArray(this sbyte source);
///
/// Converts sbyte[] to byte[].
///
[OpCode(OpCode.CONVERT, StackItemType_ByteArray)]
- public extern static byte[] AsByteArray(this sbyte[] source);
+ public extern static byte[] ToByteArray(this sbyte[] source);
///
/// Converts byte[] to sbyte[].
///
[OpCode(OpCode.CONVERT, StackItemType_ByteArray)]
- public extern static sbyte[] AsSbyteArray(this byte[] source);
+ public extern static sbyte[] ToSbyteArray(this byte[] source);
///
/// Converts byte[] to BigInteger. No guarantees are assumed regarding BigInteger working range.
/// Examples: [0x0a] -> 10; [0x80] -> -128; [] -> 0; [0xff00] -> 255
///
[OpCode(OpCode.CONVERT, StackItemType_Integer)]
- public extern static BigInteger AsBigInteger(this byte[] source);
-
-
-
- ///
- /// 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]
- ///
- [OpCode(OpCode.CONVERT, StackItemType_ByteArray)]
- public extern static byte[] AsByteArray(this BigInteger source);
+ public extern static BigInteger ToBigInteger(this byte[] source);
///
/// Converts string to byte[]. Examples: "hello" -> [0x68656c6c6f]; "" -> []; "Neo" -> [0x4e656f]
///
[OpCode(OpCode.CONVERT, StackItemType_ByteArray)]
- public extern static byte[] AsByteArray(this string source);
+ public extern static byte[] ToByteArray(this string source);
///
/// Converts byte[] to string. Examples: [0x68656c6c6f] -> "hello"; [] -> ""; [0x4e656f] -> "Neo"
@@ -135,13 +127,6 @@ public static class Helper
// return (byte) source;
//}
- ///
- /// Converts byte to byte[].
- ///
- [OpCode(OpCode.PUSH1)]
- [OpCode(OpCode.LEFT)]
- public extern static byte[] ToByteArray(this byte source);
-
///
/// Converts parameter to sbyte from (big)integer range -128-255; faults if out-of-range.
/// Examples: 256 -> fault; -1 -> -1 [0xff]; 255 -> -1 [0xff]; 0 -> 0 [0x00]; 10 -> 10 [0x0a]; 127 -> 127 [0x7f]; 128 -> -128 [0x80]
diff --git a/src/Neo.SmartContract.Framework/Services/Neo/Helper.cs b/src/Neo.SmartContract.Framework/Services/Neo/Helper.cs
index 18b2a9d2b..f956e53ec 100644
--- a/src/Neo.SmartContract.Framework/Services/Neo/Helper.cs
+++ b/src/Neo.SmartContract.Framework/Services/Neo/Helper.cs
@@ -9,7 +9,7 @@ public static StorageMap CreateMap(this StorageContext context, string prefix)
return new StorageMap
{
Context = context,
- Prefix = prefix.AsByteArray()
+ Prefix = prefix.ToByteArray()
};
}
@@ -39,7 +39,7 @@ public static void Delete(this StorageMap map, byte[] key)
public static void Delete(this StorageMap map, string key)
{
- byte[] k = map.Prefix.Concat(key.AsByteArray());
+ byte[] k = map.Prefix.Concat(key.ToByteArray());
Storage.Delete(map.Context, k);
}
@@ -51,7 +51,7 @@ public static byte[] Get(this StorageMap map, byte[] key)
public static byte[] Get(this StorageMap map, string key)
{
- byte[] k = map.Prefix.Concat(key.AsByteArray());
+ byte[] k = map.Prefix.Concat(key.ToByteArray());
return Storage.Get(map.Context, k);
}
@@ -75,19 +75,19 @@ public static void Put(this StorageMap map, byte[] key, string value)
public static void Put(this StorageMap map, string key, byte[] value)
{
- byte[] k = map.Prefix.Concat(key.AsByteArray());
+ byte[] k = map.Prefix.Concat(key.ToByteArray());
Storage.Put(map.Context, k, value);
}
public static void Put(this StorageMap map, string key, BigInteger value)
{
- byte[] k = map.Prefix.Concat(key.AsByteArray());
+ byte[] k = map.Prefix.Concat(key.ToByteArray());
Storage.Put(map.Context, k, value);
}
public static void Put(this StorageMap map, string key, string value)
{
- byte[] k = map.Prefix.Concat(key.AsByteArray());
+ byte[] k = map.Prefix.Concat(key.ToByteArray());
Storage.Put(map.Context, k, value);
}
}
diff --git a/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_NULL.cs b/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_NULL.cs
index ec5cc34dd..3c4077bd0 100644
--- a/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_NULL.cs
+++ b/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_NULL.cs
@@ -54,13 +54,13 @@ public static bool IfNull(object obj)
public static object NullCollationAndCollation(string code)
{
- return Storage.Get(code)?.AsBigInteger() ?? 123;
+ return Storage.Get(code)?.ToBigInteger() ?? 123;
}
public static object NullCollationAndCollation2(string code)
{
Storage.Put(code, "111");
- return Storage.Get(code)?.AsBigInteger() ?? 123;
+ return Storage.Get(code)?.ToBigInteger() ?? 123;
}
}
}
diff --git a/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_TypeConvert.cs b/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_TypeConvert.cs
index b7ffcc35e..a40985587 100644
--- a/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_TypeConvert.cs
+++ b/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_TypeConvert.cs
@@ -11,15 +11,15 @@ class Contract_TypeConvert : SmartContract.Framework.SmartContract
public static object testType()
{
BigInteger int0 = 0;
- var bts0 = int0.AsByteArray();
+ var bts0 = int0.ToByteArray();
BigInteger int1 = 2;
- var bts1 = int1.AsByteArray();
+ var bts1 = int1.ToByteArray();
var bts2=new byte[1] { 3 };
- var int2 = bts2.AsBigInteger();
+ var int2 = bts2.ToBigInteger();
var bts3 = new byte[0];
- var int3 = bts3.AsBigInteger();
+ var int3 = bts3.ToBigInteger();
var arrobj = new object[8];
arrobj[0] = int0;