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

Rename commands #200

Merged
merged 1 commit into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/Neo.Compiler.MSIL/MSIL/Conv_Multi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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[])")
Expand Down
31 changes: 8 additions & 23 deletions src/Neo.SmartContract.Framework/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,48 +20,40 @@ public static class Helper
/// <summary>
/// Converts byte to byte[] considering the byte as a BigInteger (0x00 at the end)
/// </summary>
[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);

/// <summary>
/// Converts sbyte to byte[].
/// </summary>
[OpCode(OpCode.CONVERT, StackItemType_ByteArray)]
public extern static byte[] AsByteArray(this sbyte source);
public extern static byte[] ToByteArray(this sbyte source);

/// <summary>
/// Converts sbyte[] to byte[].
/// </summary>
[OpCode(OpCode.CONVERT, StackItemType_ByteArray)]
public extern static byte[] AsByteArray(this sbyte[] source);
public extern static byte[] ToByteArray(this sbyte[] source);

/// <summary>
/// Converts byte[] to sbyte[].
/// </summary>
[OpCode(OpCode.CONVERT, StackItemType_ByteArray)]
public extern static sbyte[] AsSbyteArray(this byte[] source);
public extern static sbyte[] ToSbyteArray(this byte[] source);

/// <summary>
/// Converts byte[] to BigInteger. No guarantees are assumed regarding BigInteger working range.
/// Examples: [0x0a] -> 10; [0x80] -> -128; [] -> 0; [0xff00] -> 255
/// </summary>
[OpCode(OpCode.CONVERT, StackItemType_Integer)]
public extern static BigInteger AsBigInteger(this byte[] source);



/// <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>
[OpCode(OpCode.CONVERT, StackItemType_ByteArray)]
public extern static byte[] AsByteArray(this BigInteger source);
public extern static BigInteger ToBigInteger(this byte[] source);

/// <summary>
/// Converts string to byte[]. Examples: "hello" -> [0x68656c6c6f]; "" -> []; "Neo" -> [0x4e656f]
/// </summary>
[OpCode(OpCode.CONVERT, StackItemType_ByteArray)]
public extern static byte[] AsByteArray(this string source);
public extern static byte[] ToByteArray(this string source);

/// <summary>
/// Converts byte[] to string. Examples: [0x68656c6c6f] -> "hello"; [] -> ""; [0x4e656f] -> "Neo"
Expand Down Expand Up @@ -135,13 +127,6 @@ public static class Helper
// return (byte) source;
//}

/// <summary>
/// Converts byte to byte[].
/// </summary>
[OpCode(OpCode.PUSH1)]
[OpCode(OpCode.LEFT)]
public extern static byte[] ToByteArray(this byte source);

/// <summary>
/// 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]
Expand Down
12 changes: 6 additions & 6 deletions src/Neo.SmartContract.Framework/Services/Neo/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static StorageMap CreateMap(this StorageContext context, string prefix)
return new StorageMap
{
Context = context,
Prefix = prefix.AsByteArray()
Prefix = prefix.ToByteArray()
};
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down