Skip to content
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
3 changes: 2 additions & 1 deletion src/Neo.Network.RpcClient/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Neo.Network.P2P.Payloads.Conditions;
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.VM;
using Neo.VM.Types;
using Neo.Wallets;
using System;
Expand Down Expand Up @@ -282,7 +283,7 @@ public static StackItem StackItemFromJson(JObject json)
}
return map;
case StackItemType.Pointer:
return new Pointer(null, (int)json["value"].AsNumber());
return new Pointer(Script.Empty, (int)json["value"].AsNumber());
case StackItemType.InteropInterface:
return new InteropInterface(json);
default:
Expand Down
19 changes: 12 additions & 7 deletions src/Neo.VM/Script.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ public class Script
{
private int _hashCode = 0;
private readonly ReadOnlyMemory<byte> _value;
private readonly bool strictMode;
private readonly Dictionary<int, Instruction> _instructions = new();
private readonly bool _strictMode;
private readonly Dictionary<int, Instruction> _instructions = [];

/// <summary>
/// Empty script
/// </summary>
public static Script Empty { get; } = new Script(ReadOnlyMemory<byte>.Empty);

/// <summary>
/// The length of the script.
Expand Down Expand Up @@ -71,7 +76,7 @@ public Script(ReadOnlyMemory<byte> script, bool strictMode)
Length = _value.Length;
if (strictMode)
{
for (int ip = 0; ip < script.Length; ip += GetInstruction(ip).Size) { }
for (var ip = 0; ip < script.Length; ip += GetInstruction(ip).Size) { }
foreach (var (ip, instruction) in _instructions)
{
switch (instruction.OpCode)
Expand Down Expand Up @@ -120,7 +125,7 @@ public Script(ReadOnlyMemory<byte> script, bool strictMode)
case OpCode.NEWARRAY_T:
case OpCode.ISTYPE:
case OpCode.CONVERT:
StackItemType type = (StackItemType)instruction.TokenU8;
var type = (StackItemType)instruction.TokenU8;
if (!Enum.IsDefined(typeof(StackItemType), type))
throw new BadScriptException();
if (instruction.OpCode != OpCode.NEWARRAY_T && type == StackItemType.Any)
Expand All @@ -129,7 +134,7 @@ public Script(ReadOnlyMemory<byte> script, bool strictMode)
}
}
}
this.strictMode = strictMode;
_strictMode = strictMode;
}

/// <summary>
Expand All @@ -141,10 +146,10 @@ public Script(ReadOnlyMemory<byte> script, bool strictMode)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Instruction GetInstruction(int ip)
{
if (!_instructions.TryGetValue(ip, out Instruction? instruction))
if (!_instructions.TryGetValue(ip, out var instruction))
{
if (ip >= Length) throw new ArgumentOutOfRangeException(nameof(ip));
if (strictMode) throw new ArgumentException($"ip not found with strict mode", nameof(ip));
if (_strictMode) throw new ArgumentException($"ip not found with strict mode", nameof(ip));
instruction = new Instruction(_value, ip);
_instructions.Add(ip, instruction);
}
Expand Down