예제 #1
0
        internal async Task <bool> DownloadCheckPointAsync(uint blockCount)
        {
            {
                uint endBlock      = (blockCount / 100) * 100;
                var  blockResponse = await RequestTransactionBlocksAsync(endBlock, 1);

                var ns = TcpClient.GetStream();
                using (var ms = new MemoryStream())
                {
                    for (uint i = 0; i <= blockResponse.Blocks.Last().BlockNumber / 10000; i++)
                    {
                        CheckPointRequest checkPointRequest =
                            new CheckPointRequest
                        {
                            Operation   = NetOperationType.CheckPoint,
                            RequestType = RequestType.Request,
                            StartBlock  = i * 10000,
                            EndBlock    = ((i + 1) * 10000) - 1
                        };
                        if (checkPointRequest.EndBlock > blockResponse.Blocks.Last().BlockNumber - 1)
                        {
                            checkPointRequest.EndBlock = blockResponse.Blocks.Last().BlockNumber - 1;
                        }
                        checkPointRequest.CheckPointBlockCount = endBlock;
                        checkPointRequest.RequestId            = 12345;
                        checkPointRequest.CheckPointHash       = blockResponse.Blocks.Last().CheckPointHash;
                        using (MemoryStream requestStream = new MemoryStream())
                        {
                            checkPointRequest.SaveToStream(requestStream);
                            requestStream.Position = 0;
                            requestStream.CopyTo(ns);
                            ns.Flush();
                        }
                        WaitForData(10000);
                        Log.Info("Data received");
                        using (var responseStream = new MemoryStream())
                        {
                            var rp = await ReadResponse(responseStream);

                            Log.Info("All Data received");
                            responseStream.Position = 0;
                            CheckPointResponse response = new CheckPointResponse(responseStream);
                        }
                    }
                    return(true);
                }
            }
        }
예제 #2
0
        internal void DownloadCheckPoint(uint blockCount)
        {
            const uint REQUEST_ID = 123456;

            void Handler(object o, BlockResponseEventArgs e)
            {
                if (e.BlockResponse.RequestId == REQUEST_ID)
                {
                    Log.Debug(e.BlockResponse.Blocks.First().BlockNumber);
                    for (uint i = 0; i <= e.BlockResponse.Blocks.Last().BlockNumber / 10000; i++)
                    {
                        CheckPointRequest checkPointRequest =
                            new CheckPointRequest
                        {
                            Operation   = NetOperationType.CheckPoint,
                            RequestType = RequestType.Request,
                            StartBlock  = i * 10000,
                            EndBlock    = ((i + 1) * 10000) - 1
                        };
                        if (checkPointRequest.EndBlock > e.BlockResponse.Blocks.Last().BlockNumber - 1)
                        {
                            checkPointRequest.EndBlock = e.BlockResponse.Blocks.Last().BlockNumber - 1;
                        }
                        checkPointRequest.CheckPointBlockCount = 14700;
                        checkPointRequest.RequestId            = 12345;
                        checkPointRequest.CheckPointHash       = e.BlockResponse.Blocks.Last().CheckPointHash;
                        using (MemoryStream ms = new MemoryStream())
                        {
                            checkPointRequest.SaveToStream(ms);
                            NetworkStream ns = TcpClient.GetStream();
                            ms.Position = 0;
                            ms.CopyTo(ns);
                            ns.Flush();
                        }
                    }
                }
            }

            BlockResponse += Handler;
            RequestBlockChain(blockCount, 1, REQUEST_ID, NetOperationType.Transactions);
        }