ReadVarInt() public static method

public static ReadVarInt ( BinaryReader br ) : ulong
br System.IO.BinaryReader
return ulong
Example #1
0
        public void Load(byte[] data)
        {
            mInputs  = new List <TransactionInput>();
            mOutputs = new List <TransactionOutput>();

            MemoryStream stream = new MemoryStream(data);
            BinaryReader br     = new BinaryReader(stream);

            mVersion = br.ReadUInt32();
            ulong inputs = Program.ReadVarInt(br);

            for (ulong i = 0; i < inputs; i++)
            {
                TransactionInput input = new TransactionInput(br);
                mInputs.Add(input);
            }

            ulong outputs = Program.ReadVarInt(br);

            for (ulong i = 0; i < outputs; i++)
            {
                TransactionOutput output = new TransactionOutput(br);
                mOutputs.Add(output);
            }

            mLockTime = br.ReadUInt32();

            br.Close();
            Status = DataStatus.Loaded;
        }
        public TransactionOutput(BinaryReader br)
        {
            mValue = br.ReadUInt64();

            ulong scriptLen = Program.ReadVarInt(br);

            if (scriptLen <= int.MaxValue)
            {
                mScript = br.ReadBytes((int)scriptLen);
            }
            else
            {
                Console.WriteLine("Really big output script, need to handle this!");
            }
        }
Example #3
0
        public TransactionInput(BinaryReader br)
        {
            mOPHash  = br.ReadBytes(32);
            mOPIndex = br.ReadUInt32();

            ulong scriptLen = Program.ReadVarInt(br);

            if (scriptLen > int.MaxValue)
            {
                Console.WriteLine("Really big transaction data! need to handle this");
            }
            else
            {
                mSignatureScript = br.ReadBytes((int)scriptLen);
            }

            mSequence = br.ReadUInt32();
        }
        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();
        }