Beispiel #1
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);
        }
Beispiel #2
0
        private static PaymentDetails Load(Stream source)
        {
            var reader = new Protobuf.ProtobufReaderWriter(source);
            var result = new PaymentDetails();
            int key;

            while (reader.TryReadKey(out key))
            {
                switch (key)
                {
                case 1:
                    var network = reader.ReadString();
                    result.Network = network.Equals("main", StringComparison.OrdinalIgnoreCase) ? Network.Main :
                                     network.Equals("test", StringComparison.OrdinalIgnoreCase) ? Network.TestNet : null;
                    if (result.Network == null)
                    {
                        throw new NotSupportedException("Invalid network");
                    }
                    break;

                case 2:
                    result.Outputs.Add(PaymentOutput.Load(reader.ReadBytes()));
                    break;

                case 3:
                    result.Time = Utils.UnixTimeToDateTime(reader.ReadULong());
                    break;

                case 4:
                    result.Expires = Utils.UnixTimeToDateTime(reader.ReadULong());
                    break;

                case 5:
                    result.Memo = reader.ReadString();
                    break;

                case 6:
                    result.PaymentUrl = new Uri(reader.ReadString());
                    break;

                case 7:
                    result.MerchantData = reader.ReadBytes();
                    break;

                default:
                    break;
                }
            }
            return(result);
        }