Skip to content

Commit 5ad6962

Browse files
committed
Implement Display for ShutdownScript
1 parent edf8f7d commit 5ad6962

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

lightning/src/ln/channel.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ impl<Signer: Sign> Channel<Signer> {
602602

603603
if let Some(shutdown_scriptpubkey) = &shutdown_scriptpubkey {
604604
if !shutdown_scriptpubkey.is_compatible(their_features) {
605-
return Err(APIError::APIMisuseError { err: format!("Provided a scriptpubkey format not accepted by peer. script: ({})", shutdown_scriptpubkey.clone().into_inner().to_bytes().to_hex()) });
605+
return Err(APIError::APIMisuseError { err: format!("Provided a scriptpubkey format not accepted by peer: {}", shutdown_scriptpubkey) });
606606
}
607607
}
608608

@@ -837,7 +837,7 @@ impl<Signer: Sign> Channel<Signer> {
837837
} else {
838838
match ShutdownScript::try_from((script.clone(), their_features)) {
839839
Ok(shutdown_script) => Some(shutdown_script.into_inner()),
840-
Err(_) => return Err(ChannelError::Close(format!("Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format. script: ({})", script.to_bytes().to_hex()))),
840+
Err(_) => return Err(ChannelError::Close(format!("Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: {}", script))),
841841
}
842842
}
843843
},
@@ -854,7 +854,7 @@ impl<Signer: Sign> Channel<Signer> {
854854

855855
if let Some(shutdown_scriptpubkey) = &shutdown_scriptpubkey {
856856
if !shutdown_scriptpubkey.is_compatible(&their_features) {
857-
return Err(ChannelError::Close(format!("Provided a scriptpubkey format not accepted by peer. script: ({})", shutdown_scriptpubkey.clone().into_inner().to_bytes().to_hex())));
857+
return Err(ChannelError::Close(format!("Provided a scriptpubkey format not accepted by peer: {}", shutdown_scriptpubkey)));
858858
}
859859
}
860860

@@ -1577,7 +1577,7 @@ impl<Signer: Sign> Channel<Signer> {
15771577
} else {
15781578
match ShutdownScript::try_from((script.clone(), their_features)) {
15791579
Ok(shutdown_script) => Some(shutdown_script.into_inner()),
1580-
Err(_) => return Err(ChannelError::Close(format!("Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format. script: ({})", script.to_bytes().to_hex()))),
1580+
Err(_) => return Err(ChannelError::Close(format!("Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: {}", script))),
15811581
}
15821582
}
15831583
},
@@ -3285,7 +3285,7 @@ impl<Signer: Sign> Channel<Signer> {
32853285
assert!(send_shutdown);
32863286
let shutdown_scriptpubkey = keys_provider.get_shutdown_scriptpubkey();
32873287
if !shutdown_scriptpubkey.is_compatible(their_features) {
3288-
return Err(ChannelError::Close(format!("Provided a scriptpubkey format not accepted by peer. script: ({})", shutdown_scriptpubkey.clone().into_inner().to_bytes().to_hex())));
3288+
return Err(ChannelError::Close(format!("Provided a scriptpubkey format not accepted by peer: {}", shutdown_scriptpubkey)));
32893289
}
32903290
self.shutdown_scriptpubkey = Some(shutdown_scriptpubkey);
32913291
true
@@ -4477,7 +4477,7 @@ impl<Signer: Sign> Channel<Signer> {
44774477
None => {
44784478
let shutdown_scriptpubkey = keys_provider.get_shutdown_scriptpubkey();
44794479
if !shutdown_scriptpubkey.is_compatible(their_features) {
4480-
return Err(APIError::APIMisuseError { err: format!("Provided a scriptpubkey format not accepted by peer. script: ({})", shutdown_scriptpubkey.clone().into_inner().to_bytes().to_hex()) });
4480+
return Err(APIError::APIMisuseError { err: format!("Provided a scriptpubkey format not accepted by peer: {}", shutdown_scriptpubkey) });
44814481
}
44824482
self.shutdown_scriptpubkey = Some(shutdown_scriptpubkey);
44834483
true

lightning/src/ln/functional_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7543,7 +7543,7 @@ fn test_unsupported_anysegwit_upfront_shutdown_script() {
75437543
match events[0] {
75447544
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => {
75457545
assert_eq!(node_id, nodes[0].node.get_our_node_id());
7546-
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));
7546+
assert_eq!(msg.data, "Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: Script(OP_PUSHNUM_16 OP_PUSHBYTES_2 0028)");
75477547
},
75487548
_ => panic!("Unexpected event"),
75497549
}
@@ -7561,7 +7561,7 @@ fn test_unsupported_anysegwit_upfront_shutdown_script() {
75617561
match events[0] {
75627562
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => {
75637563
assert_eq!(node_id, nodes[1].node.get_our_node_id());
7564-
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));
7564+
assert_eq!(msg.data, "Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: Script(OP_PUSHNUM_16 OP_PUSHBYTES_2 0028)");
75657565
},
75667566
_ => panic!("Unexpected event"),
75677567
}
@@ -7588,7 +7588,7 @@ fn test_invalid_upfront_shutdown_script() {
75887588
match events[0] {
75897589
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => {
75907590
assert_eq!(node_id, nodes[0].node.get_our_node_id());
7591-
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));
7591+
assert_eq!(msg.data, "Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: Script(OP_0 OP_PUSHBYTES_2 0000)");
75927592
},
75937593
_ => panic!("Unexpected event"),
75947594
}

lightning/src/ln/script.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ impl Into<Script> for ShutdownScript {
163163
}
164164
}
165165

166+
impl core::fmt::Display for ShutdownScript{
167+
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
168+
match &self.0 {
169+
ShutdownScriptImpl::Legacy(_) => self.clone().into_inner().fmt(f),
170+
ShutdownScriptImpl::Bolt2(script) => script.fmt(f),
171+
}
172+
}
173+
}
174+
166175
#[cfg(test)]
167176
mod shutdown_script_tests {
168177
use super::ShutdownScript;

0 commit comments

Comments
 (0)