Skip to content
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
20 changes: 15 additions & 5 deletions src/Neo/SmartContract/ApplicationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,16 @@ protected static void OnSysCall(ExecutionEngine engine, Instruction instruction)
{
if (engine is ApplicationEngine app)
{
app.OnSysCall(GetInteropDescriptor(instruction.TokenU32));
var interop = GetInteropDescriptor(instruction.TokenU32);

if (interop?.Hardfork != null && !app.IsHardforkEnabled(interop.Hardfork.Value))
{
// The syscall is not active

throw new KeyNotFoundException();
}

app.OnSysCall(interop);
}
else
{
Expand Down Expand Up @@ -691,19 +700,20 @@ private static Block CreateDummyBlock(IReadOnlyStore snapshot, ProtocolSettings
};
}

private static InteropDescriptor Register(string name, string handler, long fixedPrice, CallFlags requiredCallFlags)
private static InteropDescriptor Register(string name, string handler, long fixedPrice, CallFlags requiredCallFlags, Hardfork? hardfork = null)
{
var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;
MethodInfo method = typeof(ApplicationEngine).GetMethod(handler, flags)
var method = typeof(ApplicationEngine).GetMethod(handler, flags)
?? typeof(ApplicationEngine).GetProperty(handler, flags).GetMethod;
InteropDescriptor descriptor = new()
var descriptor = new InteropDescriptor()
{
Name = name,
Handler = method,
Hardfork = hardfork,
FixedPrice = fixedPrice,
RequiredCallFlags = requiredCallFlags
};
services ??= new Dictionary<uint, InteropDescriptor>();
services ??= [];
services.Add(descriptor.Hash, descriptor);
return descriptor;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Neo/SmartContract/InteropDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public uint Hash
/// </summary>
public long FixedPrice { get; init; }

/// <summary>
/// Required Hardfork to be active.
/// </summary>
public Hardfork? Hardfork { get; init; }

/// <summary>
/// The required <see cref="CallFlags"/> for the interoperable service.
/// </summary>
Expand Down
Loading