private void OnGetHeadersMessageReceived(GetBlocksPayload payload) { if (!Blockchain.Default.Ability.HasFlag(BlockchainAbility.BlockIndexes)) return; UInt256 hash = payload.HashStart.Select(p => new { Hash = p, Height = Blockchain.Default.GetBlockHeight(p) }).Where(p => p.Height >= 0).OrderBy(p => p.Height).Select(p => p.Hash).FirstOrDefault(); if (hash == null || hash == payload.HashStop) return; List<BlockHeader> headers = new List<BlockHeader>(); do { hash = Blockchain.Default.GetNextBlockHash(hash); if (hash == null) break; headers.Add(Blockchain.Default.GetHeader(hash)); } while (hash != payload.HashStop && headers.Count < 2000); SendMessage("headers", HeadersPayload.Create(headers)); }
private async Task OnGetHeadersMessageReceivedAsync(GetBlocksPayload payload) { if (!localNode.ServiceEnabled) return; if (Blockchain.Default == null) return; if (!Blockchain.Default.Ability.HasFlag(BlockchainAbility.BlockIndexes)) return; UInt256 hash = payload.HashStart.Select(p => Blockchain.Default.GetHeader(p)).Where(p => p != null).OrderBy(p => p.Height).Select(p => p.Hash).FirstOrDefault(); if (hash == null || hash == payload.HashStop) return; List<Block> headers = new List<Block>(); do { hash = Blockchain.Default.GetNextBlockHash(hash); if (hash == null) break; headers.Add(Blockchain.Default.GetHeader(hash)); } while (hash != payload.HashStop && headers.Count < 2000); await SendMessageAsync("headers", HeadersPayload.Create(headers)); }
private void OnGetBlocksMessageReceived(GetBlocksPayload payload) { if (!Blockchain.Default.Ability.HasFlag(BlockchainAbility.BlockIndexes)) return; UInt256 hash = payload.HashStart.Select(p => new { Hash = p, Height = Blockchain.Default.GetBlockHeight(p) }).Where(p => p.Height >= 0).OrderBy(p => p.Height).Select(p => p.Hash).FirstOrDefault(); if (hash == null || hash == payload.HashStop) return; List<UInt256> hashes = new List<UInt256>(); do { hash = Blockchain.Default.GetNextBlockHash(hash); if (hash == null) break; hashes.Add(hash); } while (hash != payload.HashStop && hashes.Count < 500); SendMessage("inv", InvPayload.Create(InventoryType.Block, hashes.ToArray())); }
private async Task OnGetBlocksMessageReceivedAsync(GetBlocksPayload payload) { if (!localNode.ServiceEnabled) return; if (Blockchain.Default == null) return; if (!Blockchain.Default.Ability.HasFlag(BlockchainAbility.BlockIndexes)) return; UInt256 hash = payload.HashStart.Select(p => Blockchain.Default.GetHeader(p)).Where(p => p != null).OrderBy(p => p.Height).Select(p => p.Hash).FirstOrDefault(); if (hash == null || hash == payload.HashStop) return; List<UInt256> hashes = new List<UInt256>(); do { hash = Blockchain.Default.GetNextBlockHash(hash); if (hash == null) break; hashes.Add(hash); } while (hash != payload.HashStop && hashes.Count < 500); await SendMessageAsync("inv", InvPayload.Create(InventoryType.Block, hashes.ToArray())); }