Esempio n. 1
0
		public static PaymentMessage Load(Stream source)
		{
			if(source.CanSeek && source.Length > MaxLength)
				throw new ArgumentException("Payment messages larger than " + MaxLength + " bytes should be rejected by the merchant's server", "source");
			PaymentMessage message = new PaymentMessage();

			ProtobufReaderWriter proto = new ProtobufReaderWriter(source);
			int key;
			while(proto.TryReadKey(out key))
			{
				switch(key)
				{
					case 1:
						message.MerchantData = proto.ReadBytes();
						break;
					case 2:
						message.Transactions.Add(new Transaction(proto.ReadBytes()));
						break;
					case 3:
						message.RefundTo.Add(PaymentOutput.Load(proto.ReadBytes()));
						break;
					case 4:
						message.Memo = proto.ReadString();
						break;
					default:
						break;
				}
			}
			return message;
		}
Esempio n. 2
0
        public static PaymentRequest Load(Stream source, out byte[] signed)
        {
            RecorderStream record          = new RecorderStream(source);
            PaymentRequest req             = new PaymentRequest();
            var            reader          = new ProtobufReaderWriter(record);
            bool           signatureLoaded = false;
            int            key;
            bool           firstCert = true;

            while (reader.TryReadKey(out key))
            {
                switch (key)
                {
                case 1:
                    req.DetailsVersion = (uint)reader.ReadULong();
                    break;

                case 2:
                    req.PKIType = ToPKIType(reader.ReadString());
                    break;

                case 3:
                    var bytes = reader.ReadBytes();
                    ProtobufReaderWriter certs = new ProtobufReaderWriter(new MemoryStream(bytes));
                    int k;
                    while (certs.TryReadKey(out k))
                    {
                        if (firstCert)
                        {
                            req.MerchantCertificate = certs.ReadBytes();
                            firstCert = false;
                        }
                        else
                        {
                            req.AdditionalCertificates.Add(certs.ReadBytes());
                        }
                    }
                    break;

                case 4:
                    req._PaymentDetails = PaymentDetails.Load(reader.ReadBytes());
                    break;

                case 5:
                    record.Activated = false;
                    req.Signature    = reader.ReadBytes();
                    signatureLoaded  = req.Signature.Length != 0;
                    record.Activated = true;
                    record.RecordBytes(new byte[0]);
                    break;

                default:
                    break;
                }
            }
            signed = record.ToBytes();
            return(req);
        }
Esempio n. 3
0
        internal static PaymentOutput Load(byte[] bytes)
        {
            var           reader = new ProtobufReaderWriter(new MemoryStream(bytes));
            PaymentOutput output = new PaymentOutput();
            int           key;
            var           start = reader.Position;

            while (reader.TryReadKey(out key))
            {
                switch (key)
                {
                case 1:
                    output.Amount = Money.Satoshis(reader.ReadULong());
                    break;

                case 2:
                    output.Script = Script.FromBytesUnsafe(reader.ReadBytes());
                    break;

                default:
                    break;
                }
            }
            return(output);
        }
Esempio n. 4
0
        public static PaymentMessage Load(Stream source, Network network)
        {
            if (source.CanSeek && source.Length > MaxLength)
            {
                throw new ArgumentException("Payment messages larger than " + MaxLength + " bytes should be rejected by the merchant's server", "source");
            }
            network = network ?? Network.Main;
            PaymentMessage       message = new PaymentMessage();
            ProtobufReaderWriter proto   = new ProtobufReaderWriter(source);
            int key;

            while (proto.TryReadKey(out key))
            {
                switch (key)
                {
                case 1:
                    message.MerchantData = proto.ReadBytes();
                    break;

                case 2:
                    var tx = network.Consensus.ConsensusFactory.CreateTransaction();
                    tx.ReadWrite(proto.ReadBytes());
                    message.Transactions.Add(tx);
                    break;

                case 3:
                    message.RefundTo.Add(PaymentOutput.Load(proto.ReadBytes()));
                    break;

                case 4:
                    message.Memo = proto.ReadString();
                    break;

                default:
                    break;
                }
            }
            message.Network = network;
            return(message);
        }