コード例 #1
0
        private void OnGetBlocksMessageReceived(GetBlocksPayload payload)
        {
            if (!localNode.ServiceEnabled)
            {
                return;
            }

            BlockchainBase Chain = BlockchainBase.GetBlockchain(payload.ChainHash);

            if (Chain == null)
            {
                return;
            }

            UInt256 hash = payload.HashStart.Select(p => Chain.GetHeader(p)).Where(p => p != null).OrderBy(p => p.Index).Select(p => p.Hash).FirstOrDefault();

            if (hash == null || hash == payload.HashStop)
            {
                return;
            }
            List <UInt256> hashes = new List <UInt256>();

            do
            {
                hash = Chain.GetNextBlockHash(hash);
                if (hash == null)
                {
                    break;
                }
                hashes.Add(hash);
            } while (hash != payload.HashStop && hashes.Count < 500);
            if (hashes.Count > 0)
            {
                EnqueueMessage("inv", InvPayload.Create(InventoryType.Block, hashes.ToArray()));
            }
        }