+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
//! A very simple serialization framework which is used to serialize/deserialize messages as well
//! as ChannelsManagers and ChannelMonitors.
-use std::result::Result;
use std::io::{Read, Write};
use std::collections::HashMap;
use std::hash::Hash;
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};
}
}
+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)?;