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); }
public static PaymentACK Load(Stream source) { if (source.CanSeek && source.Length > MaxLength) { throw new ArgumentOutOfRangeException("PaymentACK messages larger than " + MaxLength + " bytes should be rejected", "source"); } PaymentACK ack = new PaymentACK(); Protobuf.ProtobufReaderWriter reader = new Protobuf.ProtobufReaderWriter(source); int key; while (reader.TryReadKey(out key)) { switch (key) { case 1: var bytes = reader.ReadBytes(); ack.Payment = PaymentMessage.Load(bytes); break; case 2: ack.Memo = reader.ReadString(); break; default: break; } } return(ack); }