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);
        }
Пример #2
0
 public static TxOutPoint Read(BitcoinStreamReader reader)
 {
     byte[] hash = reader.ReadBytes(32);
     int index = reader.ReadInt32();
     return new TxOutPoint(hash, index);
 }
 public static InventoryVector Read(BitcoinStreamReader reader)
 {
     InventoryVectorType type = (InventoryVectorType) reader.ReadInt32();
     byte[] hash = reader.ReadBytes(32);
     return new InventoryVector(type, hash);
 }
        public static VersionMessage Read(BitcoinStreamReader reader)
        {
            int protocolVersion = reader.ReadInt32();
            ulong services = reader.ReadUInt64();
            long timestamp = reader.ReadInt64();

            ulong remoteServices = reader.ReadUInt64();
            IPAddress remoteAddress = reader.ReadAddress();
            ushort remotePort = reader.ReadUInt16BigEndian();
            IPEndPoint remoteEndpoint = new IPEndPoint(remoteAddress, remotePort);

            ulong localServices = reader.ReadUInt64();
            IPAddress localAddress = reader.ReadAddress();
            ushort localPort = reader.ReadUInt16BigEndian();
            IPEndPoint localEndpoint = new IPEndPoint(localAddress, localPort);

            ulong nonce = reader.ReadUInt64();

            string userAgent = reader.ReadText(MaxUserAgentLength);
            int startHeight = reader.ReadInt32();
            //todo: support clients that don't send relay bit
            bool acceptBroadcasts = reader.ReadBoolean();

            VersionMessage versionMessage = new VersionMessage(
                userAgent,
                protocolVersion,
                services,
                timestamp,
                nonce,
                localEndpoint,
                remoteEndpoint,
                startHeight,
                acceptBroadcasts);
            versionMessage.LocalServices = localServices;
            versionMessage.RemoteServices = remoteServices;
            return versionMessage;
        }