]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Implement Display for ShutdownScript
authorJeffrey Czyz <jkczyz@gmail.com>
Sat, 31 Jul 2021 04:27:58 +0000 (23:27 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Mon, 9 Aug 2021 20:56:29 +0000 (15:56 -0500)
lightning/src/ln/channel.rs
lightning/src/ln/functional_tests.rs
lightning/src/ln/script.rs

index 78f08ca5366696f5452410b6f731ec67ac09e95a..d5f066c408021c96c1d13e1fa9ae9aaedca9b255 100644 (file)
@@ -608,7 +608,7 @@ impl<Signer: Sign> Channel<Signer> {
 
                if let Some(shutdown_scriptpubkey) = &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()) });
+                               return Err(APIError::APIMisuseError { err: format!("Provided a scriptpubkey format not accepted by peer: {}", shutdown_scriptpubkey) });
                        }
                }
 
@@ -843,7 +843,7 @@ impl<Signer: Sign> Channel<Signer> {
                                        } else {
                                                match ShutdownScript::try_from((script.clone(), their_features)) {
                                                        Ok(shutdown_script) => Some(shutdown_script.into_inner()),
-                                                       Err(_) => return Err(ChannelError::Close(format!("Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format. script: ({})", script.to_bytes().to_hex()))),
+                                                       Err(_) => return Err(ChannelError::Close(format!("Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: {}", script))),
                                                }
                                        }
                                },
@@ -860,7 +860,7 @@ impl<Signer: Sign> Channel<Signer> {
 
                if let Some(shutdown_scriptpubkey) = &shutdown_scriptpubkey {
                        if !shutdown_scriptpubkey.is_compatible(&their_features) {
-                               return Err(ChannelError::Close(format!("Provided a scriptpubkey format not accepted by peer. script: ({})", shutdown_scriptpubkey.clone().into_inner().to_bytes().to_hex())));
+                               return Err(ChannelError::Close(format!("Provided a scriptpubkey format not accepted by peer: {}", shutdown_scriptpubkey)));
                        }
                }
 
@@ -1587,7 +1587,7 @@ impl<Signer: Sign> Channel<Signer> {
                                        } else {
                                                match ShutdownScript::try_from((script.clone(), their_features)) {
                                                        Ok(shutdown_script) => Some(shutdown_script.into_inner()),
-                                                       Err(_) => return Err(ChannelError::Close(format!("Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format. script: ({})", script.to_bytes().to_hex()))),
+                                                       Err(_) => return Err(ChannelError::Close(format!("Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: {}", script))),
                                                }
                                        }
                                },
@@ -3295,7 +3295,7 @@ impl<Signer: Sign> Channel<Signer> {
                                assert!(send_shutdown);
                                let shutdown_scriptpubkey = keys_provider.get_shutdown_scriptpubkey();
                                if !shutdown_scriptpubkey.is_compatible(their_features) {
-                                       return Err(ChannelError::Close(format!("Provided a scriptpubkey format not accepted by peer. script: ({})", shutdown_scriptpubkey.clone().into_inner().to_bytes().to_hex())));
+                                       return Err(ChannelError::Close(format!("Provided a scriptpubkey format not accepted by peer: {}", shutdown_scriptpubkey)));
                                }
                                self.shutdown_scriptpubkey = Some(shutdown_scriptpubkey);
                                true
@@ -4487,7 +4487,7 @@ impl<Signer: Sign> Channel<Signer> {
                        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()) });
+                                       return Err(APIError::APIMisuseError { err: format!("Provided a scriptpubkey format not accepted by peer: {}", shutdown_scriptpubkey) });
                                }
                                self.shutdown_scriptpubkey = Some(shutdown_scriptpubkey);
                                true
index 204ee2a651d9a133f29fb4d143c1758bd0ff3fc0..f22df683247edb7e364713efa9eebf2387e4600c 100644 (file)
@@ -7548,7 +7548,7 @@ fn test_unsupported_anysegwit_upfront_shutdown_script() {
        match events[0] {
                MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => {
                        assert_eq!(node_id, nodes[0].node.get_our_node_id());
-                       assert!(regex::Regex::new(r"Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format. script: (\([A-Fa-f0-9]+\))").unwrap().is_match(&*msg.data));
+                       assert_eq!(msg.data, "Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: Script(OP_PUSHNUM_16 OP_PUSHBYTES_2 0028)");
                },
                _ => panic!("Unexpected event"),
        }
@@ -7566,7 +7566,7 @@ fn test_unsupported_anysegwit_upfront_shutdown_script() {
        match events[0] {
                MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => {
                        assert_eq!(node_id, nodes[1].node.get_our_node_id());
-                       assert!(regex::Regex::new(r"Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format. script: (\([A-Fa-f0-9]+\))").unwrap().is_match(&*msg.data));
+                       assert_eq!(msg.data, "Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: Script(OP_PUSHNUM_16 OP_PUSHBYTES_2 0028)");
                },
                _ => panic!("Unexpected event"),
        }
@@ -7593,7 +7593,7 @@ fn test_invalid_upfront_shutdown_script() {
        match events[0] {
                MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => {
                        assert_eq!(node_id, nodes[0].node.get_our_node_id());
-                       assert!(regex::Regex::new(r"Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format. script: (\([A-Fa-f0-9]+\))").unwrap().is_match(&*msg.data));
+                       assert_eq!(msg.data, "Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: Script(OP_0 OP_PUSHBYTES_2 0000)");
                },
                _ => panic!("Unexpected event"),
        }
index a123de741f043c3459b5b6acd0d3d47f6bf72ae4..3abb334ce478878d154f98b618df1c6ea6e1affe 100644 (file)
@@ -163,6 +163,15 @@ impl Into<Script> for ShutdownScript {
        }
 }
 
+impl core::fmt::Display for ShutdownScript{
+       fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
+               match &self.0 {
+                       ShutdownScriptImpl::Legacy(_) => self.clone().into_inner().fmt(f),
+                       ShutdownScriptImpl::Bolt2(script) => script.fmt(f),
+               }
+       }
+}
+
 #[cfg(test)]
 mod shutdown_script_tests {
        use super::ShutdownScript;