Esempio n. 1
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. 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);
        }