Adopting new bitcoin hash types and crate version
[rust-lightning] / lightning / src / util / ser.rs
index fd0e9f7a383b2bb9e0530e183e5ee9203218e065..a087467f7a438304ee3db7f52c956ce1a9ef90c3 100644 (file)
@@ -15,6 +15,7 @@ use bitcoin::blockdata::transaction::{OutPoint, Transaction, TxOut};
 use bitcoin::consensus;
 use bitcoin::consensus::Encodable;
 use bitcoin::hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hash_types::{Txid, BlockHash};
 use std::marker::Sized;
 use ln::msgs::DecodeError;
 use ln::channelmanager::{PaymentPreimage, PaymentHash, PaymentSecret};
@@ -632,6 +633,36 @@ impl<T: Readable> Readable for Option<T>
        }
 }
 
+impl Writeable for Txid {
+       fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
+               w.write_all(&self[..])
+       }
+}
+
+impl Readable for Txid {
+       fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
+               use bitcoin::hashes::Hash;
+
+               let buf: [u8; 32] = Readable::read(r)?;
+               Ok(Txid::from_slice(&buf[..]).unwrap())
+       }
+}
+
+impl Writeable for BlockHash {
+       fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
+               w.write_all(&self[..])
+       }
+}
+
+impl Readable for BlockHash {
+       fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
+               use bitcoin::hashes::Hash;
+
+               let buf: [u8; 32] = Readable::read(r)?;
+               Ok(BlockHash::from_slice(&buf[..]).unwrap())
+       }
+}
+
 impl Writeable for OutPoint {
        fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
                self.txid.write(w)?;