Typify payment_hash and payment_preimage
[rust-lightning] / src / util / ser.rs
index 84cfa8d1633f98e78a996792d53c146d981be61a..c1d2802a76da834d03555cf73b0e2f88139d52a5 100644 (file)
@@ -12,6 +12,7 @@ use bitcoin::util::hash::Sha256dHash;
 use bitcoin::blockdata::script::Script;
 use std::marker::Sized;
 use ln::msgs::DecodeError;
+use ln::channelmanager::{PaymentPreimage, PaymentHash};
 use util::byte_utils;
 
 use util::byte_utils::{be64_to_array, be48_to_array, be32_to_array, be16_to_array, slice_to_be16, slice_to_be32, slice_to_be48, slice_to_be64};
@@ -386,3 +387,29 @@ impl<R: Read> Readable<R> for Signature {
                }
        }
 }
+
+impl Writeable for PaymentPreimage {
+       fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
+               self.0.write(w)
+       }
+}
+
+impl<R: Read> Readable<R> for PaymentPreimage {
+       fn read(r: &mut R) -> Result<Self, DecodeError> {
+               let buf: [u8; 32] = Readable::read(r)?;
+               Ok(PaymentPreimage(buf))
+       }
+}
+
+impl Writeable for PaymentHash {
+       fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
+               self.0.write(w)
+       }
+}
+
+impl<R: Read> Readable<R> for PaymentHash {
+       fn read(r: &mut R) -> Result<Self, DecodeError> {
+               let buf: [u8; 32] = Readable::read(r)?;
+               Ok(PaymentHash(buf))
+       }
+}