- if let Ok((_, loaded_monitor)) =
- <(BlockHash, ChannelMonitor<Keys::ChanKeySigner>)>::read(&mut Cursor::new(&contents.unwrap()), keys) {
- res.insert(OutPoint { txid: txid.unwrap(), index: index.unwrap() }, loaded_monitor);
- } else {
- return Err(ChannelMonitorUpdateErr::PermanentFailure);
+ let contents = fs::read(&file.path())?;
+ let mut buffer = Cursor::new(&contents);
+ match <(BlockHash, ChannelMonitor<Signer>)>::read(&mut buffer, &*keys_manager) {
+ Ok((blockhash, channel_monitor)) => {
+ if channel_monitor.get_funding_txo().0.txid != txid.unwrap() || channel_monitor.get_funding_txo().0.index != index.unwrap() {
+ return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "ChannelMonitor was stored in the wrong file"));
+ }
+ res.push((blockhash, channel_monitor));
+ }
+ Err(e) => return Err(std::io::Error::new(
+ std::io::ErrorKind::InvalidData,
+ format!("Failed to deserialize ChannelMonitor: {}", e),
+ ))