public async Task <T> Post <T>(string method, params object[] parameters)
        {
            try
            {
                return(await _currentClient.Post <T>(method, parameters));
            }
            catch (HttpRequestException e)
            {
                CliConsole.WriteErrorLine(e.Message);
            }
            catch (Exception e)
            {
                CliConsole.WriteException(e);
            }

            return(default(T));
        }
Beispiel #2
0
        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"));
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            _cliConsole     = new CliConsole();
            _colorScheme    = new DraculaColorScheme();
            _terminal       = _cliConsole.Init(_colorScheme);
            _logManager     = new OneLoggerLogManager(new CliLogger(_cliConsole));
            _historyManager = new StatementHistoryManager(_cliConsole);

            RegisterConverters();
            InitEngine();
            InitNodeManager();
            LoadCliModules();

            ReadLine.AutoCompletionHandler = new AutoCompletionHandler(ModuleLoader);
            _historyManager.Init();

            TestConnection();
            _cliConsole.WriteLine();

            RunEvalLoop();
        }
Beispiel #4
0
        public JsValue Execute(string statement)
        {
            try
            {
                return(JintEngine.Execute(statement).GetCompletionValue());
            }
            catch (ParserException e)
            {
                CliConsole.WriteErrorLine(e.Message);
            }
            catch (CliArgumentParserException e)
            {
                CliConsole.WriteErrorLine(e.Message);
            }
            catch (Exception e)
            {
                CliConsole.WriteException(e);
            }

            return(JsValue.Null);
        }
Beispiel #5
0
        public async Task <T> Post <T>(string method, params object[] parameters)
        {
            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                T result = await _currentClient.Post <T>(method, parameters);

                stopwatch.Stop();
                Console.WriteLine($"Request complete in {stopwatch.ElapsedMilliseconds}ms");
                return(result);
            }
            catch (HttpRequestException e)
            {
                CliConsole.WriteErrorLine(e.Message);
            }
            catch (Exception e)
            {
                CliConsole.WriteException(e);
            }

            return(default);
Beispiel #6
0
        public async Task <T> Post <T>(string method, params object[] parameters)
        {
            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                T result = await _currentClient.Post <T>(method, parameters);

                stopwatch.Stop();
                decimal totalMicroseconds = stopwatch.ElapsedTicks * (1_000_000m / Stopwatch.Frequency);
                Console.WriteLine($"Request complete in {totalMicroseconds}μs");
                return(result);
            }
            catch (HttpRequestException e)
            {
                CliConsole.WriteErrorLine(e.Message);
            }
            catch (Exception e)
            {
                CliConsole.WriteException(e);
            }

            return(default);
Beispiel #7
0
 public void Warn(string text)
 {
     CliConsole.WriteLessImportant(text);
 }
Beispiel #8
0
        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);
                }
            }
        }