- let path = PathBuf::from(data_dir);
- util::write_to_file(path, "manager".to_string(), manager)
- }
-
- #[cfg(test)]
- fn load_channel_data<Keys: KeysInterface>(&self, keys: &Keys) ->
- Result<HashMap<OutPoint, ChannelMonitor<Keys::Signer>>, ChannelMonitorUpdateErr> {
- if let Err(_) = fs::create_dir_all(self.path_to_monitor_data()) {
- return Err(ChannelMonitorUpdateErr::PermanentFailure);
+ let mut path = PathBuf::from(&self.path_to_channel_data);
+ path.push("monitors");
+ if !Path::new(&path).exists() {
+ return Ok(Vec::new());
+ }
+ let mut res = Vec::new();
+ for file_option in fs::read_dir(path).unwrap() {
+ let file = file_option.unwrap();
+ let owned_file_name = file.file_name();
+ let filename = owned_file_name.to_str();
+ if !filename.is_some() || !filename.unwrap().is_ascii() || filename.unwrap().len() < 65 {
+ return Err(std::io::Error::new(
+ std::io::ErrorKind::InvalidData,
+ "Invalid ChannelMonitor file name",
+ ));
+ }
+ if filename.unwrap().ends_with(".tmp") {
+ // If we were in the middle of committing an new update and crashed, it should be
+ // safe to ignore the update - we should never have returned to the caller and
+ // irrevocably committed to the new state in any way.
+ continue;