コード例 #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
ファイル: PaymentACK.cs プロジェクト: PlumpMath/LushCoin
		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;
		}
コード例 #3
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);
        }