/// <exception cref="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 arrayLength = ReadVarInt(); if (arrayLength > MaxInventoryItems) throw new ProtocolException("Too many items in INV message: " + arrayLength); Items = new List<InventoryItem>((int) arrayLength); for (var i = 0UL; i < arrayLength; 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); }