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.
This commit is contained in:
Tobin Harding 2022-01-25 09:43:17 +11:00
parent 373ea89a9a
commit f5512c4931
1 changed files with 11 additions and 6 deletions

View File

@ -440,12 +440,17 @@ impl Script {
/// Checks whether a script pubkey is a p2pk output
#[inline]
pub fn is_p2pk(&self) -> bool {
(self.0.len() == 67 &&
self.0[0] == opcodes::all::OP_PUSHBYTES_65.into_u8() &&
self.0[66] == opcodes::all::OP_CHECKSIG.into_u8())
|| (self.0.len() == 35 &&
self.0[0] == opcodes::all::OP_PUSHBYTES_33.into_u8() &&
self.0[34] == opcodes::all::OP_CHECKSIG.into_u8())
match self.len() {
67 => {
self.0[0] == opcodes::all::OP_PUSHBYTES_65.into_u8()
&& self.0[66] == opcodes::all::OP_CHECKSIG.into_u8()
}
35 => {
self.0[0] == opcodes::all::OP_PUSHBYTES_33.into_u8()
&& self.0[34] == opcodes::all::OP_CHECKSIG.into_u8()
}
_ => false
}
}
/// Checks whether a script pubkey is a Segregated Witness (segwit) program.