Skip to content

Commit 5bd8837

Browse files
authored
Merge pull request #332 from ariard/2019-03-option-serialize-channel-monitor
Use more Writeable/Readable for Option<T> in ChannelMonitor serializer/deserializer
2 parents a383f64 + bcd7bae commit 5bd8837

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

src/ln/channelmonitor.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -801,18 +801,8 @@ impl ChannelMonitor {
801801
writer.write_all(&delayed_payment_base_key[..])?;
802802
writer.write_all(&payment_base_key[..])?;
803803
writer.write_all(&shutdown_pubkey.serialize())?;
804-
if let Some(ref prev_latest_per_commitment_point) = *prev_latest_per_commitment_point {
805-
writer.write_all(&[1; 1])?;
806-
writer.write_all(&prev_latest_per_commitment_point.serialize())?;
807-
} else {
808-
writer.write_all(&[0; 1])?;
809-
}
810-
if let Some(ref latest_per_commitment_point) = *latest_per_commitment_point {
811-
writer.write_all(&[1; 1])?;
812-
writer.write_all(&latest_per_commitment_point.serialize())?;
813-
} else {
814-
writer.write_all(&[0; 1])?;
815-
}
804+
prev_latest_per_commitment_point.write(writer)?;
805+
latest_per_commitment_point.write(writer)?;
816806
match funding_info {
817807
&Some((ref outpoint, ref script)) => {
818808
writer.write_all(&outpoint.txid[..])?;
@@ -823,8 +813,8 @@ impl ChannelMonitor {
823813
debug_assert!(false, "Try to serialize a useless Local monitor !");
824814
},
825815
}
826-
write_option!(current_remote_commitment_txid);
827-
write_option!(prev_remote_commitment_txid);
816+
current_remote_commitment_txid.write(writer)?;
817+
prev_remote_commitment_txid.write(writer)?;
828818
},
829819
Storage::Watchtower { .. } => unimplemented!(),
830820
}
@@ -864,7 +854,7 @@ impl ChannelMonitor {
864854
writer.write_all(&byte_utils::be64_to_array($htlc_output.amount_msat))?;
865855
writer.write_all(&byte_utils::be32_to_array($htlc_output.cltv_expiry))?;
866856
writer.write_all(&$htlc_output.payment_hash.0[..])?;
867-
write_option!(&$htlc_output.transaction_output_index);
857+
$htlc_output.transaction_output_index.write(writer)?;
868858
}
869859
}
870860

0 commit comments

Comments
 (0)