Пример #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);
        }
Пример #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 :
                                     network.Equals("regtest", StringComparison.OrdinalIgnoreCase) ? Network.RegTest : 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);
        }
Пример #3
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);
        }