Example #1
0
 public static TxOut Read(BitcoinStreamReader reader)
 {
     ulong value = reader.ReadUInt64();
     ulong pubkeyScriptLength = reader.ReadUInt64Compact();
     if (pubkeyScriptLength > 10000)
     {
         //todo: handle correctly
         throw new Exception("Pubkey script is too long.");
     }
     byte[] pubkeyScript = reader.ReadBytes((int) pubkeyScriptLength);
     return new TxOut(value, pubkeyScript);
 }
Example #2
0
        public static TxIn Read(BitcoinStreamReader reader)
        {
            TxOutPoint previousOutput = TxOutPoint.Read(reader);
            ulong signatureScriptLength = reader.ReadUInt64Compact();
            if (signatureScriptLength > 1024*1024) //todo: see if there is actual limitation for this field
            {
                //todo: handle correctly
                throw new Exception("Too many transactions.");
            }
            byte[] signatureScript = reader.ReadBytes((int) signatureScriptLength);
            uint sequence = reader.ReadUInt32();

            return new TxIn(previousOutput, signatureScript, sequence);
        }
        public static GetDataMessage Read(BitcoinStreamReader reader)
        {
            ulong count = reader.ReadUInt64Compact();
            if (count > 50000)
            {
                //todo: handle correctly
                throw new Exception("Too many inventory vectors.");
            }

            InventoryVector[] inventory = new InventoryVector[count];
            for (ulong i = 0; i < count; i++)
            {
                inventory[i] = InventoryVector.Read(reader);
            }

            return new GetDataMessage(inventory);
        }
        public static GetBlocksMessage Read(BitcoinStreamReader reader)
        {
            int protocolVersion = reader.ReadInt32();

            ulong count = reader.ReadUInt64Compact();
            if (count > 10000)
            {
                //todo: handle correctly
                throw new Exception("Too many locator hashes.");
            }

            byte[][] locatorHashes = new byte[count][];
            for (ulong i = 0; i < count; i++)
            {
                locatorHashes[i] = reader.ReadBytes(32);
            }

            byte[] hashStop = reader.ReadBytes(32);

            return new GetBlocksMessage(protocolVersion, locatorHashes, hashStop);
        }
        public static MerkleBlockMessage Read(BitcoinStreamReader reader)
        {
            BlockHeader blockHeader = BlockHeader.Read(reader);
            uint totalTransactions = reader.ReadUInt32();

            ulong hashesCount = reader.ReadUInt64Compact();
            if (hashesCount > 1024*1024) //todo: see if there is actual limitation for this field
            {
                //todo: handle correctly
                throw new Exception("Too many hashes.");
            }

            byte[][] hashes = new byte[hashesCount][];
            for (ulong i = 0; i < hashesCount; i++)
            {
                hashes[i] = reader.ReadBytes(32);
            }

            ulong flagBytesCount = reader.ReadUInt64Compact();
            if (flagBytesCount > 1024*1024) //todo: see if there is actual limitation for this field
            {
                //todo: handle correctly
                throw new Exception("Too many flags.");
            }
            byte[] flags = reader.ReadBytes((int) flagBytesCount);

            return new MerkleBlockMessage(blockHeader, totalTransactions, hashes, flags);
        }