Skip to content

Commit 6c596f5

Browse files
committed
Refactor is_p2pkh
Refactor with the aim of simplifying `is_p2kh`. This function is covered sufficiently by current unit tests. Refactor only, no logic changes.
1 parent 0b91de1 commit 6c596f5

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/blockdata/script.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,17 @@ impl Script {
440440
/// Checks whether a script pubkey is a p2pk output
441441
#[inline]
442442
pub fn is_p2pk(&self) -> bool {
443-
(self.0.len() == 67 &&
444-
self.0[0] == opcodes::all::OP_PUSHBYTES_65.into_u8() &&
445-
self.0[66] == opcodes::all::OP_CHECKSIG.into_u8())
446-
|| (self.0.len() == 35 &&
447-
self.0[0] == opcodes::all::OP_PUSHBYTES_33.into_u8() &&
448-
self.0[34] == opcodes::all::OP_CHECKSIG.into_u8())
443+
match self.len() {
444+
67 => {
445+
self.0[0] == opcodes::all::OP_PUSHBYTES_65.into_u8()
446+
&& self.0[66] == opcodes::all::OP_CHECKSIG.into_u8()
447+
}
448+
35 => {
449+
self.0[0] == opcodes::all::OP_PUSHBYTES_33.into_u8()
450+
&& self.0[34] == opcodes::all::OP_CHECKSIG.into_u8()
451+
}
452+
_ => false
453+
}
449454
}
450455

451456
/// Checks whether a script pubkey is a Segregated Witness (segwit) program.

0 commit comments

Comments
 (0)