BitCoinClient.NodeConnection.RequestData C# (CSharp) Method

RequestData() public method

public RequestData ( List transactions, List blocks ) : void
transactions List
blocks List
return void
        public void RequestData(List<Transaction> transactions, List<Block> blocks)
        {
            MemoryStream stream = new MemoryStream();
            BinaryWriter bw = new BinaryWriter(stream);

            int count = transactions.Count + blocks.Count;
            Program.WriteVarInt(bw, (ulong)count);
            foreach (Transaction t in transactions)
            {
                const int transactionType = 1;
                bw.Write(transactionType);
                bw.Write(t.Hash);
            }
            foreach (Block b in blocks)
            {
                const int blockType = 2;
                bw.Write(blockType);
                bw.Write(b.Hash);
            }
            SendPacket("getdata", stream.ToArray());

            bw.Close();
        }

Usage Example

Example #1
0
        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();
        }
All Usage Examples Of BitCoinClient.NodeConnection::RequestData