- let monitor_update = if self.shutdown_scriptpubkey.is_none() {
- self.shutdown_scriptpubkey = Some(keys_provider.get_shutdown_scriptpubkey());
- self.latest_monitor_update_id += 1;
- Some(ChannelMonitorUpdate {
- update_id: self.latest_monitor_update_id,
- updates: vec![ChannelMonitorUpdateStep::ShutdownScript {
- scriptpubkey: self.get_closing_scriptpubkey(),
- }],
- })
- } else { None };
+ let shutdown_scriptpubkey = match self.shutdown_scriptpubkey {
+ Some(_) => None,
+ None => {
+ let shutdown_scriptpubkey = keys_provider.get_shutdown_scriptpubkey();
+ if !shutdown_scriptpubkey.is_compatible(their_features) {
+ return Err(APIError::APIMisuseError { err: format!("Provided a scriptpubkey format not accepted by peer. script: ({})", shutdown_scriptpubkey.clone().into_inner().to_bytes().to_hex()) });
+ }
+ Some(shutdown_scriptpubkey)
+ },
+ };
+
+ let monitor_update = match shutdown_scriptpubkey {
+ Some(shutdown_scriptpubkey) => {
+ self.shutdown_scriptpubkey = Some(shutdown_scriptpubkey);
+ self.latest_monitor_update_id += 1;
+ Some(ChannelMonitorUpdate {
+ update_id: self.latest_monitor_update_id,
+ updates: vec![ChannelMonitorUpdateStep::ShutdownScript {
+ scriptpubkey: self.get_closing_scriptpubkey(),
+ }],
+ })
+ },
+ None => None,
+ };