Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Dispose ApplicationEngine after using (2.x) #507

Merged
merged 1 commit into from
Dec 10, 2019
Merged
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
56 changes: 30 additions & 26 deletions neo-cli/Shell/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,23 @@ private bool OnDeployCommand(string[] args)
if (tx.Inputs == null) tx.Inputs = new CoinReference[0];
if (tx.Outputs == null) tx.Outputs = new TransactionOutput[0];
if (tx.Witnesses == null) tx.Witnesses = new Witness[0];
ApplicationEngine engine = ApplicationEngine.Run(tx.Script, tx, null, true);
StringBuilder sb = new StringBuilder();
sb.AppendLine($"Script hash: {scriptHash.ToString()}");
sb.AppendLine($"VM State: {engine.State}");
sb.AppendLine($"Gas Consumed: {engine.GasConsumed}");
sb.AppendLine(
$"Evaluation Stack: {new JArray(engine.ResultStack.Select(p => p.ToParameter().ToJson()))}");
Console.WriteLine(sb.ToString());
if (engine.State.HasFlag(VMState.FAULT))
{
Console.WriteLine("Engine faulted.");
return true;
}
using (ApplicationEngine engine = ApplicationEngine.Run(tx.Script, tx, null, true))
{
StringBuilder sb = new StringBuilder();
sb.AppendLine($"Script hash: {scriptHash.ToString()}");
sb.AppendLine($"VM State: {engine.State}");
sb.AppendLine($"Gas Consumed: {engine.GasConsumed}");
sb.AppendLine(
$"Evaluation Stack: {new JArray(engine.ResultStack.Select(p => p.ToParameter().ToJson()))}");
Console.WriteLine(sb.ToString());
if (engine.State.HasFlag(VMState.FAULT))
{
Console.WriteLine("Engine faulted.");
return true;
}

tx.Gas = engine.GasConsumed - Fixed8.FromDecimal(10);
tx.Gas = engine.GasConsumed - Fixed8.FromDecimal(10);
}
if (tx.Gas < Fixed8.Zero) tx.Gas = Fixed8.Zero;
tx.Gas = tx.Gas.Ceiling();

Expand Down Expand Up @@ -226,19 +228,21 @@ private bool OnInvokeCommand(string[] args)
if (tx.Inputs == null) tx.Inputs = new CoinReference[0];
if (tx.Outputs == null) tx.Outputs = new TransactionOutput[0];
if (tx.Witnesses == null) tx.Witnesses = new Witness[0];
ApplicationEngine engine = ApplicationEngine.Run(tx.Script, tx);

StringBuilder sb = new StringBuilder();
sb.AppendLine($"VM State: {engine.State}");
sb.AppendLine($"Gas Consumed: {engine.GasConsumed}");
sb.AppendLine(
$"Evaluation Stack: {new JArray(engine.ResultStack.Select(p => p.ToParameter().ToJson()))}");
Console.WriteLine(sb.ToString());
if (engine.State.HasFlag(VMState.FAULT))
{
Console.WriteLine("Engine faulted.");
return true;
using (ApplicationEngine engine = ApplicationEngine.Run(tx.Script, tx))
{
StringBuilder sb = new StringBuilder();
sb.AppendLine($"VM State: {engine.State}");
sb.AppendLine($"Gas Consumed: {engine.GasConsumed}");
sb.AppendLine(
$"Evaluation Stack: {new JArray(engine.ResultStack.Select(p => p.ToParameter().ToJson()))}");
Console.WriteLine(sb.ToString());
if (engine.State.HasFlag(VMState.FAULT))
{
Console.WriteLine("Engine faulted.");
return true;
}
}

if (NoWallet()) return true;
tx = DecorateInvocationTransaction(tx);
if (tx == null)
Expand Down