From 3663f0875abda9566432eecb4ec7cb932dd1ea1a Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 27 Jan 2020 10:38:13 -0500 Subject: [PATCH] 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. --- lightning/src/ln/channelmanager.rs | 9 +++++++++ 1 file changed, 9 insertions(+) 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)?; -- 2.39.5