@@ -90,22 +90,30 @@ pub(crate) struct DebugTx<'a>(pub &'a Transaction);
90
90
impl < ' a > core:: fmt:: Display for DebugTx < ' a > {
91
91
fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> Result < ( ) , core:: fmt:: Error > {
92
92
if self . 0 . input . len ( ) >= 1 && self . 0 . input . iter ( ) . any ( |i| !i. witness . is_empty ( ) ) {
93
- if self . 0 . input . len ( ) == 1 && self . 0 . input [ 0 ] . witness . last ( ) . unwrap ( ) . len ( ) == 71 &&
93
+ let witness_script_len = self . 0 . input [ 0 ] . witness . last ( ) . unwrap ( ) . len ( ) ;
94
+ let is_offered_htlc_script = HTLCType :: scriptlen_to_htlctype ( witness_script_len, false ) == Some ( HTLCType :: OfferedHTLC ) ||
95
+ HTLCType :: scriptlen_to_htlctype ( witness_script_len, true ) == Some ( HTLCType :: OfferedHTLC ) ;
96
+ let is_accepted_htlc_script = HTLCType :: scriptlen_to_htlctype ( witness_script_len, false ) == Some ( HTLCType :: AcceptedHTLC ) ||
97
+ HTLCType :: scriptlen_to_htlctype ( witness_script_len, true ) == Some ( HTLCType :: AcceptedHTLC ) ;
98
+ if self . 0 . input . len ( ) == 1 && witness_script_len == 71 &&
94
99
( self . 0 . input [ 0 ] . sequence . 0 >> 8 * 3 ) as u8 == 0x80 {
95
100
write ! ( f, "commitment tx " ) ?;
96
- } else if self . 0 . input . len ( ) == 1 && self . 0 . input [ 0 ] . witness . last ( ) . unwrap ( ) . len ( ) == 71 {
101
+ } else if self . 0 . input . len ( ) == 1 && witness_script_len == 71 {
97
102
write ! ( f, "closing tx " ) ?;
98
- } else if self . 0 . input . len ( ) == 1 && HTLCType :: scriptlen_to_htlctype ( self . 0 . input [ 0 ] . witness . last ( ) . unwrap ( ) . len ( ) ) == Some ( HTLCType :: OfferedHTLC ) &&
99
- self . 0 . input [ 0 ] . witness . len ( ) == 5 {
103
+ } else if is_offered_htlc_script && self . 0 . input [ 0 ] . witness . len ( ) == 5 {
100
104
write ! ( f, "HTLC-timeout tx " ) ?;
101
- } else if self . 0 . input . len ( ) == 1 && HTLCType :: scriptlen_to_htlctype ( self . 0 . input [ 0 ] . witness . last ( ) . unwrap ( ) . len ( ) ) == Some ( HTLCType :: AcceptedHTLC ) &&
102
- self . 0 . input [ 0 ] . witness . len ( ) == 5 {
105
+ } else if is_accepted_htlc_script && self . 0 . input [ 0 ] . witness . len ( ) == 5 {
103
106
write ! ( f, "HTLC-success tx " ) ?;
104
107
} else {
105
108
for inp in & self . 0 . input {
106
109
if !inp. witness . is_empty ( ) {
107
- if HTLCType :: scriptlen_to_htlctype ( inp. witness . last ( ) . unwrap ( ) . len ( ) ) == Some ( HTLCType :: OfferedHTLC ) { write ! ( f, "preimage-" ) ?; break }
108
- else if HTLCType :: scriptlen_to_htlctype ( inp. witness . last ( ) . unwrap ( ) . len ( ) ) == Some ( HTLCType :: AcceptedHTLC ) { write ! ( f, "timeout-" ) ?; break }
110
+ let witness_script_len = inp. witness . last ( ) . unwrap ( ) . len ( ) ;
111
+ let is_offered_htlc_script = HTLCType :: scriptlen_to_htlctype ( witness_script_len, false ) == Some ( HTLCType :: OfferedHTLC ) ||
112
+ HTLCType :: scriptlen_to_htlctype ( witness_script_len, true ) == Some ( HTLCType :: OfferedHTLC ) ;
113
+ let is_accepted_htlc_script = HTLCType :: scriptlen_to_htlctype ( witness_script_len, false ) == Some ( HTLCType :: AcceptedHTLC ) ||
114
+ HTLCType :: scriptlen_to_htlctype ( witness_script_len, true ) == Some ( HTLCType :: AcceptedHTLC ) ;
115
+ if is_offered_htlc_script { write ! ( f, "preimage-" ) ?; break }
116
+ else if is_accepted_htlc_script { write ! ( f, "timeout-" ) ?; break }
109
117
}
110
118
}
111
119
write ! ( f, "tx " ) ?;
0 commit comments