Ejemplo n.º 1
0
 public static Tx Read(BitcoinStreamReader reader)
 {
     uint version = reader.ReadUInt32();
     TxIn[] inputs = reader.ReadArray(1024*1024, TxIn.Read);
     TxOut[] outputs = reader.ReadArray(1024*1024, TxOut.Read);
     uint lockTime = reader.ReadUInt32();
     return new Tx(version, inputs, outputs, lockTime);
 }
Ejemplo n.º 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 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);
        }
Ejemplo n.º 4
0
 public static NetAddr Read(BitcoinStreamReader reader)
 {
     uint timestamp = reader.ReadUInt32();
     ulong services = reader.ReadUInt64();
     IPAddress address = reader.ReadAddress();
     ushort port = reader.ReadUInt16BigEndian();
     return new NetAddr(timestamp, services, address, port);
 }
Ejemplo n.º 5
0
        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);
        }