public byte[] GenerateLoaderScriptFromInputs(DataNode inputs) { using (ScriptBuilder sb = new ScriptBuilder()) { var items = new Stack <object>(); if (inputs != null) { foreach (var item in inputs.Children) { var obj = Emulator.ConvertArgument(item); items.Push(obj); } } while (items.Count > 0) { var item = items.Pop(); NeoAPI.EmitObject(sb, item); } var loaderScript = sb.ToArray(); //System.IO.File.WriteAllBytes("loader.avm", loaderScript); return(loaderScript); } }
public byte[] GenerateLoaderScriptFromInputs(DataNode inputs, ABI abi) { var methodName = abi != null && abi.entryPoint != null ? abi.entryPoint.name : null; using (ScriptBuilder sb = new ScriptBuilder()) { var items = new Stack <object>(); if (inputs != null) { AVMFunction method = methodName != null && abi.functions.ContainsKey(methodName) ? abi.functions[methodName] : null; int index = 0; foreach (var item in inputs.Children) { Emulator.Type hint = method != null ? method.inputs[index].type : Emulator.Type.Unknown; var obj = Emulator.ConvertArgument(item, hint); items.Push(obj); index++; } } while (items.Count > 0) { var item = items.Pop(); NeoAPI.EmitObject(sb, item); } var loaderScript = sb.ToArray(); //System.IO.File.WriteAllBytes("loader.avm", loaderScript); return(loaderScript); } }
public void Reset(DataNode inputs, ABI ABI) { if (contractByteCode == null || contractByteCode.Length == 0) { throw new Exception("Contract bytecode is not set yet!"); } 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(contractByteCode); 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 = Emulator.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; _variables.Clear(); this._ABI = ABI; }