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

Capture fault Exception #1761

Merged
merged 4 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 7 additions & 0 deletions src/neo/SmartContract/ApplicationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ private class InvocationState
public StoreView Snapshot { get; }
public long GasConsumed { get; private set; } = 0;
public long GasLeft => testMode ? -1 : gas_amount - GasConsumed;
public Exception FaultException { get; private set; }
public UInt160 CurrentScriptHash => CurrentContext?.GetState<ExecutionContextState>().ScriptHash;
public UInt160 CallingScriptHash => CurrentContext?.GetState<ExecutionContextState>().CallingScriptHash;
public UInt160 EntryScriptHash => EntryContext?.GetState<ExecutionContextState>().ScriptHash;
Expand All @@ -61,6 +62,12 @@ internal void AddGas(long gas)
throw new InvalidOperationException("Insufficient GAS.");
}

protected override void OnFault(Exception e)
{
FaultException = e;
base.OnFault(e);
}

internal void CallFromNativeContract(Action onComplete, UInt160 hash, string method, params StackItem[] args)
{
InvocationState state = GetInvocationState(CurrentContext);
Expand Down
5 changes: 4 additions & 1 deletion src/neo/Wallets/Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,11 @@ private Transaction MakeTransaction(StoreView snapshot, byte[] script, Transacti
// will try to execute 'transfer' script to check if it works
using (ApplicationEngine engine = ApplicationEngine.Run(script, snapshot.Clone(), tx, testMode: true))
{
if (engine.State.HasFlag(VMState.FAULT))
if (engine.State == VMState.FAULT)
{
if (engine.FaultException != null) throw engine.FaultException;
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
throw new InvalidOperationException($"Failed execution for '{script.ToHexString()}'");
}
tx.SystemFee = engine.GasConsumed;
}

Expand Down