private static bool Contract_Call(ApplicationEngine engine) { StackItem contractOrHash = engine.CurrentContext.EvaluationStack.Pop(); ContractState contract; if (contractOrHash is InteropInterface <ContractState> _interface) { contract = _interface; } else { contract = engine.Snapshot.Contracts.TryGet(new UInt160(contractOrHash.GetByteArray())); } if (contract is null) { return(false); } StackItem method = engine.CurrentContext.EvaluationStack.Pop(); StackItem args = engine.CurrentContext.EvaluationStack.Pop(); ContractManifest currentManifest = engine.Snapshot.Contracts.TryGet(engine.CurrentScriptHash)?.Manifest; if (currentManifest != null && !currentManifest.CanCall(contract.Manifest, method.GetString())) { return(false); } ExecutionContext context_new = engine.LoadScript(contract.Script, 1); context_new.EvaluationStack.Push(args); context_new.EvaluationStack.Push(method); return(true); }
public MethodCallback(ApplicationEngine engine, UInt160 hash, string method) : base(ApplicationEngine.System_Contract_Call, false) { if (method.StartsWith('_')) { throw new ArgumentException(); } this.contract = engine.Snapshot.Contracts[hash]; ContractManifest currentManifest = engine.Snapshot.Contracts.TryGet(engine.CurrentScriptHash)?.Manifest; if (currentManifest != null && !currentManifest.CanCall(this.contract.Manifest, method)) { throw new InvalidOperationException(); } this.method = this.contract.Manifest.Abi.Methods.First(p => p.Name == method); }