Exemple #1
0
        public byte[] UserAgentBytes;       // varstring

        public BitcoinVersionPayload(BitcoinVarString userAgent, byte[] nonceBytes, BitcoinNetworkAddressPayload sender,
                                     BitcoinNetworkAddressPayload receiver)
        {
            this.ProtocolVersion      = ChatClientConfiguration.ProtocolVersion;
            this.ProtocolVersionBytes = BitConverter.GetBytes(ChatClientConfiguration.ProtocolVersion);

            this.Services      = ChatClientConfiguration.OwnPeerServices;
            this.ServicesBytes = BitConverter.GetBytes((ulong)this.Services);

            this.TimeStamp      = DateTimeOffset.UtcNow;
            this.TimestampBytes = BitConverter.GetBytes((ulong)this.TimeStamp.ToUnixTimeSeconds());

            this.Sender             = sender;
            this.SenderAddressBytes = sender.SerializeForVersion();

            this.Receiver             = receiver;
            this.ReceiverAddressBytes = receiver.SerializeForVersion();

            this.NonceBytes = nonceBytes;

            this.UserAgent      = userAgent;
            this.UserAgentBytes = userAgent.VarStringBytes;

            this.StartHeightBytes = new byte[4];
            this.StartHeight      = BitConverter.ToUInt32(this.StartHeightBytes, 0);
            this.RelayBytes       = new byte[1];
            this.RelayBytes[0]    = 1;
        }
Exemple #2
0
        public BitcoinVersionPayload(byte[] serialized)
        {
            this.ProtocolVersionBytes = new byte[4];
            Buffer.BlockCopy(serialized, 0, this.ProtocolVersionBytes, 0, 4);
            this.ProtocolVersion = BitConverter.ToUInt32(this.ProtocolVersionBytes, 0);

            this.ServicesBytes = new byte[8];
            Buffer.BlockCopy(serialized, 4, this.ServicesBytes, 0, 8);
            this.Services = (PeerServices)BitConverter.ToUInt64(this.ServicesBytes, 0);

            this.TimestampBytes = new byte[8];
            Buffer.BlockCopy(serialized, 12, this.TimestampBytes, 0, 8);
            this.TimeStamp = DateTimeOffset.FromUnixTimeSeconds((long)BitConverter.ToUInt64(this.TimestampBytes, 0));

            this.ReceiverAddressBytes = new byte[26];
            Buffer.BlockCopy(serialized, 20, this.ReceiverAddressBytes, 0, 26);
            this.Receiver = new BitcoinNetworkAddressPayload(this.ReceiverAddressBytes, 0, false);

            this.SenderAddressBytes = new byte[26];
            Buffer.BlockCopy(serialized, 46, this.SenderAddressBytes, 0, 26);
            this.Sender = new BitcoinNetworkAddressPayload(this.SenderAddressBytes, 0, false);

            this.NonceBytes = new byte[8];
            Buffer.BlockCopy(serialized, 72, this.NonceBytes, 0, 8);

            this.UserAgent      = new BitcoinVarString(serialized, 80);
            this.UserAgentBytes = this.UserAgent.VarStringBytes;

            this.StartHeightBytes = new byte[4];
            Buffer.BlockCopy(serialized, 80 + this.UserAgent.SerializedLength, this.StartHeightBytes, 0, 4);
            this.StartHeight = BitConverter.ToUInt32(this.StartHeightBytes, 0);


            this.RelayBytes    = new byte[1];
            this.RelayBytes[0] = serialized[80 + this.UserAgent.SerializedLength + 4];
        }