Пример #1
0
        public void TestRpcGetBlockCount()
        {
            using (var simulator = new MainnetSimulator())
            {
                var logger = LogManager.GetCurrentClassLogger();
                int port = FindFreePort();
                using (var rpcServer = new CoreRpcServer(simulator.CoreDaemon, port))
                {
                    rpcServer.StartListening();

                    var block9 = simulator.BlockProvider.GetBlock(9);

                    simulator.AddBlockRange(0, 9);
                    simulator.WaitForUpdate();
                    simulator.AssertAtBlock(9, block9.Hash);

                    var jsonRequestId = Guid.NewGuid().ToString();
                    var jsonRequest = JsonConvert.SerializeObject(
                        new JsonRpcRequest
                        {
                            method = "getblockcount",
                            @params = new string[0],
                            id = jsonRequestId
                        });
                    var jsonRequestBytes = Encoding.UTF8.GetBytes(jsonRequest);

                    var request = (HttpWebRequest)WebRequest.Create($"http://localhost:{port}");
                    request.Method = WebRequestMethods.Http.Post;
                    using (var requestStream = request.GetRequestStream())
                    {
                        requestStream.Write(jsonRequestBytes, 0, jsonRequestBytes.Length);
                    }

                    using (var response = request.GetResponse())
                    using (var responseStream = response.GetResponseStream())
                    using (var responseStreamReader = new StreamReader(responseStream, Encoding.UTF8))
                    {
                        var jsonResponseString = responseStreamReader.ReadToEnd();
                        var jsonResponse = JsonConvert.DeserializeObject<JsonRpcResponse>(jsonResponseString);

                        Assert.AreEqual("2.0", jsonResponse.jsonrpc);
                        Assert.AreEqual("9", jsonResponse.result);
                        Assert.AreEqual(jsonRequestId, jsonResponse.id);
                    }
                }
            }
        }
Пример #2
0
 public ListenerWorker(CoreRpcServer rpcServer, Logger logger)
     : base("CoreRpcServer.ListenerWorker", initialNotify: true, minIdleTime: TimeSpan.Zero, maxIdleTime: TimeSpan.Zero, logger: logger)
 {
     this.logger    = logger;
     this.rpcServer = rpcServer;
 }
Пример #3
0
 public ListenerWorker(CoreRpcServer rpcServer, int port)
     : base("CoreRpcServer.ListenerWorker", initialNotify: true, minIdleTime: TimeSpan.Zero, maxIdleTime: TimeSpan.Zero)
 {
     this.rpcServer = rpcServer;
     this.port = port;
 }
Пример #4
0
 public ListenerWorker(CoreRpcServer rpcServer, int port)
     : base("CoreRpcServer.ListenerWorker", initialNotify: true, minIdleTime: TimeSpan.Zero, maxIdleTime: TimeSpan.Zero)
 {
     this.rpcServer = rpcServer;
     this.port      = port;
 }