From ade99f89c7473664c2540c1c13a6ceeddc8d74be Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Fri, 30 Jul 2021 23:27:58 -0500 Subject: [PATCH] Implement Display for ShutdownScript --- lightning/src/ln/channel.rs | 12 ++++++------ lightning/src/ln/functional_tests.rs | 6 +++--- lightning/src/ln/script.rs | 9 +++++++++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 94ce779ff..554f653b5 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -601,7 +601,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) }); } } @@ -836,7 +836,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 a non-accepted scriptpubkey format. script: ({})", script.to_bytes().to_hex()))), + Err(_) => return Err(ChannelError::Close(format!("Peer is signaling upfront_shutdown but has provided a non-accepted scriptpubkey format: {}", script))), } } }, @@ -853,7 +853,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))); } } @@ -1573,7 +1573,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 a non-accepted scriptpubkey format. script: ({})", script.to_bytes().to_hex()))), + Err(_) => return Err(ChannelError::Close(format!("Peer is signaling upfront_shutdown but has provided a non-accepted scriptpubkey format: {}", script))), } } }, @@ -3281,7 +3281,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))); } Some(shutdown_scriptpubkey) }, @@ -4476,7 +4476,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) }); } Some(shutdown_scriptpubkey) }, diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 32eea83b3..0f47ef63a 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -7542,7 +7542,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 a non-accepted scriptpubkey format. script: (\([A-Fa-f0-9]+\))").unwrap().is_match(&*msg.data)); + assert_eq!(msg.data, "Peer is signaling upfront_shutdown but has provided a non-accepted scriptpubkey format: Script(OP_PUSHNUM_16 OP_PUSHBYTES_2 0028)"); }, _ => panic!("Unexpected event"), } @@ -7560,7 +7560,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 a non-accepted scriptpubkey format. script: (\([A-Fa-f0-9]+\))").unwrap().is_match(&*msg.data)); + assert_eq!(msg.data, "Peer is signaling upfront_shutdown but has provided a non-accepted scriptpubkey format: Script(OP_PUSHNUM_16 OP_PUSHBYTES_2 0028)"); }, _ => panic!("Unexpected event"), } @@ -7587,7 +7587,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 a non-accepted scriptpubkey format. script: (\([A-Fa-f0-9]+\))").unwrap().is_match(&*msg.data)); + assert_eq!(msg.data, "Peer is signaling upfront_shutdown but has provided a non-accepted 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 4ad0af02b..29ee0ad38 100644 --- a/lightning/src/ln/script.rs +++ b/lightning/src/ln/script.rs @@ -157,6 +157,15 @@ impl Into