Skip to content

Commit

Permalink
Add AppEngine.ValidateCallFlags to be callable by subclasses (#1784)
Browse files Browse the repository at this point in the history
* Update ApplicationEngine.cs

separate call flag validation into separate function so it can be called by ApplicationEngine subclasses. This is needed for the debugger, which overrides a few of the standard service implementations

* fix whitespace

* protected internal addGas

Co-authored-by: Harry Pierson <[email protected]>
  • Loading branch information
devhawk and Harry Pierson authored Jul 22, 2020
1 parent 54a1094 commit 13f303d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/neo/SmartContract/ApplicationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected ApplicationEngine(TriggerType trigger, IVerifiable container, StoreVie
this.testMode = testMode;
}

internal void AddGas(long gas)
protected internal void AddGas(long gas)
{
GasConsumed = checked(GasConsumed + gas);
if (!testMode && GasConsumed > gas_amount)
Expand Down Expand Up @@ -217,12 +217,17 @@ public override void Dispose()
base.Dispose();
}

protected override void OnSysCall(uint method)
protected void ValidateCallFlags(InteropDescriptor descriptor)
{
InteropDescriptor descriptor = services[method];
ExecutionContextState state = CurrentContext.GetState<ExecutionContextState>();
if (!state.CallFlags.HasFlag(descriptor.RequiredCallFlags))
throw new InvalidOperationException($"Cannot call this SYSCALL with the flag {state.CallFlags}.");
}

protected override void OnSysCall(uint method)
{
InteropDescriptor descriptor = services[method];
ValidateCallFlags(descriptor);
AddGas(descriptor.FixedPrice);
List<object> parameters = descriptor.Parameters.Count > 0
? new List<object>()
Expand Down

0 comments on commit 13f303d

Please sign in to comment.