Ejemplo n.º 1
0
 private void OnGetDataMessageReceived(GetDataPayload payload)
 {
     foreach (InventoryVector vector in payload.Inventories.Distinct())
     {
         Inventory data;
         if (localNode.RelayCache.TryGet(vector.Hash, out data))
         {
             SendMessage(vector.Type.GetCommandName(), data);
             continue;
         }
         switch (vector.Type)
         {
             case InventoryType.Block:
                 {
                     Block block = Blockchain.Default.GetBlock(vector.Hash);
                     if (block != null)
                     {
                         SendMessage("block", block);
                     }
                 }
                 break;
             case InventoryType.TX:
                 {
                     Transaction tx = Blockchain.Default.GetTransaction(vector.Hash);
                     if (tx != null)
                     {
                         SendMessage("tx", tx);
                     }
                 }
                 break;
         }
     }
 }
Ejemplo n.º 2
0
 private async Task OnGetDataMessageReceivedAsync(GetDataPayload payload)
 {
     foreach (InventoryVector vector in payload.Inventories.Distinct())
     {
         Inventory inventory;
         if (!localNode.RelayCache.TryGet(vector.Hash, out inventory) && !localNode.ServiceEnabled)
             continue;
         switch (vector.Type)
         {
             case InventoryType.TX:
                 if (inventory == null && Blockchain.Default != null)
                     inventory = Blockchain.Default.GetTransaction(vector.Hash);
                 if (inventory != null)
                     await SendMessageAsync("tx", inventory);
                 break;
             case InventoryType.Block:
                 if (inventory == null && Blockchain.Default != null)
                     inventory = Blockchain.Default.GetBlock(vector.Hash);
                 if (inventory != null)
                     await SendMessageAsync("block", inventory);
                 break;
         }
     }
 }