Esempio n. 1
0
        public TransactionBroadcastEntry GetTransaction(uint256 transactionHash)
        {
            TransactionBroadcastEntry txEntry = this.Broadcasts.FirstOrDefault(x => x.Transaction.GetHash() == transactionHash);

            if (txEntry == default(TransactionBroadcastEntry))
            {
                return(null);
            }

            return(txEntry);
        }
        public void AddOrUpdate(Transaction transaction, State state)
        {
            TransactionBroadcastEntry broadcastEntry = this.Broadcasts.FirstOrDefault(x => x.Transaction.GetHash() == transaction.GetHash());

            if (broadcastEntry == null)
            {
                broadcastEntry = new TransactionBroadcastEntry(transaction, state);
                this.Broadcasts.Add(broadcastEntry);
                this.OnTransactionStateChanged(broadcastEntry);
            }
            else if (broadcastEntry.State != state)
            {
                broadcastEntry.State = state;
                this.OnTransactionStateChanged(broadcastEntry);
            }
        }
Esempio n. 3
0
        protected async Task ProcessGetDataPayloadAsync(INetworkPeer peer, GetDataPayload getDataPayload)
        {
            // If node asks for tx 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.State != State.CantBroadcast))
                {
                    await peer.SendMessageAsync(new TxPayload(txEntry.Transaction)).ConfigureAwait(false);

                    if (txEntry.State == State.ToBroadcast)
                    {
                        this.broadcasterManager.AddOrUpdate(txEntry.Transaction, State.Broadcasted);
                    }
                }
            }
        }
Esempio n. 4
0
        public void AddOrUpdate(Transaction transaction, State state)
        {
            var newEntry = new TransactionBroadcastEntry(transaction, state);
            TransactionBroadcastEntry oldEntry = this.Broadcasts.FirstOrDefault(x => x.Transaction.GetHash() == transaction.GetHash());

            if (oldEntry == default(TransactionBroadcastEntry))
            {
                this.Broadcasts.Add(newEntry);
                OnTransactionStateChanged(newEntry);
            }
            else
            {
                if (oldEntry.State != state)
                {
                    this.Broadcasts.TryRemove(oldEntry);
                    this.Broadcasts.Add(newEntry);
                    OnTransactionStateChanged(newEntry);
                }
            }
        }
Esempio n. 5
0
 public void OnTransactionStateChanged(TransactionBroadcastEntry entry)
 {
     TransactionStateChanged?.Invoke(this, entry);
 }
        protected bool IsPropagated(Transaction transaction)
        {
            TransactionBroadcastEntry broadcastEntry = this.GetTransaction(transaction.GetHash());

            return(broadcastEntry != null && broadcastEntry.State == State.Propagated);
        }