Skip to content

Commit 260f269

Browse files
committed
Implement Display for ShutdownScript
1 parent 46faf93 commit 260f269

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
@@ -601,7 +601,7 @@ impl<Signer: Sign> Channel<Signer> {
601601

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

@@ -836,7 +836,7 @@ impl<Signer: Sign> Channel<Signer> {
836836
} else {
837837
match ShutdownScript::try_from((script.clone(), &their_features)) {
838838
Ok(shutdown_script) => Some(shutdown_script.into_inner()),
839-
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()))),
839+
Err(_) => return Err(ChannelError::Close(format!("Peer is signaling upfront_shutdown but has provided a non-accepted scriptpubkey format: {}", script))),
840840
}
841841
}
842842
},
@@ -853,7 +853,7 @@ impl<Signer: Sign> Channel<Signer> {
853853

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

@@ -1573,7 +1573,7 @@ impl<Signer: Sign> Channel<Signer> {
15731573
} else {
15741574
match ShutdownScript::try_from((script.clone(), &their_features)) {
15751575
Ok(shutdown_script) => Some(shutdown_script.into_inner()),
1576-
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()))),
1576+
Err(_) => return Err(ChannelError::Close(format!("Peer is signaling upfront_shutdown but has provided a non-accepted scriptpubkey format: {}", script))),
15771577
}
15781578
}
15791579
},
@@ -3281,7 +3281,7 @@ impl<Signer: Sign> Channel<Signer> {
32813281
assert!(send_shutdown);
32823282
let shutdown_scriptpubkey = keys_provider.get_shutdown_scriptpubkey();
32833283
if !shutdown_scriptpubkey.is_compatible(their_features) {
3284-
return Err(ChannelError::Close(format!("Provided a scriptpubkey format not accepted by peer. script: ({})", shutdown_scriptpubkey.clone().into_inner().to_bytes().to_hex())));
3284+
return Err(ChannelError::Close(format!("Provided a scriptpubkey format not accepted by peer: {}", shutdown_scriptpubkey)));
32853285
}
32863286
Some(shutdown_scriptpubkey)
32873287
},
@@ -4476,7 +4476,7 @@ impl<Signer: Sign> Channel<Signer> {
44764476
None => {
44774477
let shutdown_scriptpubkey = keys_provider.get_shutdown_scriptpubkey();
44784478
if !shutdown_scriptpubkey.is_compatible(their_features) {
4479-
return Err(APIError::APIMisuseError { err: format!("Provided a scriptpubkey format not accepted by peer. script: ({})", shutdown_scriptpubkey.clone().into_inner().to_bytes().to_hex()) });
4479+
return Err(APIError::APIMisuseError { err: format!("Provided a scriptpubkey format not accepted by peer: {}", shutdown_scriptpubkey) });
44804480
}
44814481
Some(shutdown_scriptpubkey)
44824482
},

lightning/src/ln/functional_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7542,7 +7542,7 @@ fn test_unsupported_anysegwit_upfront_shutdown_script() {
75427542
match events[0] {
75437543
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => {
75447544
assert_eq!(node_id, nodes[0].node.get_our_node_id());
7545-
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));
7545+
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)");
75467546
},
75477547
_ => panic!("Unexpected event"),
75487548
}
@@ -7560,7 +7560,7 @@ fn test_unsupported_anysegwit_upfront_shutdown_script() {
75607560
match events[0] {
75617561
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => {
75627562
assert_eq!(node_id, nodes[1].node.get_our_node_id());
7563-
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));
7563+
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)");
75647564
},
75657565
_ => panic!("Unexpected event"),
75667566
}
@@ -7587,7 +7587,7 @@ fn test_invalid_upfront_shutdown_script() {
75877587
match events[0] {
75887588
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => {
75897589
assert_eq!(node_id, nodes[0].node.get_our_node_id());
7590-
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));
7590+
assert_eq!(msg.data, "Peer is signaling upfront_shutdown but has provided a non-accepted scriptpubkey format: Script(OP_0 OP_PUSHBYTES_2 0000)");
75917591
},
75927592
_ => panic!("Unexpected event"),
75937593
}

lightning/src/ln/script.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ impl Into<Script> for ShutdownScript {
157157
}
158158
}
159159

160+
impl core::fmt::Display for ShutdownScript{
161+
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
162+
match &self.0 {
163+
ShutdownScriptImpl::Legacy(_) => self.clone().into_inner().fmt(f),
164+
ShutdownScriptImpl::Bolt2(script) => script.fmt(f),
165+
}
166+
}
167+
}
168+
160169
#[cfg(test)]
161170
mod shutdown_script_tests {
162171
use super::ShutdownScript;

0 commit comments

Comments
 (0)