Skip to content

Commit

Permalink
neo 3.4.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Hecate2 committed Aug 12, 2022
1 parent b948bb3 commit 0d3018b
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 59 deletions.
2 changes: 1 addition & 1 deletion Fairy.Coverage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Neo;
using Neo.IO.Json;
using Neo.Json;

namespace Neo.Plugins
{
Expand Down
14 changes: 7 additions & 7 deletions Fairy.Debugger.Breakpoint.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Neo.IO.Json;
using Neo.Json;
using Neo.SmartContract.Native;
using System.Collections.Concurrent;

Expand All @@ -10,7 +10,7 @@ public partial class Fairy
readonly ConcurrentDictionary<UInt160, HashSet<SourceFilenameAndLineNum>> contractScriptHashToSourceCodeBreakpoints = new();

[RpcMethod]
protected virtual JObject SetAssemblyBreakpoints(JArray _params)
protected virtual JToken SetAssemblyBreakpoints(JArray _params)
{
UInt160 scriptHash = UInt160.Parse(_params[0].AsString());
if (!contractScriptHashToInstructionPointerToSourceLineNum.ContainsKey(scriptHash))
Expand Down Expand Up @@ -38,7 +38,7 @@ protected virtual JObject SetAssemblyBreakpoints(JArray _params)
}

[RpcMethod]
protected virtual JObject ListAssemblyBreakpoints(JArray _params)
protected virtual JToken ListAssemblyBreakpoints(JArray _params)
{
UInt160 scriptHash = UInt160.Parse(_params[0].AsString());
if (!contractScriptHashToInstructionPointerToSourceLineNum.ContainsKey(scriptHash))
Expand All @@ -57,7 +57,7 @@ protected virtual JObject ListAssemblyBreakpoints(JArray _params)
}

[RpcMethod]
protected virtual JObject DeleteAssemblyBreakpoints(JArray _params)
protected virtual JToken DeleteAssemblyBreakpoints(JArray _params)
{
UInt160 scriptHash = UInt160.Parse(_params[0].AsString());
if (!contractScriptHashToInstructionPointerToSourceLineNum.ContainsKey(scriptHash))
Expand Down Expand Up @@ -90,7 +90,7 @@ protected virtual JObject DeleteAssemblyBreakpoints(JArray _params)
}

[RpcMethod]
protected virtual JObject SetSourceCodeBreakpoints(JArray _params)
protected virtual JToken SetSourceCodeBreakpoints(JArray _params)
{
UInt160 scriptHash = UInt160.Parse(_params[0].AsString());
if (!contractScriptHashToInstructionPointerToSourceLineNum.ContainsKey(scriptHash))
Expand Down Expand Up @@ -130,7 +130,7 @@ protected virtual JObject SetSourceCodeBreakpoints(JArray _params)
}

[RpcMethod]
protected virtual JObject ListSourceCodeBreakpoints(JArray _params)
protected virtual JToken ListSourceCodeBreakpoints(JArray _params)
{
UInt160 scriptHash = UInt160.Parse(_params[0].AsString());
if (!contractScriptHashToInstructionPointerToSourceLineNum.ContainsKey(scriptHash))
Expand All @@ -151,7 +151,7 @@ protected virtual JObject ListSourceCodeBreakpoints(JArray _params)
}

[RpcMethod]
protected virtual JObject DeleteSourceCodeBreakpoints(JArray _params)
protected virtual JToken DeleteSourceCodeBreakpoints(JArray _params)
{
UInt160 scriptHash = UInt160.Parse(_params[0].AsString());
if (!contractScriptHashToInstructionPointerToSourceLineNum.ContainsKey(scriptHash))
Expand Down
14 changes: 7 additions & 7 deletions Fairy.Debugger.DebugInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Neo.IO.Json;
using Neo.Json;
using Neo.VM;
using Neo.SmartContract.Native;
using System.IO.Compression;
Expand Down Expand Up @@ -43,14 +43,14 @@ public static string Unzip(byte[] zippedBuffer)
}

[RpcMethod]
protected virtual JObject SetDebugInfo(JArray _params)
protected virtual JToken SetDebugInfo(JArray _params)
{
string param0 = _params[0].AsString();
UInt160 scriptHash = UInt160.Parse(param0);
// nccs YourContractProject.csproj --debug
// find .nefdbgnfo beside your .nef contract, and
// give me the base64encode(content) of .nefdbgnfo file
JObject nefDbgNfo = JObject.Parse(Unzip(Convert.FromBase64String(_params[1].AsString())));
JObject nefDbgNfo = (JObject)JObject.Parse(Unzip(Convert.FromBase64String(_params[1].AsString())));
contractScriptHashToNefDbgNfo[scriptHash] = nefDbgNfo;
// https://github.com/devhawk/DumpNef
// dumpnef contract.nef > contract.nef.txt
Expand Down Expand Up @@ -110,7 +110,7 @@ protected virtual JObject SetDebugInfo(JArray _params)
}

[RpcMethod]
protected virtual JObject ListDebugInfo(JArray _params)
protected virtual JToken ListDebugInfo(JArray _params)
{
JArray scriptHashes = new JArray();
foreach (UInt160 s in contractScriptHashToInstructionPointerToSourceLineNum.Keys)
Expand All @@ -121,7 +121,7 @@ protected virtual JObject ListDebugInfo(JArray _params)
}

[RpcMethod]
protected virtual JObject ListFilenamesOfContract(JArray _params)
protected virtual JToken ListFilenamesOfContract(JArray _params)
{
string scriptHashStr = _params[0].AsString();
UInt160 scriptHash = UInt160.Parse(scriptHashStr);
Expand All @@ -136,7 +136,7 @@ protected virtual JObject ListFilenamesOfContract(JArray _params)
}

[RpcMethod]
protected virtual JObject DeleteDebugInfo(JArray _params)
protected virtual JToken DeleteDebugInfo(JArray _params)
{
JObject json = new();
foreach (var s in _params)
Expand All @@ -158,7 +158,7 @@ protected virtual JObject DeleteDebugInfo(JArray _params)
}

[RpcMethod]
protected virtual JObject GetMethodByInstructionPointer(JArray _params)
protected virtual JToken GetMethodByInstructionPointer(JArray _params)
{
UInt160 scriptHash = UInt160.Parse(_params[0].AsString());
uint instrcutionPointer = uint.Parse(_params[1].AsString());
Expand Down
4 changes: 2 additions & 2 deletions Fairy.Debugger.Snapshot.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Neo.IO.Json;
using Neo.Json;
using System.Collections.Concurrent;

namespace Neo.Plugins
Expand All @@ -8,7 +8,7 @@ public partial class Fairy
public readonly ConcurrentDictionary<string, FairyEngine> debugSessionToEngine = new();

[RpcMethod]
protected virtual JObject ListDebugSnapshots(JArray _params)
protected virtual JToken ListDebugSnapshots(JArray _params)
{
JArray session = new JArray();
foreach (string s in debugSessionToEngine.Keys)
Expand Down
40 changes: 20 additions & 20 deletions Fairy.Debugger.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Neo.IO;
using Neo.IO.Json;
using Neo.Json;
using Neo.Network.P2P.Payloads;
using Neo.Persistence;
using Neo.SmartContract;
Expand All @@ -21,13 +21,13 @@ enum BreakReason
}

[RpcMethod]
protected virtual JObject DebugFunctionWithSession(JArray _params)
protected virtual JToken DebugFunctionWithSession(JArray _params)
{
string session = _params[0].AsString();
bool writeSnapshot = _params[1].AsBoolean();
UInt160 script_hash = UInt160.Parse(_params[2].AsString());
string operation = _params[3].AsString();
ContractParameter[] args = _params.Count >= 5 ? ((JArray)_params[4]).Select(p => ContractParameter.FromJson(p)).ToArray() : System.Array.Empty<ContractParameter>();
ContractParameter[] args = _params.Count >= 5 ? ((JArray)_params[4]).Select(p => ContractParameter.FromJson((JObject)p)).ToArray() : System.Array.Empty<ContractParameter>();
Signers? signers = _params.Count >= 6 ? SignersFromJson((JArray)_params[5], system.Settings) : null;

byte[] script;
Expand Down Expand Up @@ -72,7 +72,7 @@ protected virtual JObject DebugFunctionWithSession(JArray _params)
}

[RpcMethod]
protected virtual JObject DebugContinue(JArray _params)
protected virtual JToken DebugContinue(JArray _params)
{
string session = _params[0].AsString();
FairyEngine newEngine = debugSessionToEngine[session];
Expand Down Expand Up @@ -110,7 +110,7 @@ private JObject DumpDebugResultJson(JObject json, FairyEngine newEngine, BreakRe
traceback += newEngine.FaultException.StackTrace;
foreach (Neo.VM.ExecutionContext context in newEngine.InvocationStack)
{
traceback += $"\r\nInstructionPointer={context.InstructionPointer}, OpCode {context.CurrentInstruction.OpCode}, Script Length={context.Script.Length}";
traceback += $"\r\nInstructionPointer={context.InstructionPointer}, OpCode {context.CurrentInstruction?.OpCode}, Script Length={context.Script.Length}";
}
if (!logs.IsEmpty)
{
Expand Down Expand Up @@ -239,7 +239,7 @@ private FairyEngine StepInto(FairyEngine engine, out BreakReason breakReason)
}

[RpcMethod]
protected virtual JObject DebugStepInto(JArray _params)
protected virtual JToken DebugStepInto(JArray _params)
{
string session = _params[0].AsString();
FairyEngine newEngine = debugSessionToEngine[session];
Expand All @@ -262,7 +262,7 @@ private FairyEngine StepOut(FairyEngine engine, out BreakReason breakReason)
}

[RpcMethod]
protected virtual JObject DebugStepOut(JArray _params)
protected virtual JToken DebugStepOut(JArray _params)
{
string session = _params[0].AsString();
FairyEngine newEngine = debugSessionToEngine[session];
Expand Down Expand Up @@ -296,7 +296,7 @@ private FairyEngine StepOverSourceCode(FairyEngine engine, out BreakReason break
}

[RpcMethod]
protected virtual JObject DebugStepOverSourceCode(JArray _params)
protected virtual JToken DebugStepOverSourceCode(JArray _params)
{
string session = _params[0].AsString();
FairyEngine newEngine = debugSessionToEngine[session];
Expand All @@ -309,7 +309,7 @@ protected virtual JObject DebugStepOverSourceCode(JArray _params)
}

[RpcMethod]
protected virtual JObject DebugStepOverAssembly(JArray _params)
protected virtual JToken DebugStepOverAssembly(JArray _params)
{
string session = _params[0].AsString();
FairyEngine newEngine = debugSessionToEngine[session];
Expand All @@ -322,13 +322,13 @@ protected virtual JObject DebugStepOverAssembly(JArray _params)
}

[RpcMethod]
protected virtual JObject DebugStepOver(JArray _params)
protected virtual JToken DebugStepOver(JArray _params)
{
return DebugStepOverSourceCode(_params);
}

[RpcMethod]
protected virtual JObject GetLocalVariables(JArray _params)
protected virtual JToken GetLocalVariables(JArray _params)
{
string session = _params[0].AsString();
int invocationStackIndex = _params.Count > 1 ? int.Parse(_params[1].AsString()) : 0;
Expand All @@ -337,7 +337,7 @@ protected virtual JObject GetLocalVariables(JArray _params)
}

[RpcMethod]
protected virtual JObject GetArguments(JArray _params)
protected virtual JToken GetArguments(JArray _params)
{
string session = _params[0].AsString();
int invocationStackIndex = _params.Count > 1 ? int.Parse(_params[1].AsString()) : 0;
Expand All @@ -346,7 +346,7 @@ protected virtual JObject GetArguments(JArray _params)
}

[RpcMethod]
protected virtual JObject GetStaticFields(JArray _params)
protected virtual JToken GetStaticFields(JArray _params)
{
string session = _params[0].AsString();
int invocationStackIndex = _params.Count > 1 ? int.Parse(_params[1].AsString()) : 0;
Expand All @@ -355,7 +355,7 @@ protected virtual JObject GetStaticFields(JArray _params)
}

[RpcMethod]
protected virtual JObject GetEvaluationStack(JArray _params)
protected virtual JToken GetEvaluationStack(JArray _params)
{
string session = _params[0].AsString();
int invocationStackIndex = _params.Count > 1 ? int.Parse(_params[1].AsString()) : 0;
Expand All @@ -364,7 +364,7 @@ protected virtual JObject GetEvaluationStack(JArray _params)
}

[RpcMethod]
protected virtual JObject GetInstructionPointer(JArray _params)
protected virtual JToken GetInstructionPointer(JArray _params)
{
string session = _params[0].AsString();
int invocationStackIndex = _params.Count > 1 ? int.Parse(_params[1].AsString()) : 0;
Expand All @@ -373,7 +373,7 @@ protected virtual JObject GetInstructionPointer(JArray _params)
}

[RpcMethod]
protected virtual JObject GetVariableValueByName(JArray _params)
protected virtual JToken GetVariableValueByName(JArray _params)
{
string session = _params[0].AsString();
string variableName = _params[1].AsString();
Expand All @@ -382,15 +382,15 @@ protected virtual JObject GetVariableValueByName(JArray _params)
}

[RpcMethod]
protected virtual JObject GetVariableNamesAndValues(JArray _params)
protected virtual JToken GetVariableNamesAndValues(JArray _params)
{
string session = _params[0].AsString();
int invocationStackIndex = _params.Count > 1 ? int.Parse(_params[1].AsString()) : 0;
FairyEngine newEngine = debugSessionToEngine[session];
Neo.VM.ExecutionContext invocationStackItem = newEngine.InvocationStack.ElementAt(invocationStackIndex);
UInt160 invocationStackScriptHash = invocationStackItem.GetScriptHash();
int instructionPointer = invocationStackItem.InstructionPointer;
JObject method = GetMethodByInstructionPointer(new JArray(invocationStackScriptHash.ToString(), instructionPointer));
JToken method = GetMethodByInstructionPointer(new JArray(invocationStackScriptHash.ToString(), instructionPointer));
JObject returnedJson = new();
JArray staticVariables = (JArray)contractScriptHashToNefDbgNfo[invocationStackScriptHash]["static-variables"];
foreach (JObject param in staticVariables)
Expand All @@ -401,13 +401,13 @@ protected virtual JObject GetVariableNamesAndValues(JArray _params)
}
if (method != JObject.Null)
{
foreach (JObject param in (JArray)method["params"])
foreach (JToken param in (JArray)method["params"])
{
string[] nameTypeAndIndex = param.AsString().Split(',');
int index = int.Parse(nameTypeAndIndex[2]);
returnedJson[nameTypeAndIndex[0]] = invocationStackItem.Arguments[index].ToJson();
}
foreach (JObject param in (JArray)method["variables"])
foreach (JToken param in (JArray)method["variables"])
{
string[] nameTypeAndIndex = param.AsString().Split(',');
int index = int.Parse(nameTypeAndIndex[2]);
Expand Down
20 changes: 10 additions & 10 deletions Fairy.Tester.Snapshot.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Neo.IO.Json;
using Neo.Json;
using System.Collections.Concurrent;
using System.Numerics;

Expand All @@ -25,7 +25,7 @@ private FairyEngine BuildSnapshotWithDummyScript(FairyEngine engine = null)
}

[RpcMethod]
protected virtual JObject NewSnapshotsFromCurrentSystem(JArray _params)
protected virtual JToken NewSnapshotsFromCurrentSystem(JArray _params)
{
JObject json = new();
foreach (var param in _params)
Expand All @@ -42,7 +42,7 @@ protected virtual JObject NewSnapshotsFromCurrentSystem(JArray _params)
}

[RpcMethod]
protected virtual JObject DeleteSnapshots(JArray _params)
protected virtual JToken DeleteSnapshots(JArray _params)
{
JObject json = new();
foreach (var s in _params)
Expand All @@ -54,7 +54,7 @@ protected virtual JObject DeleteSnapshots(JArray _params)
}

[RpcMethod]
protected virtual JObject ListSnapshots(JArray _params)
protected virtual JToken ListSnapshots(JArray _params)
{
JArray session = new JArray();
foreach (string s in sessionToEngine.Keys)
Expand All @@ -65,7 +65,7 @@ protected virtual JObject ListSnapshots(JArray _params)
}

[RpcMethod]
protected virtual JObject RenameSnapshot(JArray _params)
protected virtual JToken RenameSnapshot(JArray _params)
{
string from = _params[0].AsString();
string to = _params[1].AsString();
Expand All @@ -79,7 +79,7 @@ protected virtual JObject RenameSnapshot(JArray _params)
}

[RpcMethod]
protected virtual JObject CopySnapshot(JArray _params)
protected virtual JToken CopySnapshot(JArray _params)
{
string from = _params[0].AsString();
string to = _params[1].AsString();
Expand All @@ -91,7 +91,7 @@ protected virtual JObject CopySnapshot(JArray _params)
}

[RpcMethod]
protected virtual JObject SetSnapshotTimestamp(JArray _params)
protected virtual JToken SetSnapshotTimestamp(JArray _params)
{
string session = _params[0].AsString();
ulong timestamp = ulong.Parse(_params[1].AsString());
Expand All @@ -104,7 +104,7 @@ protected virtual JObject SetSnapshotTimestamp(JArray _params)
}

[RpcMethod]
protected virtual JObject GetSnapshotTimeStamp(JArray _params)
protected virtual JToken GetSnapshotTimeStamp(JArray _params)
{
JObject json = new();
foreach (var s in _params)
Expand All @@ -116,7 +116,7 @@ protected virtual JObject GetSnapshotTimeStamp(JArray _params)
}

//[RpcMethod]
//protected virtual JObject SetSnapshotRandom(JArray _params)
//protected virtual JToken SetSnapshotRandom(JArray _params)
//{
// string session = _params[0].AsString();
// string? designatedRandomString = _params[1]?.AsString();
Expand All @@ -139,7 +139,7 @@ protected virtual JObject GetSnapshotTimeStamp(JArray _params)
//}

//[RpcMethod]
//protected virtual JObject GetSnapshotRandom(JArray _params)
//protected virtual JToken GetSnapshotRandom(JArray _params)
//{
// JObject json = new();
// foreach (var s in _params)
Expand Down
Loading

0 comments on commit 0d3018b

Please sign in to comment.