Skip to content

Commit dfb1504

Browse files
committed
Implement Display for ShutdownScript
1 parent c31cf99 commit dfb1504

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

609609
if let Some(shutdown_scriptpubkey) = &shutdown_scriptpubkey {
610610
if !shutdown_scriptpubkey.is_compatible(their_features) {
611-
return Err(APIError::APIMisuseError { err: format!("Provided a scriptpubkey format not accepted by peer. script: ({})", shutdown_scriptpubkey.clone().into_inner().to_bytes().to_hex()) });
611+
return Err(APIError::APIMisuseError { err: format!("Provided a scriptpubkey format not accepted by peer: {}", shutdown_scriptpubkey) });
612612
}
613613
}
614614

@@ -843,7 +843,7 @@ impl<Signer: Sign> Channel<Signer> {
843843
} else {
844844
match ShutdownScript::try_from((script.clone(), their_features)) {
845845
Ok(shutdown_script) => Some(shutdown_script.into_inner()),
846-
Err(_) => return Err(ChannelError::Close(format!("Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format. script: ({})", script.to_bytes().to_hex()))),
846+
Err(_) => return Err(ChannelError::Close(format!("Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: {}", script))),
847847
}
848848
}
849849
},
@@ -860,7 +860,7 @@ impl<Signer: Sign> Channel<Signer> {
860860

861861
if let Some(shutdown_scriptpubkey) = &shutdown_scriptpubkey {
862862
if !shutdown_scriptpubkey.is_compatible(&their_features) {
863-
return Err(ChannelError::Close(format!("Provided a scriptpubkey format not accepted by peer. script: ({})", shutdown_scriptpubkey.clone().into_inner().to_bytes().to_hex())));
863+
return Err(ChannelError::Close(format!("Provided a scriptpubkey format not accepted by peer: {}", shutdown_scriptpubkey)));
864864
}
865865
}
866866

@@ -1587,7 +1587,7 @@ impl<Signer: Sign> Channel<Signer> {
15871587
} else {
15881588
match ShutdownScript::try_from((script.clone(), their_features)) {
15891589
Ok(shutdown_script) => Some(shutdown_script.into_inner()),
1590-
Err(_) => return Err(ChannelError::Close(format!("Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format. script: ({})", script.to_bytes().to_hex()))),
1590+
Err(_) => return Err(ChannelError::Close(format!("Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: {}", script))),
15911591
}
15921592
}
15931593
},
@@ -3295,7 +3295,7 @@ impl<Signer: Sign> Channel<Signer> {
32953295
assert!(send_shutdown);
32963296
let shutdown_scriptpubkey = keys_provider.get_shutdown_scriptpubkey();
32973297
if !shutdown_scriptpubkey.is_compatible(their_features) {
3298-
return Err(ChannelError::Close(format!("Provided a scriptpubkey format not accepted by peer. script: ({})", shutdown_scriptpubkey.clone().into_inner().to_bytes().to_hex())));
3298+
return Err(ChannelError::Close(format!("Provided a scriptpubkey format not accepted by peer: {}", shutdown_scriptpubkey)));
32993299
}
33003300
self.shutdown_scriptpubkey = Some(shutdown_scriptpubkey);
33013301
true
@@ -4487,7 +4487,7 @@ impl<Signer: Sign> Channel<Signer> {
44874487
None => {
44884488
let shutdown_scriptpubkey = keys_provider.get_shutdown_scriptpubkey();
44894489
if !shutdown_scriptpubkey.is_compatible(their_features) {
4490-
return Err(APIError::APIMisuseError { err: format!("Provided a scriptpubkey format not accepted by peer. script: ({})", shutdown_scriptpubkey.clone().into_inner().to_bytes().to_hex()) });
4490+
return Err(APIError::APIMisuseError { err: format!("Provided a scriptpubkey format not accepted by peer: {}", shutdown_scriptpubkey) });
44914491
}
44924492
self.shutdown_scriptpubkey = Some(shutdown_scriptpubkey);
44934493
true

lightning/src/ln/functional_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7548,7 +7548,7 @@ fn test_unsupported_anysegwit_upfront_shutdown_script() {
75487548
match events[0] {
75497549
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => {
75507550
assert_eq!(node_id, nodes[0].node.get_our_node_id());
7551-
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));
7551+
assert_eq!(msg.data, "Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: Script(OP_PUSHNUM_16 OP_PUSHBYTES_2 0028)");
75527552
},
75537553
_ => panic!("Unexpected event"),
75547554
}
@@ -7566,7 +7566,7 @@ fn test_unsupported_anysegwit_upfront_shutdown_script() {
75667566
match events[0] {
75677567
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => {
75687568
assert_eq!(node_id, nodes[1].node.get_our_node_id());
7569-
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));
7569+
assert_eq!(msg.data, "Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: Script(OP_PUSHNUM_16 OP_PUSHBYTES_2 0028)");
75707570
},
75717571
_ => panic!("Unexpected event"),
75727572
}
@@ -7593,7 +7593,7 @@ fn test_invalid_upfront_shutdown_script() {
75937593
match events[0] {
75947594
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => {
75957595
assert_eq!(node_id, nodes[0].node.get_our_node_id());
7596-
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));
7596+
assert_eq!(msg.data, "Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: Script(OP_0 OP_PUSHBYTES_2 0000)");
75977597
},
75987598
_ => panic!("Unexpected event"),
75997599
}

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)