Block CreateBlock(Key key) { Block block = new Block(); // Create transaction from nowhere to us! Transaction tx = new Transaction(); TransactionInput input = new TransactionInput(); TransactionOutput output = new TransactionOutput(key); tx.AddInput(input); tx.AddOutput(output); block.AddTransaction(tx); Transaction[] transactions = mBitcoin.GetTransactions(); return block; }
public void HandleInvPacket(NodeConnection node, byte[] payload) { MemoryStream stream = new MemoryStream(payload); BinaryReader br = new BinaryReader(stream); List<Transaction> transLoadList = new List<Transaction>(); List<Block> blockLoadList = new List<Block>(); ulong count = Program.ReadVarInt(br); for (ulong i = 0; i < count; i++) { uint type = br.ReadUInt32(); byte[] hash = br.ReadBytes(32); if (type != 0) { string str = Program.HashToString(hash); if (type == 1) { if (mTransactions.ContainsKey(str)) { // We already know about this transaction Transaction t = mTransactions[str]; if (t.Status == Transaction.DataStatus.NoData) { // No details about this transaction loaded yet, request it t.Status = Transaction.DataStatus.Requested; transLoadList.Add(t); } } else { // Transaction we dont know about yet Transaction t = new Transaction(hash, Transaction.DataStatus.Requested); // Add it to the transaction dictionary mTransactions[str] = t; // Add it to the list of transactions to requrest data about transLoadList.Add(t); } } else { if (mBlocks.ContainsKey(str)) { // We already know about this block Block b = mBlocks[str]; if (b.Status == NetworkDataObject.DataStatus.NoData) { // No details about this block loaded yet, request it b.Status = NetworkDataObject.DataStatus.Requested; blockLoadList.Add(b); } } else { // Block we dont know about yet Block b = new Block(hash, NetworkDataObject.DataStatus.Requested); // Add it to the block dictionary mBlocks[str] = b; // Add it to the list of blocks to requrest data about blockLoadList.Add(b); } } } } // Load the transactions and blocks we dont have loaded node.RequestData(transLoadList, blockLoadList); br.Close(); }