Example #1
0
        private ExecutionEngine ExecuteVM(Transaction tx, TriggerType trigger)
        {
            Logger("Executing VM with trigger " + trigger);
            var vm = new ChainVM(this, tx);

            currentTrigger = trigger;
            currentGas     = 0;
            vm.LoadScript(tx.script);

            vm.Execute(x => OnVMStep(x));

            int index = 0;

            var sb = new StringBuilder();

            foreach (StackItem item in vm.EvaluationStack)
            {
                if (index > 0)
                {
                    sb.Append(" / ");
                }

                sb.Append(FormattingUtils.StackItemAsString(item, true));
                index++;
            }
            Logger("Stack: " + sb);

            return(vm);
        }
Example #2
0
        private ExecutionEngine ExecuteVM(Transaction tx, TriggerType trigger)
        {
            Logger("Executing VM with trigger " + trigger);
            var vm = new ChainVM(this, tx);

            currentTrigger = trigger;
            currentGas     = 0;
            vm.LoadScript(tx.script);

            while (!vm.State.HasFlag(VMState.HALT) && !vm.State.HasFlag(VMState.FAULT))
            {
                vm.Execute(x => OnVMStep(x));
                if (vm.State.HasFlag(VMState.BREAK))
                {
                    OnVMBreak(vm);
                }
            }


            if (vm.State == VMState.HALT)
            {
                int index = 0;

                var sb = new StringBuilder();
                foreach (StackItem item in vm.ResultStack)
                {
                    if (index > 0)
                    {
                        sb.Append(" / ");
                    }

                    sb.Append(FormattingUtils.StackItemAsString(item, true));
                    index++;
                }
                Logger("Stack: " + sb);
            }
            else
            {
                Logger("State: " + vm.State);
            }

            return(vm);
        }