예제 #1
0
 private void ProcessInvPayload(InvPayload invPayload)
 {
     // if node has transaction we broadcast
     foreach (InventoryVector inv in invPayload.Inventory.Where(x => x.Type == InventoryType.MSG_TX))
     {
         TransactionBroadcastEntry txEntry = this.broadcasterManager.GetTransaction(inv.Hash);
         if (txEntry != null)
         {
             this.broadcasterManager.AddOrUpdate(txEntry.Transaction, TransactionBroadcastState.Propagated);
         }
     }
 }
        /// <summary>Adds or updates a transaction from the collection of transactions to broadcast.</summary>
        public void AddOrUpdate(Transaction transaction, TransactionBroadcastState transactionBroadcastState, MempoolError mempoolError = null)
        {
            TransactionBroadcastEntry broadcastEntry = this.Broadcasts.FirstOrDefault(x => x.Transaction.GetHash() == transaction.GetHash());

            if (broadcastEntry == null)
            {
                broadcastEntry = new TransactionBroadcastEntry(transaction, transactionBroadcastState, mempoolError);
                this.Broadcasts.Add(broadcastEntry);
                this.OnTransactionStateChanged(broadcastEntry);
            }
            else if (broadcastEntry.TransactionBroadcastState != transactionBroadcastState)
            {
                broadcastEntry.TransactionBroadcastState = transactionBroadcastState;
                this.OnTransactionStateChanged(broadcastEntry);
            }
        }
예제 #3
0
        protected async Task ProcessGetDataPayloadAsync(INetworkPeer peer, GetDataPayload getDataPayload)
        {
            // If node asks for transaction we want to broadcast.
            foreach (InventoryVector inv in getDataPayload.Inventory.Where(x => x.Type == InventoryType.MSG_TX))
            {
                TransactionBroadcastEntry txEntry = this.broadcasterManager.GetTransaction(inv.Hash);
                if ((txEntry != null) && (txEntry.TransactionBroadcastState != TransactionBroadcastState.CantBroadcast))
                {
                    await peer.SendMessageAsync(new TxPayload(txEntry.Transaction)).ConfigureAwait(false);

                    if (txEntry.TransactionBroadcastState == TransactionBroadcastState.ToBroadcast)
                    {
                        this.broadcasterManager.AddOrUpdate(txEntry.Transaction, TransactionBroadcastState.Broadcasted);
                    }
                }
            }
        }
        /// <summary>Checks if transaction was propagated to any peers on the network.</summary>
        protected bool IsPropagated(Transaction transaction)
        {
            TransactionBroadcastEntry broadcastEntry = this.GetTransaction(transaction.GetHash());

            return((broadcastEntry != null) && (broadcastEntry.TransactionBroadcastState == TransactionBroadcastState.Propagated));
        }
        /// <summary>Retrieves a transaction with provided hash from the collection of transactions to broadcast.</summary>
        /// <param name="transactionHash">Hash of the transaction to retrieve.</param>
        public TransactionBroadcastEntry GetTransaction(uint256 transactionHash)
        {
            TransactionBroadcastEntry txEntry = this.Broadcasts.FirstOrDefault(x => x.Transaction.GetHash() == transactionHash);

            return(txEntry ?? null);
        }
 public void OnTransactionStateChanged(TransactionBroadcastEntry entry)
 {
     this.TransactionStateChanged?.Invoke(this, entry);
 }