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

Sync neo-core #414

Merged
merged 47 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
0bc7234
update
Tommo-L Dec 24, 2020
663c607
reset
Tommo-L Dec 24, 2020
2f64647
CI01123
Tommo-L Dec 24, 2020
2a01c48
optimize
Tommo-L Dec 24, 2020
17d56c6
add ut
Tommo-L Dec 24, 2020
a501a06
Remove callback api
Tommo-L Dec 25, 2020
3917efa
Merge branch 'master' into sync_neo
Tommo-L Dec 28, 2020
65c2d37
Add more methods
shargon Jan 5, 2021
c29df40
Change to enum
shargon Jan 5, 2021
3ea7aa5
Merge branch 'master' into sync_neo
erikzhang Jan 6, 2021
12c45fc
sync to neo
Jan 7, 2021
953e023
Merge branch 'sync_neo' of https://github.com/Tommo-L/neo-devpack-dot…
Jan 7, 2021
163c893
fix
Jan 7, 2021
d73ee04
Fix compilation
shargon Jan 7, 2021
a3fb53d
Fix some UT
shargon Jan 7, 2021
16ec4b1
sync to neo
Jan 8, 2021
d232ab1
fix
Jan 8, 2021
2af846b
fix
Jan 8, 2021
35a58b5
Fix dynamic call
erikzhang Jan 10, 2021
1e49b04
Fix hashes and update nuget
shargon Jan 10, 2021
9adf4aa
Some fixes
shargon Jan 10, 2021
e05465a
More fixes
shargon Jan 10, 2021
61581b7
Fix Iterator
erikzhang Jan 10, 2021
d45fb3c
More Fixes
shargon Jan 10, 2021
bb38513
Fix deploy id
shargon Jan 10, 2021
4d39bec
Merge remote-tracking branch 'Tommo-L/sync_neo' into sync_neo
shargon Jan 10, 2021
4ceb1dc
Fix types
erikzhang Jan 10, 2021
9138e5f
Fix some UT
shargon Jan 11, 2021
784813b
Add ToBigInteger from ByteString
shargon Jan 11, 2021
7aae619
Fix InvocationCounter test
shargon Jan 11, 2021
ee341ad
More ut fixes
shargon Jan 11, 2021
395a835
Fix Iterator UT
shargon Jan 11, 2021
8febdf5
Fix Contract.Call UT
shargon Jan 11, 2021
72a253c
Fix UTs
shargon Jan 11, 2021
04919dd
Test Func
shargon Jan 11, 2021
c08f2cd
rename ToBigInteger to Parse
Tommo-L Jan 12, 2021
7b9a64f
add contract dynamic call
Tommo-L Jan 12, 2021
f04fc80
Fix UT
shargon Jan 12, 2021
1745ec3
Replace ToBigInteger to cast
shargon Jan 12, 2021
08f85b5
Replace ToBigInteger by BigInteger.Parse
shargon Jan 12, 2021
44e52f4
check type
shargon Jan 12, 2021
2138a96
Restore comment
shargon Jan 12, 2021
52eb0d2
Use last nuget
shargon Jan 12, 2021
a408bad
Add Parse overloads
shargon Jan 12, 2021
0963d10
Fix 1 arg call
shargon Jan 12, 2021
e110b33
Add Atoi
shargon Jan 12, 2021
aea745d
Test void return
shargon Jan 13, 2021
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
21 changes: 16 additions & 5 deletions src/Neo.Compiler.MSIL/MSIL/Conv_Multi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ private int ConvertCall(OpCode src, NeoMethod to)
}
return 0;
}
else if (calltype == 4)
else if (calltype == 4) // is sdk contract call
{
if (defs.IsGetter
&& defs.CustomAttributes.Any(a => a.AttributeType.FullName == "Neo.SmartContract.Framework.ContractHashAttribute"))
Expand All @@ -888,9 +888,17 @@ private int ConvertCall(OpCode src, NeoMethod to)
}
else
{
// Package the arguments into an array.
// Push pcount
ConvertPushNumber(pcount, null, to);
Convert1by1(VM.OpCode.PACK, null, to);

// Push hasReturnValue
if (defs.ReturnType.FullName is "System.Void")
ConvertPushBoolean(false, null, to);
else
ConvertPushBoolean(true, null, to);

// Push CallFlag.All to the tail of stack
ConvertPushNumber((int)CallFlags.All, null, to);

// Push call method name, the first letter should be lowercase.
ConvertPushString(GetMethodName(defs.Body.Method), src, to);
Expand All @@ -900,8 +908,8 @@ private int ConvertCall(OpCode src, NeoMethod to)
Insert1(VM.OpCode.SYSCALL, "", to, BitConverter.GetBytes(ApplicationEngine.System_Contract_Call));

// If the return type is void, insert a DROP.
if (defs.ReturnType.FullName is "System.Void")
Insert1(VM.OpCode.DROP, "", to);
//if (defs.ReturnType.FullName is "System.Void")
//Insert1(VM.OpCode.DROP, "", to);
}
}
else if (calltype == 5)
Expand All @@ -925,6 +933,9 @@ private int ConvertCall(OpCode src, NeoMethod to)
{
ConvertPushNumber(callpcount, src, to);
Convert1by1(VM.OpCode.ROLL, null, to);
Convert1by1(VM.OpCode.REVERSE3, null, to);
shargon marked this conversation as resolved.
Show resolved Hide resolved
ConvertPushNumber((int)CallFlags.All, null, to); // add CallFlag
Convert1by1(VM.OpCode.REVERSE4, null, to);
Convert1by1(VM.OpCode.SYSCALL, null, to, BitConverter.GetBytes(ApplicationEngine.System_Contract_Call));
}
else if (calltype == 3)
Expand Down
2 changes: 1 addition & 1 deletion src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.4.0" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="3.4.0" />
<PackageReference Include="Mono.Cecil" Version="0.11.2" />
<PackageReference Include="Neo" Version="3.0.0-CI01119" />
<PackageReference Include="Neo" Version="3.0.0-CI01124" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 6 additions & 2 deletions src/Neo.SmartContract.Framework/OpCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,17 @@ public enum OpCode : byte
/// </summary>
CALLA = 0x36,
/// <summary>
/// Calls the function which is described by the token.
/// </summary>
CALLT = 0x37,
/// <summary>
/// It turns the vm state to FAULT immediately, and cannot be caught.
/// </summary>
ABORT = 0x37,
ABORT = 0x38,
/// <summary>
/// Pop the top value of the stack, if it false, then exit vm execution and set vm state to FAULT.
/// </summary>
ASSERT = 0x38,
ASSERT = 0x39,
/// <summary>
/// Pop the top value of the stack, and throw it.
/// </summary>
Expand Down
12 changes: 7 additions & 5 deletions src/Neo.SmartContract.Framework/Services/Neo/CallFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ public enum CallFlags : byte
{
None = 0,

AllowModifyStates = 0b00000001,
AllowCall = 0b00000010,
AllowNotify = 0b00000100,
ReadStates = 0b00000001,
WriteStates = 0b00000010,
AllowCall = 0b00000100,
AllowNotify = 0b00001000,

ReadOnly = AllowCall | AllowNotify,
All = AllowModifyStates | AllowCall | AllowNotify
States = ReadStates | WriteStates,
ReadOnly = ReadStates | AllowCall,
All = States | AllowCall | AllowNotify
}
}
5 changes: 1 addition & 4 deletions src/Neo.SmartContract.Framework/Services/Neo/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ public class Contract
/// </summary>
public readonly string Manifest;

[Syscall("System.Contract.Call")]
public static extern object Call(UInt160 scriptHash, string method, object[] arguments);

[Syscall("System.Contract.CallEx")]
public static extern object CallEx(UInt160 scriptHash, string method, object[] arguments, CallFlags flag);
public static extern object Call(UInt160 scriptHash, string method, object[] arguments, CallFlags flag = CallFlags.All);
erikzhang marked this conversation as resolved.
Show resolved Hide resolved

[Syscall("System.Contract.GetCallFlags")]
public static extern byte GetCallFlags();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Neo.SmartContract.Framework.Services.Neo
{
[Contract("0x081514120c7894779309255b7fb18b376cec731a")]
[Contract("0xc530c494119164a1374a755aa54b1016749dc339")]
public class ContractManagement
{
public static extern UInt160 Hash { [ContractHash] get; }
Expand Down
3 changes: 0 additions & 3 deletions src/Neo.SmartContract.Framework/Services/Neo/Enumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ public class Enumerator<TValue> : IApiInterface
[Syscall("System.Enumerator.Create")]
public static extern Enumerator<TValue> Create(IEnumerable<TValue> entry);

[Syscall("System.Enumerator.Concat")]
public extern Enumerator<TValue> Concat(Enumerator<TValue> value);

[Syscall("System.Enumerator.Next")]
public extern bool Next();

Expand Down
17 changes: 17 additions & 0 deletions src/Neo.SmartContract.Framework/Services/Neo/FindOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

namespace Neo.SmartContract.Framework.Services.Neo
{
[Flags]
public enum FindOptions : byte
{
None = 0,

KeysOnly = 1 << 0,
RemovePrefix = 1 << 1,
ValuesOnly = 1 << 2,
DeserializeValues = 1 << 3,
PickField0 = 1 << 4,
PickField1 = 1 << 5
}
}
2 changes: 1 addition & 1 deletion src/Neo.SmartContract.Framework/Services/Neo/GAS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Neo.SmartContract.Framework.Services.Neo
{
[Contract("0xa6a6c15dcdc9b997dac448b6926522d22efeedfb")]
[Contract("0x149a7f61eb3b4763b9655836ec7e75ddafdd1717")]
public class GAS
{
public static extern UInt160 Hash { [ContractHash] get; }
Expand Down
3 changes: 0 additions & 3 deletions src/Neo.SmartContract.Framework/Services/Neo/Iterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ public class Iterator<TKey, TValue> : IApiInterface
[Syscall("System.Iterator.Create")]
public static extern Iterator<TKey, TValue> Create(IEnumerable<TValue> entry);

[Syscall("System.Iterator.Concat")]
public extern Iterator<TKey, TValue> Concat(Iterator<TKey, TValue> value);

[Syscall("System.Enumerator.Next")]
public extern bool Next();

Expand Down
2 changes: 1 addition & 1 deletion src/Neo.SmartContract.Framework/Services/Neo/NEO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Neo.SmartContract.Framework.Services.Neo
{
[Contract("0x0a46e2e37c9987f570b4af253fb77e7eef0f72b6")]
[Contract("0x0e1b9bfaa44e60311f6f3c96cfcd6d12c2fc3add")]
public class NEO
{
public static extern UInt160 Hash { [ContractHash] get; }
Expand Down
2 changes: 1 addition & 1 deletion src/Neo.SmartContract.Framework/Services/Neo/Oracle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Neo.SmartContract.Framework.Services.Neo
{
[Contract("0xb1c37d5847c2ae36bdde31d0cc833a7ad9667f8f")]
[Contract("0xfe723d2bf2e9eace4a21ac7a93d9598710cb0e68")]
public class Oracle
{
public static extern UInt160 Hash { [ContractHash] get; }
Expand Down
17 changes: 17 additions & 0 deletions src/Neo.SmartContract.Framework/Services/Neo/OracleResponseCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Neo.SmartContract.Framework.Services.Neo
{
public enum OracleResponseCode : byte
{
Success = 0x00,

ProtocolNotSupported = 0x10,
ConsensusUnreachable = 0x12,
NotFound = 0x14,
Timeout = 0x16,
Forbidden = 0x18,
ResponseTooLarge = 0x1a,
InsufficientFunds = 0x1c,

Error = 0xff
}
}
2 changes: 1 addition & 1 deletion src/Neo.SmartContract.Framework/Services/Neo/Policy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Neo.SmartContract.Framework.Services.Neo
{
[Contract("0xdde31084c0fdbebc7f5ed5f53a38905305ccee14")]
[Contract("0x6916fc60a2007a76f02abaee6c7bbd12af548453")]
public class Policy
{
public static extern UInt160 Hash { [ContractHash] get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Neo.SmartContract.Framework.Services.Neo
{
[Contract("0x136ec44854ad9a714901eb7d714714f1791203f2")]
[Contract("0x35fa4a901392076619a3269626b6580c0b2afdf9")]
public class RoleManagement
{
public static extern UInt160 Hash { [ContractHash] get; }
Expand Down
26 changes: 26 additions & 0 deletions src/Neo.SmartContract.Framework/Services/Neo/Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,31 @@ public static extern StorageContext CurrentReadOnlyContext
[Syscall("System.Storage.GetContext")]
[Syscall("System.Storage.Find")]
public static extern Iterator<string, byte[]> Find(string prefix);

/// <summary>
/// Returns a key string enumerator for a byte[] prefix on current Storage context
/// </summary>
[Syscall("System.Storage.GetContext")]
[Syscall("System.Storage.FindKeys")]
public static extern Enumerator<byte[]> FindKeys(byte[] prefix, FindOptions options);
shargon marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Returns a key string enumerator for a string prefix on current Storage context
/// </summary>
[Syscall("System.Storage.GetContext")]
[Syscall("System.Storage.FindKeys")]
public static extern Enumerator<string> FindKeys(string prefix, FindOptions options);

/// <summary>
/// Returns a key string enumerator for a byte[] prefix on current Storage context
/// </summary>
[Syscall("System.Storage.FindKeys")]
public static extern Enumerator<byte[]> FindKeys(StorageContext context, byte[] prefix, FindOptions options);

/// <summary>
/// Returns a key string enumerator for a string prefix on current Storage context
/// </summary>
[Syscall("System.Storage.FindKeys")]
public static extern Enumerator<string> FindKeys(StorageContext context, string prefix, FindOptions options);
}
}
103 changes: 0 additions & 103 deletions src/Neo.SmartContract.Framework/Services/System/Callback.cs

This file was deleted.

12 changes: 6 additions & 6 deletions tests/Neo.Compiler.MSIL.UnitTests/UnitTest_NativeContracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public void Test_Init()
public void TestHashes()
{
// var attr = typeof(Oracle).GetCustomAttribute<ContractAttribute>();
Assert.AreEqual(NativeContract.ContractManagement.Hash.ToString(), "0x081514120c7894779309255b7fb18b376cec731a");
Assert.AreEqual(NativeContract.RoleManagement.Hash.ToString(), "0x136ec44854ad9a714901eb7d714714f1791203f2");
Assert.AreEqual(NativeContract.Oracle.Hash.ToString(), "0xb1c37d5847c2ae36bdde31d0cc833a7ad9667f8f");
Assert.AreEqual(NativeContract.NEO.Hash.ToString(), "0x0a46e2e37c9987f570b4af253fb77e7eef0f72b6");
Assert.AreEqual(NativeContract.GAS.Hash.ToString(), "0xa6a6c15dcdc9b997dac448b6926522d22efeedfb");
Assert.AreEqual(NativeContract.Policy.Hash.ToString(), "0xdde31084c0fdbebc7f5ed5f53a38905305ccee14");
Assert.AreEqual(NativeContract.ContractManagement.Hash.ToString(), "0xc530c494119164a1374a755aa54b1016749dc339");
Assert.AreEqual(NativeContract.RoleManagement.Hash.ToString(), "0x35fa4a901392076619a3269626b6580c0b2afdf9");
Assert.AreEqual(NativeContract.Oracle.Hash.ToString(), "0xfe723d2bf2e9eace4a21ac7a93d9598710cb0e68");
Assert.AreEqual(NativeContract.NEO.Hash.ToString(), "0x0e1b9bfaa44e60311f6f3c96cfcd6d12c2fc3add");
Assert.AreEqual(NativeContract.GAS.Hash.ToString(), "0x149a7f61eb3b4763b9655836ec7e75ddafdd1717");
Assert.AreEqual(NativeContract.Policy.Hash.ToString(), "0x6916fc60a2007a76f02abaee6c7bbd12af548453");
}

[TestMethod]
Expand Down
Loading