コード例 #1
0
        public UInt160 GetExecutionResult(Neo.Network.P2P.Payloads.InvocationTransaction transaction)
        {
            UInt160 contractHash = null;

            using (ApplicationEngine engine = new ApplicationEngine(
                       TriggerType.Application,
                       transaction,
                       Blockchain.Singleton.GetSnapshot().Clone(),
                       transaction.Gas,
                       true))
            {
                engine.LoadScript(transaction.Script);
                while (
                    !engine.State.HasFlag(VMState.FAULT) &&
                    engine.InvocationStack.Any() &&
                    engine.CurrentContext.InstructionPointer != engine.CurrentContext.Script.Length)
                {
                    var nextOpCode = engine.CurrentContext.NextInstruction.OpCode;
                    if (nextOpCode == OpCode.APPCALL || nextOpCode == OpCode.TAILCALL)
                    {
                        contractHash = new UInt160(engine.CurrentContext.NextInstruction.Operand);
                        break;
                    }

                    var executeNextMethod = typeof(ExecutionEngine).GetMethod("ExecuteNext", BindingFlags.NonPublic | BindingFlags.Instance);
                    executeNextMethod.Invoke(engine, new object[0]);
                }
            }

            return(contractHash);
        }
コード例 #2
0
        public UInt160 GetExecutionResult(Neo.Network.P2P.Payloads.InvocationTransaction transaction)
        {
            UInt160 contractHash = null;

            using (ApplicationEngine engine = new ApplicationEngine(
                       TriggerType.Application,
                       transaction,
                       Blockchain.Singleton.GetSnapshot().Clone(),
                       transaction.Gas,
                       true))
            {
                engine.LoadScript(transaction.Script);
                while (
                    !engine.State.HasFlag(VMState.FAULT) &&
                    engine.InvocationStack.Any() &&
                    engine.CurrentContext.InstructionPointer != engine.CurrentContext.Script.Length)
                {
                    var nextOpCode = engine.CurrentContext.NextInstruction;

                    if (nextOpCode == OpCode.APPCALL || nextOpCode == OpCode.TAILCALL)
                    {
                        var startingPosition = engine.CurrentContext.InstructionPointer;
                        engine.CurrentContext.InstructionPointer = startingPosition + 1;

                        var reader          = engine.CurrentContext.GetFieldValue <BinaryReader>("OpReader");
                        var rawContractHash = reader.ReadBytes(20);
                        if (rawContractHash.All(x => x == 0))
                        {
                            rawContractHash = engine.CurrentContext.EvaluationStack.Pop().GetByteArray();
                        }

                        engine.CurrentContext.InstructionPointer = startingPosition;

                        contractHash = new UInt160(rawContractHash);
                        break;
                    }

                    engine.StepInto();
                }
            }

            return(contractHash);
        }