コード例 #1
0
        private void ConfirmEnoughEstimate(Transaction tx, Block block, long estimate)
        {
            CallOutputTracer outputTracer = new CallOutputTracer();

            tx.GasLimit = estimate;
            TestContext.WriteLine(tx.GasLimit);

            GethLikeTxTracer gethTracer = new GethLikeTxTracer(GethTraceOptions.Default);

            _transactionProcessor.CallAndRestore(tx, block.Header, gethTracer);
            string traceEnoughGas = new EthereumJsonSerializer().Serialize(gethTracer.BuildResult(), true);

            _transactionProcessor.CallAndRestore(tx, block.Header, outputTracer);
            traceEnoughGas.Should().NotContain("OutOfGas");

            outputTracer = new CallOutputTracer();
            tx.GasLimit  = Math.Min(estimate - 1, estimate * 63 / 64);
            TestContext.WriteLine(tx.GasLimit);

            gethTracer = new GethLikeTxTracer(GethTraceOptions.Default);
            _transactionProcessor.CallAndRestore(tx, block.Header, gethTracer);

            string traceOutOfGas = new EthereumJsonSerializer().Serialize(gethTracer.BuildResult(), true);

            TestContext.WriteLine(traceOutOfGas);

            _transactionProcessor.CallAndRestore(tx, block.Header, outputTracer);

            bool failed = traceEnoughGas.Contains("failed") || traceEnoughGas.Contains("OutOfGas");

            failed.Should().BeTrue();
        }
コード例 #2
0
        public static string TestSerializedRequest <T>(IReadOnlyCollection <JsonConverter> converters, T module, string method, params string[] parameters) where T : class, IModule
        {
            IJsonRpcService        service    = BuildRpcService(module);
            JsonRpcRequest         request    = GetJsonRequest(method, parameters);
            JsonRpcResponse        response   = service.SendRequestAsync(request).Result;
            EthereumJsonSerializer serializer = new EthereumJsonSerializer();

            foreach (JsonConverter converter in converters)
            {
                serializer.RegisterConverter(converter);
            }

            Stream stream = new MemoryStream();

            serializer.Serialize(stream, response);

            // for coverage (and to prove that it does not throw
            Stream indentedStream = new MemoryStream();

            serializer.Serialize(indentedStream, response, true);

            stream.Seek(0, SeekOrigin.Begin);
            string serialized = new StreamReader(stream).ReadToEnd();

            TestContext.Out?.WriteLine("Serialized:");
            TestContext.Out?.WriteLine(serialized);
            return(serialized);
        }
コード例 #3
0
ファイル: StartRpc.cs プロジェクト: sandakersmann/nethermind
        private IJsonSerializer CreateJsonSerializer(JsonRpcService jsonRpcService)
        {
            IJsonSerializer serializer = new EthereumJsonSerializer();

            serializer.RegisterConverters(jsonRpcService.Converters);
            return(serializer);
        }
コード例 #4
0
ファイル: KeyStoreTests.cs プロジェクト: prestwich/nethermind
        public void Same_storage_format_as_in_geth(string keyJson)
        {
            EthereumJsonSerializer serializer = new EthereumJsonSerializer();
            KeyStoreItem           item       = serializer.Deserialize <KeyStoreItem>(keyJson);

            SecureString securePassword = new SecureString();
            string       password       = "******";

            for (int i = 0; i < password.Length; i++)
            {
                securePassword.AppendChar(password[i]);
            }

            Address address = new Address(item.Address);

            _store.StoreKey(address, item);

            try
            {
                string[] files = _store.FindKeyFiles(address);
                Assert.AreEqual(1, files.Length);
                string text = File.ReadAllText(files[0]);
                Assert.AreEqual(keyJson, text, "same json");
            }
            finally
            {
                _store.DeleteKey(new Address(item.Address));
            }
        }
コード例 #5
0
        public void RunMigration(int?migratedBlockNumber)
        {
            int                    chainLength             = 10;
            IConfigProvider        configProvider          = Substitute.For <IConfigProvider>();
            BlockTreeBuilder       blockTreeBuilder        = Core.Test.Builders.Build.A.BlockTree().OfChainLength(chainLength);
            InMemoryReceiptStorage inMemoryReceiptStorage  = new() { MigratedBlockNumber = migratedBlockNumber != null ? 0 : long.MaxValue };
            InMemoryReceiptStorage outMemoryReceiptStorage = new() { MigratedBlockNumber = migratedBlockNumber != null ? 0 : long.MaxValue };
            NethermindApi          context = new()
            {
                ConfigProvider         = configProvider,
                EthereumJsonSerializer = new EthereumJsonSerializer(),
                LogManager             = LimboLogs.Instance,
                ReceiptStorage         = new TestReceiptStorage(inMemoryReceiptStorage, outMemoryReceiptStorage),
                DbProvider             = Substitute.For <IDbProvider>(),
                BlockTree                = blockTreeBuilder.TestObject,
                Synchronizer             = Substitute.For <ISynchronizer>(),
                ChainLevelInfoRepository = blockTreeBuilder.ChainLevelInfoRepository,
                SyncModeSelector         = Substitute.For <ISyncModeSelector>()
            };

            configProvider.GetConfig <IInitConfig>().StoreReceipts.Returns(true);
            configProvider.GetConfig <IInitConfig>().ReceiptsMigration.Returns(true);
            context.SyncModeSelector.Current.Returns(SyncMode.WaitingForBlock);

            int txIndex = 0;

            for (int i = 1; i < chainLength; i++)
            {
                Block block = context.BlockTree.FindBlock(i);
                inMemoryReceiptStorage.Insert(block, new[] {
                    Core.Test.Builders.Build.A.Receipt.WithTransactionHash(TestItem.Keccaks[txIndex++]).TestObject,
                    Core.Test.Builders.Build.A.Receipt.WithTransactionHash(TestItem.Keccaks[txIndex++]).TestObject
                });
            }

            ManualResetEvent guard           = new(false);
            Keccak           lastTransaction = TestItem.Keccaks[txIndex - 1];

            context.DbProvider.ReceiptsDb.When(x => x.Remove(lastTransaction.Bytes)).Do(c => guard.Set());
            ReceiptMigration migration = new(context);

            if (migratedBlockNumber.HasValue)
            {
                migration.Run(migratedBlockNumber.Value);
            }
            else
            {
                migration.Run();
            }


            guard.WaitOne(TimeSpan.FromSeconds(1));
            int txCount = ((migratedBlockNumber ?? chainLength) - 1 - 1) * 2;

            context.DbProvider.ReceiptsDb.Received(Quantity.Exactly(txCount)).Remove(Arg.Any <byte[]>());
            outMemoryReceiptStorage.Count.Should().Be(txCount);
        }

        private class TestReceiptStorage : IReceiptStorage
        {
コード例 #6
0
ファイル: KeyStoreTests.cs プロジェクト: prestwich/nethermind
        public void Can_unlock_test_accounts(string keyJson)
        {
            EthereumJsonSerializer serializer = new EthereumJsonSerializer();
            KeyStoreItem           item       = serializer.Deserialize <KeyStoreItem>(keyJson);

            SecureString securePassword = new SecureString();
            string       password       = "******";

            for (int i = 0; i < password.Length; i++)
            {
                securePassword.AppendChar(password[i]);
            }

            securePassword.MakeReadOnly();

            _store.StoreKey(new Address(item.Address), item);
            try
            {
                (PrivateKey key, Result result) = _store.GetKey(new Address(item.Address), securePassword);
                Assert.AreEqual(ResultType.Success, result.ResultType, item.Address + " " + result.Error);
                Assert.AreEqual(key.Address.ToString(false, false), item.Address);
            }
            finally
            {
                _store.DeleteKey(new Address(item.Address));
            }
        }
コード例 #7
0
        public void Can_call_by_hash_canonical()
        {
            Block lastHead       = _blockTree.Head;
            Block block          = Build.A.Block.WithParent(lastHead).TestObject;
            Block newBlockOnMain = Build.A.Block.WithParent(lastHead).WithDifficulty(block.Difficulty + 1).TestObject;

            BlockTreeBuilder.AddBlock(_blockTree, block);
            BlockTreeBuilder.AddBlock(_blockTree, newBlockOnMain);

            // would need to setup state root somehow...

            TransactionForRpc tx = new TransactionForRpc
            {
                From     = TestItem.AddressA,
                To       = TestItem.AddressB,
                GasPrice = _useNonZeroGasPrice ? 10.GWei() : 0
            };

            EthereumJsonSerializer serializer = new EthereumJsonSerializer();
            string response = RpcTest.TestSerializedRequest(_proofModule, "proof_call", $"{serializer.Serialize(tx)}", $"{{\"blockHash\" : \"{block.Hash}\", \"requireCanonical\" : true}}");

            Assert.True(response.Contains("-32000"));

            response = RpcTest.TestSerializedRequest(_proofModule, "proof_call", $"{serializer.Serialize(tx)}", $"{{\"blockHash\" : \"{TestItem.KeccakG}\", \"requireCanonical\" : true}}");
            Assert.True(response.Contains("-32001"));
        }
コード例 #8
0
        private void LogDiagnosticTrace(IBlockTracer blockTracer)
        {
            GethLikeBlockTracer   gethTracer   = blockTracer as GethLikeBlockTracer;
            ParityLikeBlockTracer parityTracer = blockTracer as ParityLikeBlockTracer;

            if (gethTracer != null)
            {
                var serializer = new EthereumJsonSerializer();
                var trace      = gethTracer.BuildResult();
                var serialized = serializer.Serialize(trace, true);
                if (_logger.IsInfo)
                {
                    _logger.Info(serialized);
                }
            }

            if (parityTracer != null)
            {
                var serializer = new EthereumJsonSerializer();
                var trace      = parityTracer.BuildResult();
                var serialized = serializer.Serialize(trace, true);
                if (_logger.IsInfo)
                {
                    _logger.Info(serialized);
                }
            }
        }
コード例 #9
0
        private void LogDiagnosticTrace(IBlockTracer blockTracer, Block block)
        {
            FileStream GetDiagnosticFile() => new FileStream($"trace_{block}.txt", FileMode.Create, FileAccess.Write);

            GethLikeBlockTracer   gethTracer   = blockTracer as GethLikeBlockTracer;
            ParityLikeBlockTracer parityTracer = blockTracer as ParityLikeBlockTracer;

            if (gethTracer != null)
            {
                using var diagnosticFile = GetDiagnosticFile();
                var serializer = new EthereumJsonSerializer();
                var trace      = gethTracer.BuildResult();
                serializer.Serialize(diagnosticFile, trace, true);
                if (_logger.IsInfo)
                {
                    _logger.Info($"Created trace of block {block} in file {diagnosticFile.Name}");
                }
            }

            if (parityTracer != null)
            {
                using var diagnosticFile = GetDiagnosticFile();
                var serializer = new EthereumJsonSerializer();
                var trace      = parityTracer.BuildResult();
                serializer.Serialize(diagnosticFile, trace, true);
                if (_logger.IsInfo)
                {
                    _logger.Info($"Created trace of block {block} in file {diagnosticFile.Name}");
                }
            }
        }
コード例 #10
0
        public void Can_call_by_hash()
        {
            StateProvider stateProvider = CreateInitialState(null);

            Keccak root  = stateProvider.StateRoot;
            Block  block = Build.A.Block.WithParent(_blockTree.Head).WithStateRoot(root).TestObject;

            BlockTreeBuilder.AddBlock(_blockTree, block);

            // would need to setup state root somehow...

            TransactionForRpc tx = new TransactionForRpc
            {
                From     = TestItem.AddressA,
                To       = TestItem.AddressB,
                GasPrice = _useNonZeroGasPrice ? 10.GWei() : 0
            };

            _proofModule.proof_call(tx, new BlockParameter(block.Hash));

            EthereumJsonSerializer serializer = new EthereumJsonSerializer();
            string response = RpcTest.TestSerializedRequest(_proofModule, "proof_call", $"{serializer.Serialize(tx)}", $"{block.Hash}");

            Assert.True(response.Contains("\"result\""));
        }
コード例 #11
0
ファイル: RunnerAppBase.cs プロジェクト: prestwich/nethermind
        public Task Run(string[] args)
        {
            (CommandLineApplication app, var buildConfigProvider, var getDbBasePath) = BuildCommandLineApp();

            ManualResetEventSlim appClosed = new ManualResetEventSlim(true);

            app.OnExecute(async() =>
            {
                appClosed.Reset();
                IConfigProvider configProvider = buildConfigProvider();
                IInitConfig initConfig         = configProvider.GetConfig <IInitConfig>();
                _logger = new NLogLogger(initConfig.LogFileName, initConfig.LogDirectory);
                if (_logger.IsDebug)
                {
                    _logger.Debug($"Nethermind version: {ClientVersion.Description}");
                }
                LogMemoryConfiguration();

                string?pathDbPath = getDbBasePath();
                if (!string.IsNullOrWhiteSpace(pathDbPath))
                {
                    string newDbPath = Path.Combine(pathDbPath, initConfig.BaseDbPath);
                    if (_logger.IsDebug)
                    {
                        _logger.Debug(
                            $"Adding prefix to baseDbPath, new value: {newDbPath}, old value: {initConfig.BaseDbPath}");
                    }
                    initConfig.BaseDbPath =
                        newDbPath ?? Path.Combine(AppDomain.CurrentDomain.BaseDirectory ?? "", "db");
                }

                Console.Title           = initConfig.LogFileName;
                Console.CancelKeyPress += ConsoleOnCancelKeyPress;

                EthereumJsonSerializer serializer = new EthereumJsonSerializer();
                if (_logger.IsDebug)
                {
                    _logger.Debug($"Nethermind config:\n{serializer.Serialize(initConfig, true)}\n");
                }

                _processExit     = new TaskCompletionSource <object?>();
                _cancelKeySource = new TaskCompletionSource <object?>();

                await StartRunners(_processCloseCancellationSource.Token, configProvider);

                await Task.WhenAny(_cancelKeySource.Task, _processExit.Task);

                Console.WriteLine("Closing, please wait until all functions are stopped properly...");
                StopAsync().Wait();
                Console.WriteLine("All done, goodbye!");
                appClosed.Set();

                return(0);
            });

            app.Execute(args);
            appClosed.Wait();
            return(Task.CompletedTask);
        }
コード例 #12
0
        public Scenario(string jsonRpcUrl)
        {
            var logsManager = LimboLogs.Instance;
            var serializer  = new EthereumJsonSerializer();

            _client = new JsonRpcClientProxy(new DefaultHttpClient(new HttpClient(), serializer, logsManager, 0),
                                             new[] { jsonRpcUrl }, logsManager);
        }
コード例 #13
0
        public void Can_Run_Smoke_test()
        {
            var code       = Bytes.FromHexString("0x600060000100");
            var txTracer   = RunVirtualMachine(code);
            var serializer = new EthereumJsonSerializer();
            var trace      = txTracer.BuildResult();

            _testOutputHelper.WriteLine(serializer.Serialize(trace, true));
        }
コード例 #14
0
        private static IJsonSerializer BuildSerializer()
        {
            IJsonSerializer serializer = new EthereumJsonSerializer();

            serializer.RegisterConverters(EthModuleFactory.Converters);
            serializer.RegisterConverters(TraceModuleFactory.Converters);
            serializer.RegisterConverter(new BlockParameterConverter());
            return(serializer);
        }
コード例 #15
0
 public void CanHandleOptionalArguments()
 {
     EthereumJsonSerializer serializer = new EthereumJsonSerializer();
     string serialized = serializer.Serialize(new TransactionForRpc());
     IEthRpcModule ethRpcModule = Substitute.For<IEthRpcModule>();
     ethRpcModule.eth_call(Arg.Any<TransactionForRpc>()).ReturnsForAnyArgs(x => ResultWrapper<string>.Success("0x1"));
     JsonRpcSuccessResponse response = TestRequest(ethRpcModule, "eth_call", serialized) as JsonRpcSuccessResponse;
     Assert.AreEqual("0x1", response?.Result);
 }
コード例 #16
0
        public void Can_Run_Smoke_test()
        {
            var code = Bytes.FromHexString("0x600060000100");
            GethLikeTxTracer       txTracer   = RunVirtualMachine(code);
            EthereumJsonSerializer serializer = new EthereumJsonSerializer();
            GethLikeTxTrace        trace      = txTracer.BuildResult();

            TestContext.WriteLine(serializer.Serialize(trace, true));
        }
コード例 #17
0
        private IJsonSerializer GetSerializer(IEnumerable <JsonConverter> additionalConverters)
        {
            IJsonSerializer jsonSerializer = new EthereumJsonSerializer();

            if (additionalConverters != null)
            {
                jsonSerializer.RegisterConverters(additionalConverters);
            }

            return(jsonSerializer);
        }
コード例 #18
0
        public void CanHandleOptionalArguments()
        {
            EthereumJsonSerializer serializer = new EthereumJsonSerializer();
            string     serialized             = serializer.Serialize(new TransactionForRpc());
            IEthModule ethModule = Substitute.For <IEthModule>();

            ethModule.eth_call(Arg.Any <TransactionForRpc>()).ReturnsForAnyArgs(x => ResultWrapper <byte[]> .Success(new byte[] { 1 }));
            JsonRpcResponse response = TestRequest <IEthModule>(ethModule, "eth_call", serialized);

            Assert.AreEqual(1, (response.Result as byte[]).Length);
        }
コード例 #19
0
        public void Can_Invoke_Gas_Limit()
        {
            var code       = Bytes.FromHexString("0x4500");
            var txTracer   = RunVirtualMachine(code);
            var serializer = new EthereumJsonSerializer();
            var trace      = txTracer.BuildResult();

            _testOutputHelper.WriteLine(serializer.Serialize(trace, true));
            trace.Failed.Should().Be(false);
            trace.Entries.Last().Stack.Count.Should().Be(1);
            trace.Entries.Last().Stack.Last().Should().Be("f4240".PadLeft(64, '0'));
        }
コード例 #20
0
        public void Can_Invoke_Range_Proof_Precompile()
        {
            var code       = Bytes.FromHexString("0x60008080806201000062050000F400");
            var txTracer   = RunVirtualMachine(code);
            var serializer = new EthereumJsonSerializer();
            var trace      = txTracer.BuildResult();

            _testOutputHelper.WriteLine(serializer.Serialize(trace, true));
            trace.Failed.Should().Be(false);
            trace.Entries.Last().Stack.Count.Should().Be(1);
            trace.Entries.Last().Stack.Last().Should().Be(VirtualMachine.BytesOne32.ToHexString());
        }
コード例 #21
0
        public void Can_Invoke_Address()
        {
            var code       = Bytes.FromHexString("0x3000");
            var txTracer   = RunVirtualMachine(code);
            var serializer = new EthereumJsonSerializer();
            var trace      = txTracer.BuildResult();

            _testOutputHelper.WriteLine(serializer.Serialize(trace, true));
            trace.Failed.Should().Be(false);
            trace.Entries.Last().Stack.Count.Should().Be(1);
            trace.Entries.Last().Stack.Last().Should().Be(VirtualMachine.BytesZero32.ToHexString());
        }
コード例 #22
0
        public void Can_Invoke_Origin()
        {
            var code = Bytes.FromHexString("0x3200");
            GethLikeTxTracer       txTracer   = RunVirtualMachine(code);
            EthereumJsonSerializer serializer = new EthereumJsonSerializer();
            GethLikeTxTrace        trace      = txTracer.BuildResult();

            TestContext.WriteLine(serializer.Serialize(trace, true));
            trace.Failed.Should().Be(false);
            trace.Entries.Last().Stack.Count.Should().Be(1);
            trace.Entries.Last().Stack.Last().Should().Be(VirtualMachine.BytesZero32.ToHexString());
        }
コード例 #23
0
        public void Blake_precompile()
        {
            Address                blakeAddress = Address.FromNumber(1 + KatVirtualMachine.CatalystPrecompilesAddressingSpace);
            string                 addressCode  = blakeAddress.Bytes.ToHexString(false);
            var                    code         = Bytes.FromHexString("0x602060006080600073" + addressCode + "45fa00");
            GethLikeTxTracer       txTracer     = RunVirtualMachine(code);
            EthereumJsonSerializer serializer   = new EthereumJsonSerializer();
            GethLikeTxTrace        trace        = txTracer.BuildResult();

            TestContext.WriteLine(serializer.Serialize(trace, true));
            trace.Entries.Last().Stack.First().Should().Be("0000000000000000000000000000000000000000000000000000000000000001");
            trace.Entries.Last().Memory.First().Should().Be("378d0caaaa3855f1b38693c1d6ef004fd118691c95c959d4efa950d6d6fcf7c1");
        }
コード例 #24
0
        private void TestToJson <T>(T item, JsonConverter <T> converter, string expectedResult)
        {
            EthereumJsonSerializer serializer = BuildSerializer();

            if (converter != null)
            {
                serializer.RegisterConverter(converter);
            }

            string result = serializer.Serialize(item);

            Assert.AreEqual(expectedResult, result, result.Replace("\"", "\\\""));
        }
コード例 #25
0
        public void Setup()
        {
            _serializer    = new EthereumJsonSerializer();
            _jsonRpcClient = Substitute.For <IJsonRpcClient>();
            _engine        = new CliEngine(_cliConsole);
            NodeManager nodeManager = new NodeManager(_engine, _serializer, _cliConsole, LimboLogs.Instance);

            nodeManager.SwitchClient(_jsonRpcClient);
            ICliConsole     cliConsole   = Substitute.For <ICliConsole>();
            CliModuleLoader moduleLoader = new CliModuleLoader(_engine, nodeManager, cliConsole);

            moduleLoader.LoadModule(typeof(ProofCliModule));
        }
コード例 #26
0
ファイル: RunnerAppBase.cs プロジェクト: fosfuan/nethermind
        public void Run(string[] args)
        {
            var(app, buildConfigProvider, getDbBasePath) = BuildCommandLineApp();
            ManualResetEventSlim appClosed = new ManualResetEventSlim(true);

            app.OnExecute(async() =>
            {
                appClosed.Reset();
                var configProvider       = buildConfigProvider();
                var initConfig           = configProvider.GetConfig <IInitConfig>();
                LogManager.Configuration = new XmlLoggingConfiguration("NLog.config".GetApplicationResourcePath());
                _logger = new NLogLogger(initConfig.LogFileName, initConfig.LogDirectory);
                LogMemoryConfiguration();

                var pathDbPath = getDbBasePath();
                if (!string.IsNullOrWhiteSpace(pathDbPath))
                {
                    var newDbPath = Path.Combine(pathDbPath, initConfig.BaseDbPath);
                    if (_logger.IsDebug)
                    {
                        _logger.Debug($"Adding prefix to baseDbPath, new value: {newDbPath}, old value: {initConfig.BaseDbPath}");
                    }
                    initConfig.BaseDbPath = newDbPath ?? Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "db");
                }

                Console.Title           = initConfig.LogFileName;
                Console.CancelKeyPress += ConsoleOnCancelKeyPress;

                var serializer = new EthereumJsonSerializer();
                if (_logger.IsInfo)
                {
                    _logger.Info($"Nethermind config:\n{serializer.Serialize(initConfig, true)}\n");
                }

                _cancelKeySource = new TaskCompletionSource <object>();

                await StartRunners(configProvider);
                await _cancelKeySource.Task;

                Console.WriteLine("Closing, please wait until all functions are stopped properly...");
                StopAsync().Wait();
                Console.WriteLine("All done, goodbye!");
                appClosed.Set();

                return(0);
            });

            app.Execute(args);
            appClosed.Wait();
        }
コード例 #27
0
        protected void TestRoundtrip <T>(string json, JsonConverter converter = null)
        {
            EthereumJsonSerializer serializer = BuildSerializer();

            if (converter != null)
            {
                serializer.RegisterConverter(converter);
            }

            T      deserialized = serializer.Deserialize <T>(json);
            string result       = serializer.Serialize(deserialized);

            Assert.AreEqual(json, result);
        }
コード例 #28
0
        public void Setup()
        {
            _blockTree     = Build.A.BlockTree().OfChainLength(5).TestObject;
            _networkConfig = new NetworkConfig();
            IPeerManager peerManager = Substitute.For <IPeerManager>();

            peerManager.ActivePeers.Returns(new List <Peer> {
                new Peer(new Node("127.0.0.1", 30303, true))
            });

            IStaticNodesManager staticNodesManager = Substitute.For <IStaticNodesManager>();
            Enode enode = new Enode(_enodeString);

            _adminRpcModule = new AdminRpcModule(_blockTree, _networkConfig, peerManager, staticNodesManager, enode, _exampleDataDir);
            _serializer     = new EthereumJsonSerializer();
        }
コード例 #29
0
ファイル: PeersApp.cs プロジェクト: uzbekdev1/nethermind
        public PeersApp() : base("Peers")
        {
            string[] urls = { DefaultUrl };

            var logger            = LimboLogs.Instance;
            var serializer        = new EthereumJsonSerializer();
            var httpClient        = new HttpClient();
            var defaultHttpClient = new DefaultHttpClient(httpClient, serializer, logger, int.MaxValue);
            var proxy             = new JsonRpcClientProxy(defaultHttpClient, urls, logger);

            _adminRpc = new AdminJsonRpcClientProxy(proxy);

            MenuBar menu = new MenuBar(new MenuBarItem[]
            {
                new MenuBarItem("_File", new MenuItem[]
                {
                    new MenuItem("_Quit", "", () => { Application.RequestStop(); })
                }),
            });

            ListView view = new ListView()
            {
                X      = 0,
                Y      = 1,
                Width  = Dim.Fill(),
                Height = Dim.Fill() - 1,
            };

            view.AllowsAll();

            Add(menu, view);

            bool UpdateTimer(MainLoop mainLoop)
            {
                _adminRpc.admin_peers(true).ContinueWith(
                    t => Application.MainLoop.Invoke(() =>
                {
                    Title = $"Last Peers Update {DateTime.Now}";
                    view.SetSourceAsync(t.Result.Result.Select(ToPeerInfoRow).OrderByDescending(r => r.Reputation).ToArray());
                })
                    );

                return(true);
            }

            var token = Application.MainLoop.AddTimeout(TimeSpan.FromSeconds(10), UpdateTimer);
        }
コード例 #30
0
        public void Init(string path)
        {
            var dbOnTheRocks = new BlocksRocksDb(path, new DbConfig(), LimboLogs.Instance);
            var blocksBytes  = dbOnTheRocks.GetAll();
            var blockDecoder = new BlockDecoder();
            var blocks       = blocksBytes
                               .Select(b => blockDecoder.Decode(b.Value.AsRlpStream()))
                               .OrderBy(b => b.Number)
                               .ToList();

            var window = new Window("Blocks")
            {
                X = 0, Y = 10, Width = Dim.Fill(), Height = Dim.Fill()
            };

            if (!blocks.Any())
            {
                MessageBox.Query(40, 7, "Info", "No data.");
                window.FocusPrev();
                return;
            }

            var y = 1;

            foreach (var block in blocks)
            {
                var blockBtn = new Button(1, y++, $"Number: {block.Number}, Hash: {block.Hash}");


                blockBtn.Clicked = () =>
                {
                    var blockDetailsWindow = new Window("Block details")
                    {
                        X = 0, Y = 10, Width = Dim.Fill(), Height = Dim.Fill()
                    };
                    Application.Top.Add(blockDetailsWindow);
                    var serializer = new EthereumJsonSerializer();
                    var blockLbl   = new Label(1, 1, serializer.Serialize(block, true));
                    blockDetailsWindow.Add(blockLbl);
                    Application.Run(blockDetailsWindow);
                };
                window.Add(blockBtn);
            }

            Application.Top.Add(window);
            Application.Run(window);
        }