From: Matt Corallo Date: Mon, 27 Jan 2020 15:38:13 +0000 (-0500) Subject: Impl ReadableArgs for Arc, not just ChannelManager. X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=3663f0875abda9566432eecb4ec7cb932dd1ea1a;p=rust-lightning Impl ReadableArgs for Arc, not just ChannelManager. This provides a simple wrapper for deserializing right into an Arc, which improves UX a tiny bit when working with SimpleArcChannelManager types. --- diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index a62004e6e..fb917c933 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -3481,6 +3481,15 @@ pub struct ChannelManagerReadArgs<'a, ChanSigner: ChannelKeys, M: Deref> where M pub channel_monitors: &'a mut HashMap, } +// Implement ReadableArgs for an Arc'd ChannelManager to make it a bit easier to work with the +// SipmleArcChannelManager type: +impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable, M: Deref> ReadableArgs> for (Sha256dHash, Arc>) where M::Target: ManyChannelMonitor { + fn read(reader: &mut R, args: ChannelManagerReadArgs<'a, ChanSigner, M>) -> Result { + let (blockhash, chan_manager) = <(Sha256dHash, ChannelManager)>::read(reader, args)?; + Ok((blockhash, Arc::new(chan_manager))) + } +} + impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable, M: Deref> ReadableArgs> for (Sha256dHash, ChannelManager) where M::Target: ManyChannelMonitor { fn read(reader: &mut R, args: ChannelManagerReadArgs<'a, ChanSigner, M>) -> Result { let _ver: u8 = Readable::read(reader)?;