From 86aff3ee91d52e4e446c41db567d2181912757ec Mon Sep 17 00:00:00 2001 From: Shargon Date: Thu, 22 Aug 2019 21:55:15 +0200 Subject: [PATCH] Remove hashes --- neo/SmartContract/ApplicationEngine.cs | 21 ++++++++++----------- neo/SmartContract/ExecutionContextState.cs | 10 ++++++++++ 2 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 neo/SmartContract/ExecutionContextState.cs diff --git a/neo/SmartContract/ApplicationEngine.cs b/neo/SmartContract/ApplicationEngine.cs index 9223fcb50d..45763ed30a 100644 --- a/neo/SmartContract/ApplicationEngine.cs +++ b/neo/SmartContract/ApplicationEngine.cs @@ -15,7 +15,6 @@ public partial class ApplicationEngine : ExecutionEngine public const long GasFree = 0; private readonly long gas_amount; private readonly bool testMode; - private readonly RandomAccessStack hashes = new RandomAccessStack(); private readonly List notifications = new List(); private readonly List disposables = new List(); @@ -23,9 +22,9 @@ public partial class ApplicationEngine : ExecutionEngine public IVerifiable ScriptContainer { get; } public Snapshot Snapshot { get; } public long GasConsumed { get; private set; } = 0; - public UInt160 CurrentScriptHash => hashes.Count > 0 ? hashes.Peek() : null; - public UInt160 CallingScriptHash => hashes.Count > 1 ? hashes.Peek(1) : null; - public UInt160 EntryScriptHash => hashes.Count > 0 ? hashes.Peek(hashes.Count - 1) : null; + public UInt160 CurrentScriptHash => CurrentContext?.GetState().ScriptHash; + public UInt160 CallingScriptHash => InvocationStack.Count > 1 ? InvocationStack.Peek(1).GetState().ScriptHash : null; + public UInt160 EntryScriptHash => EntryContext?.GetState().ScriptHash; public IReadOnlyList Notifications => notifications; internal Dictionary InvocationCounter { get; } = new Dictionary(); @@ -50,15 +49,15 @@ private bool AddGas(long gas) return testMode || GasConsumed <= gas_amount; } - protected override void ContextUnloaded(ExecutionContext context) - { - hashes.Pop(); - base.ContextUnloaded(context); - } - protected override void LoadContext(ExecutionContext context) { - hashes.Push(((byte[])context.Script).ToScriptHash()); + // Set default execution context state + + context.SetState(new ExecutionContextState() + { + ScriptHash = ((byte[])context.Script).ToScriptHash() + }); + base.LoadContext(context); } diff --git a/neo/SmartContract/ExecutionContextState.cs b/neo/SmartContract/ExecutionContextState.cs new file mode 100644 index 0000000000..7895d943a2 --- /dev/null +++ b/neo/SmartContract/ExecutionContextState.cs @@ -0,0 +1,10 @@ +namespace Neo.SmartContract +{ + public class ExecutionContextState + { + /// + /// Script hash + /// + public UInt160 ScriptHash { get; set; } + } +} \ No newline at end of file