private void LocalNode_NewInventory(object sender, Inventory inventory) { if (inventory.InventoryType != InventoryType.ConsRequest) return; BlockConsensusRequest request = (BlockConsensusRequest)inventory; if (request.Verify() != VerificationResult.OK) return; context.AddRequest(request, wallet); }
private void RemoteNode_NewInventory(object sender, Inventory inventory) { lock (KnownHashes) { if (!KnownHashes.Add(inventory.Hash)) return; } VerificationResult vr = inventory.Verify(); if ((vr & ~(VerificationResult.Incapable | VerificationResult.LackOfInformation)) > 0) return; if (inventory.InventoryType == InventoryType.TX && vr.HasFlag(VerificationResult.LackOfInformation)) return; RelayAsync(inventory).Void(); if (NewInventory != null) { NewInventory(this, inventory); } if (inventory.InventoryType == InventoryType.Block && NewBlock != null) { NewBlock(this, (Block)inventory); } if (inventory.InventoryType == InventoryType.TX && NewTransaction != null && vr == VerificationResult.OK) { NewTransaction(this, (Transaction)inventory); } }
public async Task<bool> RelayAsync(Inventory data) { bool unknown; lock (KnownHashes) { unknown = KnownHashes.Add(data.Hash); } if (data.InventoryType == InventoryType.TX && unknown) { Transaction tx = (Transaction)data; if (!Blockchain.Default.ContainsTransaction(tx.Hash) && tx.Verify() == VerificationResult.OK && NewTransaction != null) NewTransaction(this, tx); } if (connectedPeers.Count == 0) return false; RemoteNode[] remoteNodes; lock (connectedPeers) { if (connectedPeers.Count == 0) return false; remoteNodes = connectedPeers.Values.ToArray(); } if (remoteNodes.Length == 0) return false; RelayCache.Add(data); await Task.WhenAny(remoteNodes.Select(p => p.RelayAsync(data))); return true; }
internal async Task RelayAsync(Inventory data) { await SendMessageAsync("inv", InvPayload.Create(data.InventoryType, data.Hash)); }
private void OnNewInventory(Inventory inventory) { if (NewInventory != null) { NewInventory(this, inventory); } }
private void OnInventoryReceived(Inventory inventory) { lock (KnownHashes) { KnownHashes.Add(inventory.Hash); } lock (missions_global) { missions_global.Remove(inventory.Hash); } missions.Remove(inventory.Hash); if (inventory is Block) { if (BlockReceived != null) BlockReceived(this, (Block)inventory); } else if (inventory is Transaction) { if (TransactionReceived != null) TransactionReceived(this, (Transaction)inventory); } }
private async Task<bool> RelayInternalAsync(Inventory data) { if (connectedPeers.Count == 0) return false; RemoteNode[] remoteNodes; lock (connectedPeers) { if (connectedPeers.Count == 0) return false; remoteNodes = connectedPeers.Values.ToArray(); } if (remoteNodes.Length == 0) return false; RelayCache.Add(data); await Task.WhenAny(remoteNodes.Select(p => p.RelayAsync(data))); return true; }
public async Task<bool> RelayAsync(Inventory data) { bool result = await RelayInternalAsync(data); if (data is Block) { if (Blockchain.Default != null && !Blockchain.Default.ContainsBlock(data.Hash) && Blockchain.Default.AddBlock(data as Block)) { if (NewInventory != null) NewInventory(this, data); } } else if (data is Transaction) { if (Blockchain.Default != null && !Blockchain.Default.ContainsTransaction(data.Hash) && Blockchain.Default.AddTransaction(data as Transaction)) { if (NewInventory != null) NewInventory(this, data); } } return result; }
internal void Relay(Inventory data) { EnqueueMessage("inv", InvPayload.Create(data.InventoryType, data.Hash)); }