-impl Writeable for ChannelMonitorUpdateStep {
- fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
- match self {
- &ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo { ref commitment_tx, ref htlc_outputs } => {
- 0u8.write(w)?;
- commitment_tx.write(w)?;
- (htlc_outputs.len() as u64).write(w)?;
- for &(ref output, ref signature, ref source) in htlc_outputs.iter() {
- output.write(w)?;
- signature.write(w)?;
- source.write(w)?;
- }
- }
- &ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTXInfo { commitment_txid, ref htlc_outputs, ref commitment_number, ref their_revocation_point } => {
- 1u8.write(w)?;
- commitment_txid.write(w)?;
- commitment_number.write(w)?;
- their_revocation_point.write(w)?;
- (htlc_outputs.len() as u64).write(w)?;
- for &(ref output, ref source) in htlc_outputs.iter() {
- output.write(w)?;
- source.as_ref().map(|b| b.as_ref()).write(w)?;
- }
- },
- &ChannelMonitorUpdateStep::PaymentPreimage { ref payment_preimage } => {
- 2u8.write(w)?;
- payment_preimage.write(w)?;
- },
- &ChannelMonitorUpdateStep::CommitmentSecret { ref idx, ref secret } => {
- 3u8.write(w)?;
- idx.write(w)?;
- secret.write(w)?;
- },
- &ChannelMonitorUpdateStep::ChannelForceClosed { ref should_broadcast } => {
- 4u8.write(w)?;
- should_broadcast.write(w)?;
- },
- }
- Ok(())
- }
-}
-impl Readable for ChannelMonitorUpdateStep {
- fn read<R: ::std::io::Read>(r: &mut R) -> Result<Self, DecodeError> {
- match Readable::read(r)? {
- 0u8 => {
- Ok(ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
- commitment_tx: Readable::read(r)?,
- htlc_outputs: {
- let len: u64 = Readable::read(r)?;
- let mut res = Vec::new();
- for _ in 0..len {
- res.push((Readable::read(r)?, Readable::read(r)?, Readable::read(r)?));
- }
- res
- },
- })
- },
- 1u8 => {
- Ok(ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTXInfo {
- commitment_txid: Readable::read(r)?,
- commitment_number: Readable::read(r)?,
- their_revocation_point: Readable::read(r)?,
- htlc_outputs: {
- let len: u64 = Readable::read(r)?;
- let mut res = Vec::new();
- for _ in 0..len {
- res.push((Readable::read(r)?, <Option<HTLCSource> as Readable>::read(r)?.map(|o| Box::new(o))));
- }
- res
- },
- })
- },
- 2u8 => {
- Ok(ChannelMonitorUpdateStep::PaymentPreimage {
- payment_preimage: Readable::read(r)?,
- })
- },
- 3u8 => {
- Ok(ChannelMonitorUpdateStep::CommitmentSecret {
- idx: Readable::read(r)?,
- secret: Readable::read(r)?,
- })
- },
- 4u8 => {
- Ok(ChannelMonitorUpdateStep::ChannelForceClosed {
- should_broadcast: Readable::read(r)?
- })
- },
- _ => Err(DecodeError::InvalidValue),
- }
- }
-}
+impl_writeable_tlv_based_enum!(ChannelMonitorUpdateStep,
+ (0, LatestHolderCommitmentTXInfo) => {
+ (0, commitment_tx, required),
+ (2, htlc_outputs, vec_type),
+ },
+ (1, LatestCounterpartyCommitmentTXInfo) => {
+ (0, commitment_txid, required),
+ (2, commitment_number, required),
+ (4, their_revocation_point, required),
+ (6, htlc_outputs, vec_type),
+ },
+ (2, PaymentPreimage) => {
+ (0, payment_preimage, required),
+ },
+ (3, CommitmentSecret) => {
+ (0, idx, required),
+ (2, secret, required),
+ },
+ (4, ChannelForceClosed) => {
+ (0, should_broadcast, required),
+ },
+;);