diff --git a/src/Neo.Network.RpcClient/Utility.cs b/src/Neo.Network.RpcClient/Utility.cs index 30e196de7c..eb9bad02ef 100644 --- a/src/Neo.Network.RpcClient/Utility.cs +++ b/src/Neo.Network.RpcClient/Utility.cs @@ -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; @@ -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: diff --git a/src/Neo.VM/Script.cs b/src/Neo.VM/Script.cs index 6b190130e0..28a599cdb8 100644 --- a/src/Neo.VM/Script.cs +++ b/src/Neo.VM/Script.cs @@ -26,8 +26,13 @@ public class Script { private int _hashCode = 0; private readonly ReadOnlyMemory _value; - private readonly bool strictMode; - private readonly Dictionary _instructions = new(); + private readonly bool _strictMode; + private readonly Dictionary _instructions = []; + + /// + /// Empty script + /// + public static Script Empty { get; } = new Script(ReadOnlyMemory.Empty); /// /// The length of the script. @@ -71,7 +76,7 @@ public Script(ReadOnlyMemory 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) @@ -120,7 +125,7 @@ public Script(ReadOnlyMemory 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) @@ -129,7 +134,7 @@ public Script(ReadOnlyMemory script, bool strictMode) } } } - this.strictMode = strictMode; + _strictMode = strictMode; } /// @@ -141,10 +146,10 @@ public Script(ReadOnlyMemory 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); }