예제 #1
0
 private void RemoteNode_InventoryReceived(object sender, IInventory inventory)
 {
     if (inventory is Transaction)
     {
         if (Blockchain.Default == null)
         {
             return;
         }
         lock (KnownHashes)
         {
             if (!KnownHashes.Add(inventory.Hash))
             {
                 return;
             }
         }
         InventoryReceivingEventArgs args = new InventoryReceivingEventArgs(inventory);
         InventoryReceiving?.Invoke(this, args);
         if (args.Cancel)
         {
             return;
         }
         lock (temp_pool)
         {
             temp_pool.Add((Transaction)inventory);
         }
         new_tx_event.Set();
     }
     else
     {
         Relay(inventory);
     }
 }
예제 #2
0
        public bool Relay(IInventory inventory)
        {
            if (inventory is MinerTransaction)
            {
                return(false);
            }
            lock (KnownHashes)
            {
                if (!KnownHashes.Add(inventory.Hash))
                {
                    return(false);
                }
            }
            InventoryReceivingEventArgs args = new InventoryReceivingEventArgs(inventory);

            InventoryReceiving?.Invoke(this, args);
            if (args.Cancel)
            {
                return(false);
            }
            if (inventory is Block)
            {
                if (Blockchain.Default == null)
                {
                    return(false);
                }
                Block block = (Block)inventory;
                if (Blockchain.Default.ContainsBlock(block.Hash))
                {
                    return(false);
                }
                if (!Blockchain.Default.AddBlock(block))
                {
                    return(false);
                }
            }
            else if (inventory is Transaction)
            {
                if (!AddTransaction((Transaction)inventory))
                {
                    return(false);
                }
            }
            else //if (inventory is Consensus)
            {
                if (!inventory.Verify())
                {
                    return(false);
                }
            }
            bool relayed = RelayDirectly(inventory);

            InventoryReceived?.Invoke(this, inventory);
            return(relayed);
        }