Skip to content

Commit

Permalink
Update VM to last changes (#1048)
Browse files Browse the repository at this point in the history
* Update VM to last changes

* Remove hashes
  • Loading branch information
shargon authored Aug 23, 2019
1 parent b1a4d29 commit 8960dd8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
27 changes: 13 additions & 14 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 @@ -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>(T disposable) where T : IDisposable
Expand All @@ -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()
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; }
}
}
2 changes: 1 addition & 1 deletion neo/neo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
<PackageReference Include="Neo.VM" Version="3.0.0-CI00030" />
<PackageReference Include="Neo.VM" Version="3.0.0-CI00033" />
<PackageReference Include="System.Text.Encodings.Web" Version="4.5.0" />
</ItemGroup>

Expand Down

0 comments on commit 8960dd8

Please sign in to comment.