@@ -20,10 +20,14 @@ pub const NUMS_H: [u8; 32] = [
2020
2121#[ derive( Debug , Clone , Copy , PartialEq ) ]
2222pub enum SpInputs {
23- P2TR ,
24- P2WPKH ,
25- WrappedSegwit ,
26- P2PKH ,
23+ /// The input spends a P2TR output.
24+ Tr ,
25+ /// The input spends a P2WPKH output.
26+ Wpkh ,
27+ /// The input spends a P2WPKH output nested in a P2SH.
28+ ShWpkh ,
29+ /// The inputs spends a P2PKH output.
30+ Pkh ,
2731}
2832
2933pub fn tag_txin ( txin : & TxIn , script_pubkey : & ScriptBuf ) -> Option < SpInputs > {
@@ -36,12 +40,12 @@ pub fn tag_txin(txin: &TxIn, script_pubkey: &ScriptBuf) -> Option<SpInputs> {
3640 . redeem_script ( )
3741 . filter ( |script_pubkey| script_pubkey. is_p2wpkh ( ) )
3842 // if not P2SH-P2WPKH return None
39- . map ( |_| WrappedSegwit ) ,
43+ . map ( |_| ShWpkh ) ,
4044 // Native segwit
4145 ( false , true ) => {
4246 // P2WPKH
4347 if script_pubkey. is_p2wpkh ( ) {
44- Some ( P2WPKH )
48+ Some ( Wpkh )
4549 } else {
4650 // P2TR
4751 script_pubkey
@@ -51,13 +55,13 @@ pub fn tag_txin(txin: &TxIn, script_pubkey: &ScriptBuf) -> Option<SpInputs> {
5155 . taproot_control_block ( )
5256 . filter ( |control_block| control_block[ 1 ..33 ] == NUMS_H )
5357 // if P2TR has no internal key return None
54- . map_or ( Some ( P2TR ) , |_| None )
58+ . map_or ( Some ( Tr ) , |_| None )
5559 } )
5660 . flatten ( )
5761 }
5862 }
5963 // No witness, legacy P2PKH
60- ( true , false ) if script_pubkey. is_p2pkh ( ) => Some ( P2PKH ) ,
64+ ( true , false ) if script_pubkey. is_p2pkh ( ) => Some ( Pkh ) ,
6165 // All other cases
6266 _ => None ,
6367 }
@@ -166,7 +170,7 @@ mod tests {
166170
167171 let tagged_input = tag_txin ( & txin, & script_pubkey) ;
168172
169- assert_eq ! ( Some ( SpInputs :: WrappedSegwit ) , tagged_input) ;
173+ assert_eq ! ( Some ( SpInputs :: ShWpkh ) , tagged_input) ;
170174 }
171175
172176 #[ test]
@@ -217,7 +221,7 @@ mod tests {
217221
218222 let tagged_input = tag_txin ( & txin, & script_pubkey) ;
219223
220- assert_eq ! ( Some ( SpInputs :: P2TR ) , tagged_input) ;
224+ assert_eq ! ( Some ( SpInputs :: Tr ) , tagged_input) ;
221225 }
222226
223227 #[ test]
@@ -273,7 +277,7 @@ mod tests {
273277
274278 let tagged_input = tag_txin ( & txin, & script_pubkey) ;
275279
276- assert_eq ! ( Some ( SpInputs :: P2WPKH ) , tagged_input) ;
280+ assert_eq ! ( Some ( SpInputs :: Wpkh ) , tagged_input) ;
277281 }
278282
279283 #[ test]
@@ -322,7 +326,7 @@ mod tests {
322326
323327 let tagged_input = tag_txin ( & txin, & script_pubkey) ;
324328
325- assert_eq ! ( Some ( SpInputs :: P2PKH ) , tagged_input) ;
329+ assert_eq ! ( Some ( SpInputs :: Pkh ) , tagged_input) ;
326330 }
327331
328332 #[ test]
0 commit comments