X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Fser.rs;h=a087467f7a438304ee3db7f52c956ce1a9ef90c3;hb=27079e04d7b542058e48cafaf5c2e7114b3b8e15;hp=60d5329d781c8ed247a36eef791470e224878d48;hpb=f1c7fd2ab9b4df5f4b7cad855501d1178b2eb1c6;p=rust-lightning diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index 60d5329d..a087467f 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -8,16 +8,17 @@ use std::hash::Hash; use std::sync::Mutex; use std::cmp; -use secp256k1::Signature; -use secp256k1::key::{PublicKey, SecretKey}; +use bitcoin::secp256k1::Signature; +use bitcoin::secp256k1::key::{PublicKey, SecretKey}; use bitcoin::blockdata::script::Script; use bitcoin::blockdata::transaction::{OutPoint, Transaction, TxOut}; use bitcoin::consensus; use bitcoin::consensus::Encodable; -use bitcoin_hashes::sha256d::Hash as Sha256dHash; +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}; +use ln::channelmanager::{PaymentPreimage, PaymentHash, PaymentSecret}; 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}; @@ -542,7 +543,7 @@ impl Writeable for Sha256dHash { impl Readable for Sha256dHash { fn read(r: &mut R) -> Result { - use bitcoin_hashes::Hash; + use bitcoin::hashes::Hash; let buf: [u8; 32] = Readable::read(r)?; Ok(Sha256dHash::from_slice(&buf[..]).unwrap()) @@ -591,6 +592,19 @@ impl Readable for PaymentHash { } } +impl Writeable for PaymentSecret { + fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { + self.0.write(w) + } +} + +impl Readable for PaymentSecret { + fn read(r: &mut R) -> Result { + let buf: [u8; 32] = Readable::read(r)?; + Ok(PaymentSecret(buf)) + } +} + impl Writeable for Option { fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { match *self { @@ -619,6 +633,36 @@ impl Readable for Option } } +impl Writeable for Txid { + fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { + w.write_all(&self[..]) + } +} + +impl Readable for Txid { + fn read(r: &mut R) -> Result { + use bitcoin::hashes::Hash; + + let buf: [u8; 32] = Readable::read(r)?; + Ok(Txid::from_slice(&buf[..]).unwrap()) + } +} + +impl Writeable for BlockHash { + fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { + w.write_all(&self[..]) + } +} + +impl Readable for BlockHash { + fn read(r: &mut R) -> Result { + use bitcoin::hashes::Hash; + + let buf: [u8; 32] = Readable::read(r)?; + Ok(BlockHash::from_slice(&buf[..]).unwrap()) + } +} + impl Writeable for OutPoint { fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { self.txid.write(w)?;