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

Update Neo.SmartContract.Framework according to last neo3 changes #106

Merged
merged 36 commits into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4dcef17
Update syscalls for neo3
shargon Sep 11, 2019
c6c9860
Update block
shargon Sep 11, 2019
7c53c7d
Fix
shargon Sep 11, 2019
301e56f
UT for test all syscalls
shargon Sep 12, 2019
27d4966
Clean ut
shargon Sep 12, 2019
7f2f83b
Update values
shargon Sep 19, 2019
1eee64c
Merge branch 'master' into more-syscalls
shargon Sep 25, 2019
e803309
Merge branch 'master' into more-syscalls
shargon Oct 16, 2019
d999c8e
Update opcodes
shargon Oct 16, 2019
f0f70c7
More Syscalls
shargon Oct 18, 2019
4499736
All ut
shargon Oct 18, 2019
b61191e
Remove CRLF
shargon Oct 18, 2019
ff4001d
Test Account
shargon Oct 19, 2019
a260f0a
Json Test
shargon Oct 19, 2019
b27d159
Update
shargon Oct 19, 2019
e8ec727
More tests
shargon Oct 19, 2019
b52fb36
Ensure checks
shargon Oct 19, 2019
b9d0e71
Runtime done
shargon Oct 19, 2019
dee96ba
Native contracts
shargon Oct 19, 2019
05c73d8
Format
shargon Oct 19, 2019
c2b4e80
Reorder UT
shargon Oct 19, 2019
7a09c9d
Merge branch 'master' into more-syscalls
shargon Oct 20, 2019
0438b71
Native contract tests
shargon Oct 21, 2019
1338353
Remove unused class
shargon Oct 21, 2019
ee75624
Blockchain UT
shargon Oct 21, 2019
b8e67ae
Blockchain UT 100%
shargon Oct 21, 2019
40936fb
Crypto
shargon Oct 21, 2019
2373468
Clean
shargon Oct 21, 2019
b868953
ReadOnly Storages
shargon Oct 21, 2019
7f7e22a
Enumerator
shargon Oct 21, 2019
345afd2
Iterator
shargon Oct 21, 2019
1856640
Merge branch 'master' into more-syscalls
shargon Oct 21, 2019
0aa2282
Contract Unit test
shargon Oct 22, 2019
c46dce4
Format
shargon Oct 22, 2019
5642b38
Format
shargon Oct 22, 2019
7cb2633
Revert dotnet upgrade in this PR
shargon Oct 22, 2019
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
6 changes: 4 additions & 2 deletions src/Neo.Compiler.MSIL/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public static uint ToInteropMethodHash(this byte[] method)
return BitConverter.ToUInt32(sha.ComputeHash(method), 0);
}
}
public static byte[] HexString2Bytes(string str)

public static byte[] HexString2Bytes(this string str)
{
if (str.IndexOf("0x") == 0)
str = str.Substring(2);
Expand All @@ -46,6 +47,7 @@ public static byte[] HexString2Bytes(string str)
}
return outd;
}

public static byte[] OpDataToBytes(string opdata)
{
try // convert hex string to byte[]
Expand All @@ -54,7 +56,7 @@ public static byte[] OpDataToBytes(string opdata)
}
catch
{
return System.Text.Encoding.UTF8.GetBytes(opdata);
return Encoding.UTF8.GetBytes(opdata);
}
}
}
Expand Down
13 changes: 1 addition & 12 deletions src/Neo.Compiler.MSIL/MSIL/CctorSubVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@ public static object Dup(object src)
}
}

public static byte[] HexString2Bytes(string str)
{
byte[] outd = new byte[str.Length / 2];
for (var i = 0; i < str.Length / 2; i++)
{
outd[i] = byte.Parse(str.Substring(i * 2, 2), System.Globalization.NumberStyles.HexNumber);
}
return outd;
}

public static void Parse(ILMethod from, NeoModule to)
{
calcStack = new Stack<object>();
Expand Down Expand Up @@ -193,8 +183,7 @@ public static void Parse(ILMethod from, NeoModule to)
}
else if (attrname == "HexToBytes")//HexString2Bytes to bytes[]
{
if (text.IndexOf("0x") == 0) text = text.Substring(2);
var hex = HexString2Bytes(text);
var hex = text.HexString2Bytes();
calcStack.Push(hex);
}
else if (attrname == "ToBigInteger")
Expand Down
11 changes: 4 additions & 7 deletions src/Neo.Compiler.MSIL/MSIL/Conv_Multi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,10 @@ public bool IsAppCall(Mono.Cecil.MethodDefinition defs, out byte[] hash)

try
{
hash = new byte[20];
if (hashstr.Length < 40)
throw new Exception("hash too short:" + hashstr);
for (var i = 0; i < 20; i++)
{
hash[i] = byte.Parse(hashstr.Substring(i * 2, 2), System.Globalization.NumberStyles.HexNumber);
}
hash = hashstr.HexString2Bytes();
if (hash.Length != 20)
throw new Exception("Wrong hash:" + hashstr);

//string hexhash 需要反序
hash = hash.Reverse().ToArray();
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Copyright>2015-2019 The Neo Project</Copyright>
Expand All @@ -23,7 +23,7 @@

<ItemGroup>
<PackageReference Include="Mono.Cecil" Version="0.11.0" />
<PackageReference Include="Neo" Version="3.0.0-CI00190" />
<PackageReference Include="Neo" Version="3.0.0-CI00191" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions src/Neo.SmartContract.Framework/AppcallAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public AppcallAttribute(byte[] scriptHash)
public AppcallAttribute(string scriptHash)
{
if (scriptHash == null) throw new ArgumentNullException();

if (scriptHash.StartsWith("0x"))
{
scriptHash = scriptHash.Remove(0, 2);
}

if (scriptHash.Length != 40) throw new ArgumentException();
this.ScriptHash = new byte[scriptHash.Length / 2];
for (int i = 0; i < this.ScriptHash.Length; i++)
Expand Down
4 changes: 2 additions & 2 deletions src/Neo.SmartContract.Framework/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ public static byte[] Reverse(this byte[] source)
[NonemitWithConvert(ConvertMethod.ToBigInteger)]
public extern static BigInteger ToBigInteger(this string text);

[Syscall("Neo.Runtime.Serialize")]
[Syscall("System.Runtime.Serialize")]
public extern static byte[] Serialize(this object source);

[Syscall("Neo.Runtime.Deserialize")]
[Syscall("System.Runtime.Deserialize")]
public extern static object Deserialize(this byte[] source);
}
}
18 changes: 9 additions & 9 deletions src/Neo.SmartContract.Framework/Services/Neo/Block.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
namespace Neo.SmartContract.Framework.Services.Neo
{
public class Block : Header
public class Block
{
[Syscall("Neo.Block.GetTransactionCount")]
public extern int GetTransactionCount();

[Syscall("Neo.Block.GetTransactions")]
public extern Transaction[] GetTransactions();

[Syscall("Neo.Block.GetTransaction")]
public extern Transaction GetTransaction(int index);
public readonly byte[] Hash;
public readonly uint Version;
public readonly byte[] PrevHash;
public readonly byte[] MerkleRoot;
public readonly ulong Timestamp;
public readonly uint Index;
public readonly byte[] NextConsensus;
public readonly int TransactionsCount;
}
}
27 changes: 16 additions & 11 deletions src/Neo.SmartContract.Framework/Services/Neo/Blockchain.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
using System.Numerics;

namespace Neo.SmartContract.Framework.Services.Neo
{
public static class Blockchain
{
[Syscall("Neo.Blockchain.GetHeight")]
[Syscall("System.Blockchain.GetHeight")]
public static extern uint GetHeight();

[Syscall("Neo.Blockchain.GetHeader")]
public static extern Header GetHeader(uint height);

[Syscall("Neo.Blockchain.GetHeader")]
public static extern Header GetHeader(byte[] hash);

[Syscall("Neo.Blockchain.GetBlock")]
[Syscall("System.Blockchain.GetBlock")]
public static extern Block GetBlock(uint height);

[Syscall("Neo.Blockchain.GetBlock")]
[Syscall("System.Blockchain.GetBlock")]
public static extern Block GetBlock(byte[] hash);

[Syscall("Neo.Blockchain.GetTransaction")]
[Syscall("System.Blockchain.GetTransaction")]
public static extern Transaction GetTransaction(byte[] hash);

[Syscall("Neo.Blockchain.GetContract")]
[Syscall("System.Blockchain.GetTransactionFromBlock")]
public static extern Transaction GetTransactionFromBlock(byte[] blockHash, int txIndex);

[Syscall("System.Blockchain.GetTransactionFromBlock")]
public static extern Transaction GetTransactionFromBlock(uint blockIndex, int txIndex);

[Syscall("System.Blockchain.GetTransactionHeight")]
public static extern BigInteger GetTransactionHeight(byte[] hash);

[Syscall("System.Blockchain.GetContract")]
public static extern Contract GetContract(byte[] script_hash);
}
}
32 changes: 19 additions & 13 deletions src/Neo.SmartContract.Framework/Services/Neo/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@ namespace Neo.SmartContract.Framework.Services.Neo
{
public class Contract
{
public extern byte[] Script
{
[Syscall("Neo.Contract.GetScript")]
get;
}
/// <summary>
/// Script
/// </summary>
public readonly byte[] Script;

public extern bool IsPayable
{
[Syscall("Neo.Contract.IsPayable")]
get;
}
/// <summary>
/// Has storage
/// </summary>
public readonly bool HasStorage;

/// <summary>
/// Is payable
/// </summary>
public readonly bool IsPayable;

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

[Syscall("Neo.Contract.Create")]
public static extern Contract Create(byte[] script, ContractPropertyState contract_property_state);
public static extern Contract Create(byte[] script, string manifest);

[Syscall("Neo.Contract.Migrate")]
public static extern Contract Migrate(byte[] script, ContractPropertyState contract_property_state);
[Syscall("Neo.Contract.Update")]
public static extern void Update(byte[] script, string manifest);

[Syscall("System.Contract.Destroy")]
public static extern void Destroy();
Expand Down

This file was deleted.

14 changes: 14 additions & 0 deletions src/Neo.SmartContract.Framework/Services/Neo/Crypto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Neo.SmartContract.Framework.Services.Neo
{
public static class Crypto
{
[Syscall("Neo.Crypto.CheckSig")]
public extern static bool VerifySignature(byte[] pubkey, byte[] signature);

[Syscall("System.Crypto.Verify")]
shargon marked this conversation as resolved.
Show resolved Hide resolved
public extern static bool VerifySignature(byte[] message, byte[] pubkey, byte[] signature);

[Syscall("Neo.Crypto.CheckMultiSig")]
public extern static bool VerifySignatures(byte[][] pubkey, byte[][] signature);
}
}
22 changes: 22 additions & 0 deletions src/Neo.SmartContract.Framework/Services/Neo/Enumerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;

namespace Neo.SmartContract.Framework.Services.Neo
{
public class Enumerator<TValue>
{
[Syscall("Neo.Enumerator.Create")]
public static extern Enumerator<TValue> Create(IEnumerable<TValue> entry);

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

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

public extern TValue Value
{
[Syscall("Neo.Enumerator.Value")]
get;
}
}
}
47 changes: 0 additions & 47 deletions src/Neo.SmartContract.Framework/Services/Neo/Header.cs

This file was deleted.

23 changes: 23 additions & 0 deletions src/Neo.SmartContract.Framework/Services/Neo/Iterator.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
using System.Collections.Generic;

namespace Neo.SmartContract.Framework.Services.Neo
{
public class Iterator<TKey, TValue>
{
[Syscall("Neo.Iterator.Create")]
public static extern Iterator<TKey, TValue> Create(Map<TKey, TValue> entry);

[Syscall("Neo.Iterator.Create")]
public static extern Iterator<TKey, TValue> Create(IEnumerable<TValue> entry);

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

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

Expand All @@ -16,5 +27,17 @@ public class Iterator<TKey, TValue>
[Syscall("Neo.Enumerator.Value")]
get;
}

public extern Enumerator<TKey> Keys
{
[Syscall("Neo.Iterator.Keys")]
get;
}

public extern Enumerator<TValue> Values
{
[Syscall("Neo.Iterator.Values")]
get;
}
}
}
11 changes: 11 additions & 0 deletions src/Neo.SmartContract.Framework/Services/Neo/Json.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Neo.SmartContract.Framework.Services.Neo
{
public static class Json
{
[Syscall("Neo.Json.Serialize")]
public extern static string Serialize(object obj);

[Syscall("Neo.Json.Deserialize")]
public extern static object Deserialize(string json);
}
}
14 changes: 14 additions & 0 deletions src/Neo.SmartContract.Framework/Services/Neo/Native.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Neo.SmartContract.Framework.Services.Neo
{
public class Native
{
[Appcall("0x43cf98eddbe047e198a3e5d57006311442a0ca15")]
public static extern object NEO(string method, object[] arguments);

[Appcall("0xa1760976db5fcdfab2a9930e8f6ce875b2d18225")]
public static extern object GAS(string method, object[] arguments);

[Appcall("0x9c5699b260bd468e2160dd5d45dfd2686bba8b77")]
public static extern object Policy(string method, object[] arguments);
}
}
8 changes: 7 additions & 1 deletion src/Neo.SmartContract.Framework/Services/Neo/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ public static class Runtime
get;
}

public static extern uint Time
public static extern string Platform
{
[Syscall("System.Runtime.Platform")]
get;
}

public static extern ulong Time
{
[Syscall("System.Runtime.GetTime")]
get;
Expand Down
Loading