diff --git a/neo/SmartContract/ApplicationEngine.cs b/neo/SmartContract/ApplicationEngine.cs index d211d7aac8..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(); @@ -36,8 +35,6 @@ public ApplicationEngine(TriggerType trigger, IVerifiable container, Snapshot sn this.Trigger = trigger; this.ScriptContainer = container; this.Snapshot = snapshot; - ContextLoaded += ApplicationEngine_ContextLoaded; - ContextUnloaded += ApplicationEngine_ContextUnloaded; } internal T AddDisposable(T disposable) where T : IDisposable @@ -52,14 +49,16 @@ private bool AddGas(long gas) return testMode || GasConsumed <= gas_amount; } - private void ApplicationEngine_ContextLoaded(object sender, ExecutionContext e) - { - hashes.Push(((byte[])e.Script).ToScriptHash()); - } - - private void ApplicationEngine_ContextUnloaded(object sender, ExecutionContext e) - { - hashes.Pop(); + protected override void LoadContext(ExecutionContext context) + { + // Set default execution context state + + context.SetState(new ExecutionContextState() + { + ScriptHash = ((byte[])context.Script).ToScriptHash() + }); + + base.LoadContext(context); } public override void Dispose() 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 diff --git a/neo/neo.csproj b/neo/neo.csproj index df29d088f2..66e85016bc 100644 --- a/neo/neo.csproj +++ b/neo/neo.csproj @@ -29,7 +29,7 @@ - +