]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Use adapter instead of custom consensus_decode method.
authorArik Sosman <git@arik.io>
Fri, 2 Aug 2024 07:54:55 +0000 (00:54 -0700)
committerArik Sosman <git@arik.io>
Fri, 2 Aug 2024 07:54:55 +0000 (00:54 -0700)
lightning/src/util/ser.rs

index 738d58bc046e849e15d914958fa35c9c463a6a3b..83c80e804cf6f6015c4e5c6b45652728c846e691 100644 (file)
@@ -14,7 +14,7 @@
 //! [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
 
 use crate::prelude::*;
-use crate::io::{self, Read, Seek, Write};
+use crate::io::{self, BufRead, Read, Seek, Write};
 use crate::io_extras::{copy, sink};
 use core::hash::Hash;
 use crate::sync::{Mutex, RwLock};
@@ -64,6 +64,24 @@ impl<W: Write> Writer for W {
        }
 }
 
+pub(crate) struct ReadBufReadAdapter<R: Read + ?Sized>(pub R);
+
+impl<R: Read + ?Sized> Read for ReadBufReadAdapter<R> {
+       fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
+               self.0.read(buf)
+       }
+}
+
+impl<R: Read + ?Sized> BufRead for ReadBufReadAdapter<R> {
+       fn fill_buf(&mut self) -> io::Result<&[u8]> {
+               todo!()
+       }
+
+       fn consume(&mut self, amount: usize) {
+               todo!()
+       }
+}
+
 pub(crate) struct WriterWriteAdaptor<'a, W: Writer + 'a>(pub &'a mut W);
 impl<'a, W: Writer + 'a> Write for WriterWriteAdaptor<'a, W> {
        #[inline]
@@ -1272,7 +1290,7 @@ macro_rules! impl_consensus_ser {
 
                impl Readable for $bitcoin_type {
                        fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
-                               match consensus::encode::Decodable::consensus_decode_read(r) {
+                               match consensus::encode::Decodable::consensus_decode(&mut ReadBufReadAdapter(r)) {
                                        Ok(t) => Ok(t),
                                        Err(consensus::encode::Error::Io(ref e)) if e.kind() == io::ErrorKind::UnexpectedEof => Err(DecodeError::ShortRead),
                                        Err(consensus::encode::Error::Io(e)) => Err(DecodeError::Io(e.kind().into())),