Skip to content

Commit

Permalink
Remove hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon committed Aug 22, 2019
1 parent ea39390 commit 86aff3e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
21 changes: 10 additions & 11 deletions neo/SmartContract/ApplicationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ public partial class ApplicationEngine : ExecutionEngine
public const long GasFree = 0;
private readonly long gas_amount;
private readonly bool testMode;
private readonly RandomAccessStack<UInt160> hashes = new RandomAccessStack<UInt160>();
private readonly List<NotifyEventArgs> notifications = new List<NotifyEventArgs>();
private readonly List<IDisposable> disposables = new List<IDisposable>();

public TriggerType Trigger { get; }
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<ExecutionContextState>().ScriptHash;
public UInt160 CallingScriptHash => InvocationStack.Count > 1 ? InvocationStack.Peek(1).GetState<ExecutionContextState>().ScriptHash : null;
public UInt160 EntryScriptHash => EntryContext?.GetState<ExecutionContextState>().ScriptHash;
public IReadOnlyList<NotifyEventArgs> Notifications => notifications;
internal Dictionary<UInt160, int> InvocationCounter { get; } = new Dictionary<UInt160, int>();

Expand All @@ -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);
}

Expand Down
10 changes: 10 additions & 0 deletions neo/SmartContract/ExecutionContextState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Neo.SmartContract
{
public class ExecutionContextState
{
/// <summary>
/// Script hash
/// </summary>
public UInt160 ScriptHash { get; set; }
}
}

0 comments on commit 86aff3e

Please sign in to comment.