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);
 }
Exemple #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 GetHeadersMessage 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 GetHeadersMessage(protocolVersion, locatorHashes, hashStop);
        }
 public static InventoryVector Read(BitcoinStreamReader reader)
 {
     InventoryVectorType type = (InventoryVectorType) reader.ReadInt32();
     byte[] hash = reader.ReadBytes(32);
     return new InventoryVector(type, hash);
 }
 public static TxOutPoint Read(BitcoinStreamReader reader)
 {
     byte[] hash = reader.ReadBytes(32);
     int index = reader.ReadInt32();
     return new TxOutPoint(hash, index);
 }
        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);
        }
        public static BlockHeader Read(BitcoinStreamReader reader)
        {
            uint version = reader.ReadUInt32();
            byte[] prevBlock = reader.ReadBytes(32);
            byte[] merkleRoot = reader.ReadBytes(32);
            uint timestamp = reader.ReadUInt32();
            uint bits = reader.ReadUInt32();
            uint nonce = reader.ReadUInt32();

            return new BlockHeader(version, prevBlock, merkleRoot, timestamp, bits, nonce);
        }