Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update VM to last changes #1048

Merged
merged 2 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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