From: Jeffrey Czyz Date: Sat, 31 Jul 2021 04:27:58 +0000 (-0500) Subject: Implement Display for ShutdownScript X-Git-Tag: v0.0.100~7^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=4a44bfa3a42841de88b7c52379892a358646d9b8;p=rust-lightning Implement Display for ShutdownScript --- diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 78f08ca53..d5f066c40 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -608,7 +608,7 @@ impl Channel { 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 Channel { } 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 Channel { 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 Channel { } 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 Channel { 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 Channel { 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 diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 204ee2a65..f22df6832 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -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"), } diff --git a/lightning/src/ln/script.rs b/lightning/src/ln/script.rs index a123de741..3abb334ce 100644 --- a/lightning/src/ln/script.rs +++ b/lightning/src/ln/script.rs @@ -163,6 +163,15 @@ impl Into