- (0, short_channel_id),
- (2, outpoint),
- (4, htlc_id),
- (6, incoming_packet_shared_secret)
-}, {}, {});
-
-impl Writeable for ClaimableHTLC {
- fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
- write_tlv_fields!(writer, {
- (0, self.prev_hop),
- (2, self.value),
- (4, self.payment_data.payment_secret),
- (6, self.payment_data.total_msat),
- (8, self.cltv_expiry)
- }, {});
- Ok(())
- }
-}
-
-impl Readable for ClaimableHTLC {
- fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
- let mut prev_hop = HTLCPreviousHopData {
- short_channel_id: 0, htlc_id: 0,
- incoming_packet_shared_secret: [0; 32],
- outpoint: OutPoint::null(),
- };
- let mut value = 0;
- let mut payment_secret = PaymentSecret([0; 32]);
- let mut total_msat = 0;
- let mut cltv_expiry = 0;
- read_tlv_fields!(reader, {
- (0, prev_hop),
- (2, value),
- (4, payment_secret),
- (6, total_msat),
- (8, cltv_expiry)
- }, {});
- Ok(ClaimableHTLC {
- prev_hop,
- value,
- payment_data: msgs::FinalOnionHopData {
- payment_secret,
- total_msat,
- },
- cltv_expiry,
- })
- }
-}
-
-impl Writeable for HTLCSource {
- fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
- match self {
- &HTLCSource::PreviousHopData(ref hop_data) => {
- 0u8.write(writer)?;
- hop_data.write(writer)?;
- },
- &HTLCSource::OutboundRoute { ref path, ref session_priv, ref first_hop_htlc_msat } => {
- 1u8.write(writer)?;
- path.write(writer)?;
- session_priv.write(writer)?;
- first_hop_htlc_msat.write(writer)?;
- }
- }
- Ok(())
- }
-}
-
-impl Readable for HTLCSource {
- fn read<R: ::std::io::Read>(reader: &mut R) -> Result<HTLCSource, DecodeError> {
- match <u8 as Readable>::read(reader)? {
- 0 => Ok(HTLCSource::PreviousHopData(Readable::read(reader)?)),
- 1 => Ok(HTLCSource::OutboundRoute {
- path: Readable::read(reader)?,
- session_priv: Readable::read(reader)?,
- first_hop_htlc_msat: Readable::read(reader)?,
- }),
- _ => Err(DecodeError::InvalidValue),
- }
- }
-}
-
-impl Writeable for HTLCFailReason {
- fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
- match self {
- &HTLCFailReason::LightningError { ref err } => {
- 0u8.write(writer)?;
- err.write(writer)?;
- },
- &HTLCFailReason::Reason { ref failure_code, ref data } => {
- 1u8.write(writer)?;
- failure_code.write(writer)?;
- data.write(writer)?;
- }
- }
- Ok(())
- }
-}
-
-impl Readable for HTLCFailReason {
- fn read<R: ::std::io::Read>(reader: &mut R) -> Result<HTLCFailReason, DecodeError> {
- match <u8 as Readable>::read(reader)? {
- 0 => Ok(HTLCFailReason::LightningError { err: Readable::read(reader)? }),
- 1 => Ok(HTLCFailReason::Reason {
- failure_code: Readable::read(reader)?,
- data: Readable::read(reader)?,
- }),
- _ => Err(DecodeError::InvalidValue),
- }
- }
-}
-
-impl Writeable for HTLCForwardInfo {
- fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
- match self {
- &HTLCForwardInfo::AddHTLC { ref prev_short_channel_id, ref prev_funding_outpoint, ref prev_htlc_id, ref forward_info } => {
- 0u8.write(writer)?;
- prev_short_channel_id.write(writer)?;
- prev_funding_outpoint.write(writer)?;
- prev_htlc_id.write(writer)?;
- forward_info.write(writer)?;
- },
- &HTLCForwardInfo::FailHTLC { ref htlc_id, ref err_packet } => {
- 1u8.write(writer)?;
- htlc_id.write(writer)?;
- err_packet.write(writer)?;
- },
- }
- Ok(())
- }
-}
-
-impl Readable for HTLCForwardInfo {
- fn read<R: ::std::io::Read>(reader: &mut R) -> Result<HTLCForwardInfo, DecodeError> {
- match <u8 as Readable>::read(reader)? {
- 0 => Ok(HTLCForwardInfo::AddHTLC {
- prev_short_channel_id: Readable::read(reader)?,
- prev_funding_outpoint: Readable::read(reader)?,
- prev_htlc_id: Readable::read(reader)?,
- forward_info: Readable::read(reader)?,
- }),
- 1 => Ok(HTLCForwardInfo::FailHTLC {
- htlc_id: Readable::read(reader)?,
- err_packet: Readable::read(reader)?,
- }),
- _ => Err(DecodeError::InvalidValue),
- }
- }
-}
+ (0, short_channel_id, required),
+ (2, outpoint, required),
+ (4, htlc_id, required),
+ (6, incoming_packet_shared_secret, required)
+});
+
+impl_writeable_tlv_based!(ClaimableHTLC, {
+ (0, prev_hop, required),
+ (2, value, required),
+ (4, payment_data, required),
+ (6, cltv_expiry, required),
+});
+
+impl_writeable_tlv_based_enum!(HTLCSource,
+ (0, OutboundRoute) => {
+ (0, session_priv, required),
+ (2, first_hop_htlc_msat, required),
+ (4, path, vec_type),
+ }, ;
+ (1, PreviousHopData)
+);
+
+impl_writeable_tlv_based_enum!(HTLCFailReason,
+ (0, LightningError) => {
+ (0, err, required),
+ },
+ (1, Reason) => {
+ (0, failure_code, required),
+ (2, data, vec_type),
+ },
+;);
+
+impl_writeable_tlv_based_enum!(HTLCForwardInfo,
+ (0, AddHTLC) => {
+ (0, forward_info, required),
+ (2, prev_short_channel_id, required),
+ (4, prev_htlc_id, required),
+ (6, prev_funding_outpoint, required),
+ },
+ (1, FailHTLC) => {
+ (0, htlc_id, required),
+ (2, err_packet, required),
+ },
+;);