Beispiel #1
0
 private async Task OnGetHeadersMessageReceivedAsync(GetBlocksPayload payload)
 {
     if (!localNode.ServiceEnabled) return;
     if (Blockchain.Default == null) 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<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));
 }
Beispiel #2
0
 private async Task OnGetBlocksMessageReceivedAsync(GetBlocksPayload payload)
 {
     if (!localNode.ServiceEnabled) return;
     if (Blockchain.Default == null) 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);
     await SendMessageAsync("inv", InvPayload.Create(InventoryType.MSG_BLOCK, hashes.ToArray()));
 }