X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fchannelmonitor.rs;h=503a358e8b3c49c10a33950615ccd41999b6f311;hb=b04219a7670f38f31342aedc5ad06597d2f42cca;hp=7a6bac9c7fba4bf30da188ef8842a569f986c4da;hpb=99a34e1d17eb97f62f0f855a85c87fc770a5c1f3;p=rust-lightning diff --git a/lightning/src/ln/channelmonitor.rs b/lightning/src/ln/channelmonitor.rs index 7a6bac9c..503a358e 100644 --- a/lightning/src/ln/channelmonitor.rs +++ b/lightning/src/ln/channelmonitor.rs @@ -833,8 +833,14 @@ impl PartialEq for ChannelMonitor { } impl ChannelMonitor { - /// Serializes into a vec, with various modes for the exposed pub fns - fn write(&self, writer: &mut W, for_local_storage: bool) -> Result<(), ::std::io::Error> { + /// Writes this monitor into the given writer, suitable for writing to disk. + /// + /// Note that the deserializer is only implemented for (Sha256dHash, ChannelMonitor), which + /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along + /// the "reorg path" (ie not just starting at the same height but starting at the highest + /// common block that appears on your best chain as well as on the chain which contains the + /// last block hash returned) upon deserializing the object! + pub fn write_for_disk(&self, writer: &mut W) -> Result<(), ::std::io::Error> { //TODO: We still write out all the serialization here manually instead of using the fancy //serialization framework we have, we should migrate things over to it. writer.write_all(&[SERIALIZATION_VERSION; 1])?; @@ -929,14 +935,10 @@ impl ChannelMonitor { } } - if for_local_storage { - writer.write_all(&byte_utils::be64_to_array(self.remote_hash_commitment_number.len() as u64))?; - for (ref payment_hash, commitment_number) in self.remote_hash_commitment_number.iter() { - writer.write_all(&payment_hash.0[..])?; - writer.write_all(&byte_utils::be48_to_array(*commitment_number))?; - } - } else { - writer.write_all(&byte_utils::be64_to_array(0))?; + writer.write_all(&byte_utils::be64_to_array(self.remote_hash_commitment_number.len() as u64))?; + for (ref payment_hash, commitment_number) in self.remote_hash_commitment_number.iter() { + writer.write_all(&payment_hash.0[..])?; + writer.write_all(&byte_utils::be48_to_array(*commitment_number))?; } macro_rules! serialize_local_tx { @@ -977,17 +979,8 @@ impl ChannelMonitor { writer.write_all(&[0; 1])?; } - if for_local_storage { - writer.write_all(&byte_utils::be48_to_array(self.current_remote_commitment_number))?; - } else { - writer.write_all(&byte_utils::be48_to_array(0))?; - } - - if for_local_storage { - writer.write_all(&byte_utils::be48_to_array(self.current_local_commitment_number))?; - } else { - writer.write_all(&byte_utils::be48_to_array(0))?; - } + writer.write_all(&byte_utils::be48_to_array(self.current_remote_commitment_number))?; + writer.write_all(&byte_utils::be48_to_array(self.current_local_commitment_number))?; writer.write_all(&byte_utils::be64_to_array(self.payment_preimages.len() as u64))?; for payment_preimage in self.payment_preimages.values() { @@ -1039,28 +1032,6 @@ impl ChannelMonitor { Ok(()) } - - /// Writes this monitor into the given writer, suitable for writing to disk. - /// - /// Note that the deserializer is only implemented for (Sha256dHash, ChannelMonitor), which - /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along - /// the "reorg path" (ie not just starting at the same height but starting at the highest - /// common block that appears on your best chain as well as on the chain which contains the - /// last block hash returned) upon deserializing the object! - pub fn write_for_disk(&self, writer: &mut W) -> Result<(), ::std::io::Error> { - self.write(writer, true) - } - - /// Encodes this monitor into the given writer, suitable for sending to a remote watchtower - /// - /// Note that the deserializer is only implemented for (Sha256dHash, ChannelMonitor), which - /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along - /// the "reorg path" (ie not just starting at the same height but starting at the highest - /// common block that appears on your best chain as well as on the chain which contains the - /// last block hash returned) upon deserializing the object! - pub fn write_for_watchtower(&self, writer: &mut W) -> Result<(), ::std::io::Error> { - self.write(writer, false) - } } impl ChannelMonitor {