- #[cfg(test)]
- fn load_channel_data<Keys: KeysInterface>(&self, keys: &Keys) ->
- Result<HashMap<OutPoint, ChannelMonitor<Keys::ChanKeySigner>>, ChannelMonitorUpdateErr> {
- if let Err(_) = fs::create_dir_all(&self.path_to_channel_data) {
- return Err(ChannelMonitorUpdateErr::PermanentFailure);
+ /// Get the directory which was provided when this persister was initialized.
+ pub fn get_data_dir(&self) -> String {
+ self.path_to_channel_data.clone()
+ }
+
+ pub(crate) fn path_to_monitor_data(&self) -> PathBuf {
+ let mut path = PathBuf::from(self.path_to_channel_data.clone());
+ path.push("monitors");
+ path
+ }
+
+ /// Writes the provided `ChannelManager` to the path provided at `FilesystemPersister`
+ /// initialization, within a file called "manager".
+ pub fn persist_manager<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>(
+ data_dir: String,
+ manager: &ChannelManager<Signer, M, T, K, F, L>
+ ) -> Result<(), std::io::Error>
+ where
+ M::Target: chain::Watch<Signer>,
+ T::Target: BroadcasterInterface,
+ K::Target: KeysInterface<Signer=Signer>,
+ F::Target: FeeEstimator,
+ L::Target: Logger,
+ {
+ let path = PathBuf::from(data_dir);
+ util::write_to_file(path, "manager".to_string(), manager)
+ }
+
+ /// Read `ChannelMonitor`s from disk.
+ pub fn read_channelmonitors<Signer: Sign, K: Deref> (
+ &self, keys_manager: K
+ ) -> Result<Vec<(BlockHash, ChannelMonitor<Signer>)>, std::io::Error>
+ where K::Target: KeysInterface<Signer=Signer> + Sized,
+ {
+ let path = self.path_to_monitor_data();
+ if !Path::new(&path).exists() {
+ return Ok(Vec::new());