Skip to content

Commit 93cd3a5

Browse files
committed
Implement Display for ShutdownScript
1 parent a802c89 commit 93cd3a5

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 a non-accepted scriptpubkey format. script: ({})", script.to_bytes().to_hex()))),
840+
Err(_) => return Err(ChannelError::Close(format!("Peer is signaling upfront_shutdown but has provided a non-accepted 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

@@ -1574,7 +1574,7 @@ impl<Signer: Sign> Channel<Signer> {
15741574
} else {
15751575
match ShutdownScript::try_from((script.clone(), their_features)) {
15761576
Ok(shutdown_script) => Some(shutdown_script.into_inner()),
1577-
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()))),
1577+
Err(_) => return Err(ChannelError::Close(format!("Peer is signaling upfront_shutdown but has provided a non-accepted scriptpubkey format: {}", script))),
15781578
}
15791579
}
15801580
},
@@ -3282,7 +3282,7 @@ impl<Signer: Sign> Channel<Signer> {
32823282
assert!(send_shutdown);
32833283
let shutdown_scriptpubkey = keys_provider.get_shutdown_scriptpubkey();
32843284
if !shutdown_scriptpubkey.is_compatible(their_features) {
3285-
return Err(ChannelError::Close(format!("Provided a scriptpubkey format not accepted by peer. script: ({})", shutdown_scriptpubkey.clone().into_inner().to_bytes().to_hex())));
3285+
return Err(ChannelError::Close(format!("Provided a scriptpubkey format not accepted by peer: {}", shutdown_scriptpubkey)));
32863286
}
32873287
self.shutdown_scriptpubkey = Some(shutdown_scriptpubkey);
32883288
true
@@ -4474,7 +4474,7 @@ impl<Signer: Sign> Channel<Signer> {
44744474
None => {
44754475
let shutdown_scriptpubkey = keys_provider.get_shutdown_scriptpubkey();
44764476
if !shutdown_scriptpubkey.is_compatible(their_features) {
4477-
return Err(APIError::APIMisuseError { err: format!("Provided a scriptpubkey format not accepted by peer. script: ({})", shutdown_scriptpubkey.clone().into_inner().to_bytes().to_hex()) });
4477+
return Err(APIError::APIMisuseError { err: format!("Provided a scriptpubkey format not accepted by peer: {}", shutdown_scriptpubkey) });
44784478
}
44794479
self.shutdown_scriptpubkey = Some(shutdown_scriptpubkey);
44804480
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 a non-accepted 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 a non-accepted 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 a non-accepted 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 a non-accepted 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 a non-accepted 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 a non-accepted 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)