private static void TestConnection() { _cliConsole.WriteLine($"Connecting to {_nodeManager.CurrentUri}"); JsValue result = _engine.Execute("web3.clientVersion"); if (result != JsValue.Null) { _cliConsole.WriteGood("Connected"); } }
public static void Main() { RegisterConverters(); Engine.JintEngine.SetValue("serialize", new Action <JsValue>(v => { string text = Serializer.Serialize(v.ToObject(), true); CliConsole.WriteGood(text); })); ModuleLoader.DiscoverAndLoadModules(); ReadLine.AutoCompletionHandler = new AutoCompletionHandler(ModuleLoader); NodeManager.SwitchUri(new Uri("http://localhost:8545")); HistoryManager.Init(); TestConnection(); CliConsole.WriteLine(); RunEvalLoop(); }
private static void Test() { CliConsole.WriteLine($"Connecting to {_nodeManager.CurrentUri}"); JsValue result = _engine.Execute("web3.clientVersion"); if (result != JsValue.Null) { CliConsole.WriteGood("Connected"); } // Console.WriteLine(_serializer.Serialize(result.ToObject(), true)); CliConsole.WriteLine(); }
private static void Setup() { Serializer.RegisterConverter(new ParityLikeTxTraceConverter()); Serializer.RegisterConverter(new ParityAccountStateChangeConverter()); Serializer.RegisterConverter(new ParityTraceActionConverter()); Serializer.RegisterConverter(new ParityTraceResultConverter()); Serializer.RegisterConverter(new ParityVmOperationTraceConverter()); Serializer.RegisterConverter(new ParityVmTraceConverter()); _engine = new CliEngine(); _engine.JintEngine.SetValue("serialize", new Action <JsValue>(v => { string text = Serializer.Serialize(v.ToObject(), true); // File.AppendAllText("C:\\temp\\cli.txt", text); CliConsole.WriteGood(text); })); _logManager = new OneLoggerLogManager(new CliLogger()); _nodeManager = new NodeManager(_engine, Serializer, _logManager); _nodeManager.SwitchUri(new Uri("http://localhost:8545")); }
private static void RunEvalLoop() { try { if (File.Exists(HistoryFilePath)) { foreach (string line in File.ReadLines(HistoryFilePath).TakeLast(60)) { if (line != _removedString) { ReadLine.AddHistory(line); } } } } catch (Exception e) { CliConsole.WriteErrorLine($"Could not load cmd history from {HistoryFilePath} {e.Message}"); } ReadLine.AutoCompletionHandler = new AutoCompletionHandler(); while (true) { try { if (_terminal != Terminal.Cmder) { Console.ForegroundColor = ColorScheme.Text; } int bufferSize = 1024 * 16; string statement; using (Stream inStream = System.Console.OpenStandardInput(bufferSize)) { Console.SetIn(new StreamReader(inStream, Console.InputEncoding, false, bufferSize)); CliConsole.WriteLessImportant("nethermind> "); statement = _terminal == Terminal.Cygwin ? Console.ReadLine() : ReadLine.Read(); CleanStatement(statement); if (!File.Exists(HistoryFilePath)) { File.Create(HistoryFilePath).Dispose(); } if (!SecuredCommands.Any(sc => statement.Contains(sc))) { ReadLine.AddHistory(statement); using (var fileStream = File.AppendText(HistoryFilePath)) { fileStream.WriteLine(statement); } } else { ReadLine.AddHistory(_removedString); } } if (statement == "exit") { break; } JsValue result = _engine.Execute(statement); if (result.IsObject() && result.AsObject().Class == "Function") { CliConsole.WriteGood(result.ToString()); CliConsole.WriteLine(); } else if (!result.IsNull()) { string text = Serializer.Serialize(result.ToObject(), true); // File.AppendAllText("C:\\temp\\cli.txt", text); CliConsole.WriteGood(text); } else { CliConsole.WriteLessImportant("null"); CliConsole.WriteLine(); } // bool isNull = result.IsNull(); // if (!isNull) // { // CliConsole.WriteString(result); // } } catch (Exception e) { CliConsole.WriteException(e); } } }