public static MyJson.JsonNode_Object StatkItemToJson(VM.StackItem item) { MyJson.JsonNode_Object json = new MyJson.JsonNode_Object(); var type = item.GetType().Name; if (type == "InteropInterface") { json.SetDictValue(type, (item as VM.Types.InteropInterface).GetInterface <VM.IInteropInterface>().GetType().Name); } else if (type == "Boolean") { json.SetDictValue(type, item.GetBoolean().ToString()); } else if (type == "ByteArray") { json.SetDictValue(type, item.GetByteArray().ToHexString()); } else if (type == "Integer") { json.SetDictValue(type, item.GetBigInteger().ToString()); } else if (item is VM.Types.Array)//item is VM.Types.Struct || 是struct 一定是array { MyJson.JsonNode_Array array = new MyJson.JsonNode_Array(); json.SetDictValue(type, array); foreach (var i in (item as VM.Types.Array).ToArray()) { array.Add(StatkItemToJson(i)); } } return(json); }
void LogResult(VM.OpCode nextOpcode, VM.ExecutionStackRecord.Op[] records, VM.StackItem lastrecord) { if (records != null && records.Length > 0) { this.FullLog.OPStackRecord(records.ToArray()); } if (lastrecord != null) { this.FullLog.OpResult(lastrecord); } }
public new bool Execute() { try { while (!State.HasFlag(VMState.HALT) && !State.HasFlag(VMState.FAULT)) { OpCode nextOpcode = OpCode.NOP; if (CurrentContext.InstructionPointer < CurrentContext.Script.Length) { nextOpcode = CurrentContext.NextInstruction; if (this.FullLog != null) { this.FullLog.NextOp(CurrentContext.InstructionPointer, nextOpcode); this.EvaluationStack.ClearRecord(); } gas_consumed = checked (gas_consumed + GetPrice(nextOpcode) * ratio); if (!testMode && gas_consumed > gas_amount) { if (FullLog != null) { FullLog.Error("gas_consumed > gas_amount"); } State |= VMState.FAULT; return(false); } if (!CheckItemSize(nextOpcode)) { if (FullLog != null) { FullLog.Error("CheckItemSize"); } State |= VMState.FAULT; return(false); } if (!CheckStackSize(nextOpcode)) { if (FullLog != null) { FullLog.Error("CheckStackSize"); } State |= VMState.FAULT; return(false); } if (!CheckArraySize(nextOpcode)) { if (FullLog != null) { FullLog.Error("CheckArraySize"); } State |= VMState.FAULT; return(false); } if (!CheckInvocationStack(nextOpcode)) { if (FullLog != null) { FullLog.Error("CheckInvocationStack"); } State |= VMState.FAULT; return(false); } if (!CheckBigIntegers(nextOpcode)) { if (FullLog != null) { FullLog.Error("CheckBigIntegers"); } State |= VMState.FAULT; return(false); } if (!CheckDynamicInvoke(nextOpcode)) { if (FullLog != null) { FullLog.Error("CheckBigIntegers"); } State |= VMState.FAULT; return(false); } } StepInto(); if (FullLog != null) { VM.StackItem result = null; ExecutionStackRecord.Op[] record = this.EvaluationStack.record.ToArray(); var ltype = this.EvaluationStack.GetLastRecordType(); if (ltype == ExecutionStackRecord.OpType.Push) { result = this.EvaluationStack.PeekWithoutLog(); } else if (ltype == ExecutionStackRecord.OpType.Insert) { result = this.EvaluationStack.PeekWithoutLog(this.EvaluationStack.record.Last().ind); } else if (ltype == ExecutionStackRecord.OpType.Set) { result = this.EvaluationStack.PeekWithoutLog(this.EvaluationStack.record.Last().ind); } LogResult(nextOpcode, record, result); } } } catch (Exception err) { State |= VMState.FAULT; return(false); } if (FullLog != null) { FullLog.Finish(State); } return(!State.HasFlag(VMState.FAULT)); }
public void OpResult(VM.StackItem item) { curOp.opresult = item; }
public new bool Execute() { try { while (true) { OpCode nextOpcode = CurrentContext.InstructionPointer >= CurrentContext.Script.Length ? OpCode.RET : CurrentContext.NextInstruction; if (this.DumpInfo != null) { this.DumpInfo.NextOp(CurrentContext.InstructionPointer, nextOpcode); this.CurrentContext.EvaluationStack.ClearRecord(); } if (!PreStepInto(nextOpcode)) { State |= VMState.FAULT; return(false); } StepInto(); if (State.HasFlag(VMState.HALT) || State.HasFlag(VMState.FAULT)) { break; } if (DumpInfo != null) { if (State.HasFlag(VMState.HALT) || State.HasFlag(VMState.FAULT)) { continue; } var EvaluationStackRec = this.CurrentContext.EvaluationStack; VM.StackItem result = null; ExecutionStackRecord.Op[] record = EvaluationStackRec.record.ToArray(); var ltype = EvaluationStackRec.GetLastRecordType(); if (ltype == ExecutionStackRecord.OpType.Push) { result = EvaluationStackRec.PeekWithoutLog(); } else if (ltype == ExecutionStackRecord.OpType.Insert) { result = EvaluationStackRec.PeekWithoutLog(EvaluationStackRec.record.Last().ind); } else if (ltype == ExecutionStackRecord.OpType.Set) { result = EvaluationStackRec.PeekWithoutLog(EvaluationStackRec.record.Last().ind); } else if (ltype == ExecutionStackRecord.OpType.Peek) { result = EvaluationStackRec.PeekWithoutLog(); } LogResult(nextOpcode, record, result); } } } catch { State |= VMState.FAULT; return(false); } if (DumpInfo != null) { DumpInfo.Finish(State); } return(!State.HasFlag(VMState.FAULT)); }