/// <exception cref="BitCoinSharp.ProtocolException" /> protected override void Parse() { // An inv is vector<CInv> where CInv is int+hash. The int is either 1 or 2 for tx or block. var arrayLen = ReadVarInt(); if (arrayLen > _maxInventoryItems) throw new ProtocolException("Too many items in INV message: " + arrayLen); _items = new List<InventoryItem>((int) arrayLen); for (var i = 0UL; i < arrayLen; i++) { if (Cursor + 4 + 32 > Bytes.Length) { throw new ProtocolException("Ran off the end of the INV"); } var typeCode = ReadUint32(); InventoryItem.ItemType type; // See ppszTypeName in net.h switch (typeCode) { case 0: type = InventoryItem.ItemType.Error; break; case 1: type = InventoryItem.ItemType.Transaction; break; case 2: type = InventoryItem.ItemType.Block; break; default: throw new ProtocolException("Unknown CInv type: " + typeCode); } var item = new InventoryItem(type, ReadHash()); _items.Add(item); } Bytes = null; }
public void AddItem(InventoryItem item) { _items.Add(item); }