Exemplo n.º 1
0
        public static RejectMessage Read(BitcoinStreamReader reader)
        {
            string rejectedCommand = reader.ReadText(MaxTextLength);
            byte reasonByte = reader.ReadByte();
            string reasonText = reader.ReadText(MaxTextLength);
            //todo: parse data? length should be provided as parameter?

            RejectReason reason = (RejectReason) reasonByte;

            return new RejectMessage(rejectedCommand, reason, reasonText);
        }
        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;
        }