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

a #18

Merged
merged 5 commits into from
Dec 10, 2020
Merged

a #18

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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ You can also use `RocksDBStore` in the NEO system by modifying the default stora
### RpcServer
Plugin for hosting a RpcServer on the neo-node, being able to disable specific calls.

### RpcNep5Tracker
Plugin that enables NEP5 tracking using LevelDB.
### RpcNep17Tracker
Plugin that enables NEP17 tracking using LevelDB.
This module works in conjunction with RpcServer, otherwise, just local storage (on leveldb) would be created.

## C# SDK

### RpcClient
The RpcClient Project is an individual SDK that is used to interact with NEO blockchain through NEO RPC methods for development using. The main functions include RPC calling, Transaction making, Contract deployment & calling, and Asset transfering.
It needs a NEO node with the `RpcServer` plugin as a provider. And the provider needs more plugins like `RpcNep5Tracker` and `ApplicationLogs` if you want to call RPC methods supplied by the plugins.
It needs a NEO node with the `RpcServer` plugin as a provider. And the provider needs more plugins like `RpcNep17Tracker` and `ApplicationLogs` if you want to call RPC methods supplied by the plugins.
18 changes: 16 additions & 2 deletions neo-modules.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28729.10
MinimumVisualStudioVersion = 10.0.40219.1
Expand All @@ -10,7 +10,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationLogs", "src\Appl
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StatesDumper", "src\StatesDumper\StatesDumper.csproj", "{86531DB1-A231-46C4-823F-BE60972F7523}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RpcNep5Tracker", "src\RpcNep5Tracker\RpcNep5Tracker.csproj", "{BBE8AC15-12DF-4AF0-ABC1-F1557EB5DC8E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RpcNep17Tracker", "src\RpcNep17Tracker\RpcNep17Tracker.csproj", "{BBE8AC15-12DF-4AF0-ABC1-F1557EB5DC8E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LevelDBStore", "src\LevelDBStore\LevelDBStore.csproj", "{C66214CD-0B97-4EA5-B7A2-164F54346F19}"
EndProject
Expand All @@ -24,6 +24,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Network.RPC.Tests", "te
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Plugins.Storage.Tests", "tests\Neo.Plugins.Storage.Tests\Neo.Plugins.Storage.Tests.csproj", "{9E7EA895-302A-4C0C-BA9B-54F9A67AD75C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StateService", "src\StateService\StateService.csproj", "{A0F4A66F-6F87-4B99-B8BE-A779BC002F47}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo.Plugins.StateService.Tests", "tests\Neo.Plugins.StateService.Tests\Neo.Plugins.StateService.Tests.csproj", "{149822EC-4E0C-425F-A032-4196B615BFEB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -66,6 +70,14 @@ Global
{9E7EA895-302A-4C0C-BA9B-54F9A67AD75C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9E7EA895-302A-4C0C-BA9B-54F9A67AD75C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9E7EA895-302A-4C0C-BA9B-54F9A67AD75C}.Release|Any CPU.Build.0 = Release|Any CPU
{A0F4A66F-6F87-4B99-B8BE-A779BC002F47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A0F4A66F-6F87-4B99-B8BE-A779BC002F47}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A0F4A66F-6F87-4B99-B8BE-A779BC002F47}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A0F4A66F-6F87-4B99-B8BE-A779BC002F47}.Release|Any CPU.Build.0 = Release|Any CPU
{149822EC-4E0C-425F-A032-4196B615BFEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{149822EC-4E0C-425F-A032-4196B615BFEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{149822EC-4E0C-425F-A032-4196B615BFEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{149822EC-4E0C-425F-A032-4196B615BFEB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -80,6 +92,8 @@ Global
{1403FFE9-4265-4269-8E3D-5A79EFD108CA} = {97E81C78-1637-481F-9485-DA1225E94C23}
{D52460B3-AB5C-4D07-B400-9E7ADCB01FF5} = {59D802AB-C552-422A-B9C3-64D329FBCDCC}
{9E7EA895-302A-4C0C-BA9B-54F9A67AD75C} = {59D802AB-C552-422A-B9C3-64D329FBCDCC}
{A0F4A66F-6F87-4B99-B8BE-A779BC002F47} = {97E81C78-1637-481F-9485-DA1225E94C23}
{149822EC-4E0C-425F-A032-4196B615BFEB} = {59D802AB-C552-422A-B9C3-64D329FBCDCC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {61D3ADE6-BBFC-402D-AB42-1C71C9F9EDE3}
Expand Down
13 changes: 7 additions & 6 deletions src/ApplicationLogs/LogReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Neo.Ledger;
using Neo.Persistence;
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.VM;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -40,7 +41,7 @@ public JObject GetApplicationLog(JArray _params)
if (value is null)
throw new RpcException(-100, "Unknown transaction/blockhash");

var raw = JObject.Parse(Utility.StrictUTF8.GetString(value));
var raw = JObject.Parse(Neo.Utility.StrictUTF8.GetString(value));
//Additional optional "trigger" parameter to getapplicationlog for clients to be able to get just one execution result for a block.
if (_params.Count >= 2 && Enum.TryParse(_params[1].AsString(), true, out TriggerType trigger))
{
Expand All @@ -66,7 +67,7 @@ public static JObject TxLogToJson(Blockchain.ApplicationExecuted appExec)
trigger["trigger"] = appExec.Trigger;
trigger["vmstate"] = appExec.VMState;
trigger["exception"] = GetExceptionMessage(appExec.Exception);
trigger["gasconsumed"] = appExec.GasConsumed.ToString();
trigger["gasconsumed"] = new BigDecimal(appExec.GasConsumed, NativeContract.GAS.Decimals).ToString();
try
{
trigger["stack"] = appExec.Stack.Select(q => q.ToJson()).ToArray();
Expand Down Expand Up @@ -109,7 +110,7 @@ public static JObject BlockLogToJson(StoreView snapshot, IReadOnlyList<Blockchai
JObject trigger = new JObject();
trigger["trigger"] = appExec.Trigger;
trigger["vmstate"] = appExec.VMState;
trigger["gasconsumed"] = appExec.GasConsumed.ToString();
trigger["gasconsumed"] = new BigDecimal(appExec.GasConsumed, NativeContract.GAS.Decimals).ToString();
try
{
trigger["stack"] = appExec.Stack.Select(q => q.ToJson()).ToArray();
Expand Down Expand Up @@ -150,14 +151,14 @@ public void OnPersist(StoreView snapshot, IReadOnlyList<Blockchain.ApplicationEx
foreach (var appExec in applicationExecutedList.Where(p => p.Transaction != null))
{
var txJson = TxLogToJson(appExec);
writeBatch.Put(appExec.Transaction.Hash.ToArray(), Utility.StrictUTF8.GetBytes(txJson.ToString()));
writeBatch.Put(appExec.Transaction.Hash.ToArray(), Neo.Utility.StrictUTF8.GetBytes(txJson.ToString()));
}

//processing log for block
var blockJson = BlockLogToJson(snapshot, applicationExecutedList);
if (blockJson != null)
{
writeBatch.Put(snapshot.PersistingBlock.Hash.ToArray(), Utility.StrictUTF8.GetBytes(blockJson.ToString()));
writeBatch.Put(snapshot.PersistingBlock.Hash.ToArray(), Neo.Utility.StrictUTF8.GetBytes(blockJson.ToString()));
}
db.Write(WriteOptions.Default, writeBatch);
}
Expand All @@ -173,7 +174,7 @@ public bool ShouldThrowExceptionFromCommit(Exception ex)

static string GetExceptionMessage(Exception exception)
{
if (exception == null) return "Engine faulted.";
if (exception == null) return null;

if (exception.InnerException != null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-CI01066" />
<PackageReference Include="Neo" Version="3.0.0-CI01091" />
</ItemGroup>

</Project>
6 changes: 4 additions & 2 deletions src/RpcClient/Models/RpcApplicationLog.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Neo.IO.Json;
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.VM;
using Neo.VM.Types;
using System;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -54,7 +56,7 @@ public JObject ToJson()
JObject json = new JObject();
json["trigger"] = Trigger;
json["vmstate"] = VMState;
json["gasconsumed"] = GasConsumed.ToString();
json["gasconsumed"] = new BigDecimal(GasConsumed, NativeContract.GAS.Decimals).ToString();
json["stack"] = Stack.Select(q => q.ToJson()).ToArray();
json["notifications"] = Notifications.Select(q => q.ToJson()).ToArray();
return json;
Expand All @@ -66,7 +68,7 @@ public static Execution FromJson(JObject json)
{
Trigger = json["trigger"].TryGetEnum<TriggerType>(),
VMState = json["vmstate"].TryGetEnum<VMState>(),
GasConsumed = long.Parse(json["gasconsumed"].AsString()),
GasConsumed = (long)BigDecimal.Parse(json["gasconsumed"].AsString(), NativeContract.GAS.Decimals).Value,
Stack = ((JArray)json["stack"]).Select(p => Utility.StackItemFromJson(p)).ToList(),
Notifications = ((JArray)json["notifications"]).Select(p => RpcNotifyEventArgs.FromJson(p)).ToList()
};
Expand Down
2 changes: 1 addition & 1 deletion src/RpcClient/Models/RpcBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class RpcBlock

public JObject ToJson()
{
JObject json = Block.ToJson();
JObject json = Utility.BlockToJson(Block);
json["confirmations"] = Confirmations;
json["nextblockhash"] = NextBlockHash?.ToString();
return json;
Expand Down
2 changes: 2 additions & 0 deletions src/RpcClient/Models/RpcContractState.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Neo;
using Neo.IO.Json;
using Neo.Ledger;
using Neo.SmartContract.Manifest;
Expand All @@ -19,6 +20,7 @@ public static RpcContractState FromJson(JObject json)
ContractState = new ContractState
{
Id = (int)json["id"].AsNumber(),
Hash = UInt160.Parse(json["hash"].AsString()),
Script = Convert.FromBase64String(json["script"].AsString()),
Manifest = ContractManifest.FromJson(json["manifest"])
}
Expand Down
4 changes: 3 additions & 1 deletion src/RpcClient/Models/RpcInvokeResult.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Neo.IO.Json;
using Neo.SmartContract.Native;
using Neo.VM;
using Neo.VM.Types;
using System;
using System.Linq;
using System.Numerics;

namespace Neo.Network.RPC.Models
{
Expand All @@ -25,7 +27,7 @@ public JObject ToJson()
JObject json = new JObject();
json["script"] = Script;
json["state"] = State;
json["gasconsumed"] = GasConsumed;
json["gasconsumed"] = GasConsumed.ToString();
if (!string.IsNullOrEmpty(Exception))
json["exception"] = Exception;
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

namespace Neo.Network.RPC.Models
{
public class RpcNep5Balances
public class RpcNep17Balances
{
public UInt160 UserScriptHash { get; set; }

public List<RpcNep5Balance> Balances { get; set; }
public List<RpcNep17Balance> Balances { get; set; }

public JObject ToJson()
{
Expand All @@ -20,18 +20,18 @@ public JObject ToJson()
return json;
}

public static RpcNep5Balances FromJson(JObject json)
public static RpcNep17Balances FromJson(JObject json)
{
RpcNep5Balances nep5Balance = new RpcNep5Balances
RpcNep17Balances nep17Balance = new RpcNep17Balances
{
Balances = ((JArray)json["balance"]).Select(p => RpcNep5Balance.FromJson(p)).ToList(),
Balances = ((JArray)json["balance"]).Select(p => RpcNep17Balance.FromJson(p)).ToList(),
UserScriptHash = json["address"].ToScriptHash()
};
return nep5Balance;
return nep17Balance;
}
}

public class RpcNep5Balance
public class RpcNep17Balance
{
public UInt160 AssetHash { get; set; }

Expand All @@ -48,9 +48,9 @@ public JObject ToJson()
return json;
}

public static RpcNep5Balance FromJson(JObject json)
public static RpcNep17Balance FromJson(JObject json)
{
RpcNep5Balance balance = new RpcNep5Balance
RpcNep17Balance balance = new RpcNep17Balance
{
AssetHash = json["assethash"].ToScriptHash(),
Amount = BigInteger.Parse(json["amount"].AsString()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Neo.Network.RPC.Models
{
public class RpcNep5TokenInfo
public class RpcNep17TokenInfo
{
public string Name { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

namespace Neo.Network.RPC.Models
{
public class RpcNep5Transfers
public class RpcNep17Transfers
{
public UInt160 UserScriptHash { get; set; }

public List<RpcNep5Transfer> Sent { get; set; }
public List<RpcNep17Transfer> Sent { get; set; }

public List<RpcNep5Transfer> Received { get; set; }
public List<RpcNep17Transfer> Received { get; set; }

public JObject ToJson()
{
Expand All @@ -24,19 +24,19 @@ public JObject ToJson()
return json;
}

public static RpcNep5Transfers FromJson(JObject json)
public static RpcNep17Transfers FromJson(JObject json)
{
RpcNep5Transfers transfers = new RpcNep5Transfers
RpcNep17Transfers transfers = new RpcNep17Transfers
{
Sent = ((JArray)json["sent"]).Select(p => RpcNep5Transfer.FromJson(p)).ToList(),
Received = ((JArray)json["received"]).Select(p => RpcNep5Transfer.FromJson(p)).ToList(),
Sent = ((JArray)json["sent"]).Select(p => RpcNep17Transfer.FromJson(p)).ToList(),
Received = ((JArray)json["received"]).Select(p => RpcNep17Transfer.FromJson(p)).ToList(),
UserScriptHash = json["address"].ToScriptHash()
};
return transfers;
}
}

public class RpcNep5Transfer
public class RpcNep17Transfer
{
public ulong TimestampMS { get; set; }

Expand Down Expand Up @@ -65,9 +65,9 @@ public JObject ToJson()
return json;
}

public static RpcNep5Transfer FromJson(JObject json)
public static RpcNep17Transfer FromJson(JObject json)
{
return new RpcNep5Transfer
return new RpcNep17Transfer
{
TimestampMS = (ulong)json["timestamp"].AsNumber(),
AssetHash = json["assethash"].ToScriptHash(),
Expand Down
2 changes: 1 addition & 1 deletion src/RpcClient/Models/RpcTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class RpcTransaction

public JObject ToJson()
{
JObject json = Transaction.ToJson();
JObject json = Utility.TransactionToJson(Transaction);
if (Confirmations != null)
{
json["blockhash"] = BlockHash.ToString();
Expand Down
6 changes: 3 additions & 3 deletions src/RpcClient/Models/RpcUnclaimedGas.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Neo.IO.Json;
using System.Numerics;
using Neo.SmartContract.Native;

namespace Neo.Network.RPC.Models
{
public class RpcUnclaimedGas
{
public BigInteger Unclaimed { get; set; }
public BigDecimal Unclaimed { get; set; }

public string Address { get; set; }

Expand All @@ -21,7 +21,7 @@ public static RpcUnclaimedGas FromJson(JObject json)
{
return new RpcUnclaimedGas
{
Unclaimed = BigInteger.Parse(json["unclaimed"].AsString()),
Unclaimed = BigDecimal.Parse(json["unclaimed"].AsString(), NativeContract.GAS.Decimals),
Address = json["address"].AsString()
};
}
Expand Down
Loading