コード例 #1
0
        public void Reset(DataNode inputs)
        {
            if (lastState.state == DebuggerState.State.Reset)
            {
                return;
            }

            if (currentTransaction == null)
            {
                //throw new Exception("Transaction not set");
                currentTransaction = new Transaction(this.blockchain.currentBlock);
            }

            _usedGas = 0;

            currentTransaction.emulator = this;
            engine = new ExecutionEngine(currentTransaction, Crypto.Default, null, interop);
            engine.LoadScript(contractBytes);

            using (ScriptBuilder sb = new ScriptBuilder())
            {
                var items = new Stack <object>();

                if (inputs != null)
                {
                    foreach (var item in inputs.Children)
                    {
                        var obj = NeoEmulator.ConvertArgument(item);
                        items.Push(obj);
                    }
                }

                while (items.Count > 0)
                {
                    var item = items.Pop();
                    EmitObject(sb, item);
                }

                engine.LoadScript(sb.ToArray());
            }

            foreach (var pos in _breakpoints)
            {
                engine.AddBreakPoint((uint)pos);
            }

            engine.Reset();

            lastState          = new DebuggerState(DebuggerState.State.Reset, 0);
            currentTransaction = null;
        }
コード例 #2
0
        public void Reset(DataNode inputs)
        {
            if (lastState.state == DebuggerState.State.Reset)
            {
                return;
            }

            if (currentTransaction == null)
            {
                //throw new Exception("Transaction not set");
                currentTransaction = new Transaction(this.blockchain.currentBlock);
            }

            usedGas         = 0;
            usedOpcodeCount = 0;

            currentTransaction.emulator = this;
            engine = new ExecutionEngine(currentTransaction, Crypto.Default, null, interop);
            engine.LoadScript(contractBytes);

            foreach (var output in currentTransaction.outputs)
            {
                if (output.hash == this.currentHash)
                {
                    output.hash = new UInt160(engine.CurrentContext.ScriptHash);
                }
            }

            foreach (var pos in _breakpoints)
            {
                engine.AddBreakPoint((uint)pos);
            }

            using (ScriptBuilder sb = new ScriptBuilder())
            {
                var items = new Stack <object>();

                if (inputs != null)
                {
                    foreach (var item in inputs.Children)
                    {
                        var obj = NeoEmulator.ConvertArgument(item);
                        items.Push(obj);
                    }
                }

                while (items.Count > 0)
                {
                    var item = items.Pop();
                    EmitObject(sb, item);
                }

                var loaderScript = sb.ToArray();
                //System.IO.File.WriteAllBytes("loader.avm", loaderScript);
                engine.LoadScript(loaderScript);
            }

            //engine.Reset();

            lastState          = new DebuggerState(DebuggerState.State.Reset, 0);
            currentTransaction = null;
        }