/// <summary> /// Invoke method /// </summary> /// <param name="method">Method</param> /// <param name="engine">Execution engine</param> /// <returns>Return false if something is wrong</returns> public bool Invoke(byte[] method, ExecutionEngineBase engine) { var hash = method.Length == 4 ? BitConverter.ToUInt32(method, 0) : GetMethodHash(Encoding.ASCII.GetString(method)); void InvokeOnSysCall(SysCallResult result) => OnSysCall?.Invoke(this, new SysCallArgs(engine, GetMethodName(hash), hash, result)); if (!_entries.TryGetValue(hash, out var entry)) { InvokeOnSysCall(SysCallResult.NotFound); return(false); } if (!engine.IncreaseGas(entry.GasCost)) { InvokeOnSysCall(SysCallResult.OutOfGas); return(false); } var ret = entry.MethodHandler(engine); InvokeOnSysCall(ret ? SysCallResult.True : SysCallResult.False); return(ret); }
/// <summary> /// Invoke /// </summary> /// <param name="method">Method name</param> /// <param name="engine">Execution engine</param> /// <returns>Return false if something wrong</returns> public bool Invoke(string method, IExecutionEngine engine) { if (!Entries.TryGetValue(method, out delHandler func)) { OnSysCall?.Invoke(this, new SysCallArgs(engine, method, SysCallArgs.EResult.NotFound)); return(false); } var ret = func(engine); OnSysCall?.Invoke(this, new SysCallArgs(engine, method, ret ? SysCallArgs.EResult.True : SysCallArgs.EResult.False)); return(ret); }