Esempio n. 1
0
 private void RemoteNode_InventoryReceived(object sender, IInventory inventory)
 {
     if (inventory is Transaction tx && tx.Type != TransactionType.ClaimTransaction && tx.Type != TransactionType.IssueTransaction)
     {
         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(tx);
         }
         new_tx_event.Set();
     }
Esempio n. 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);
        }