Skip to content

Commit 0d439c7

Browse files
committed
Refactor is_provably_unspendable
Refactor with the aim of making the code easier to read. Code path is covered by current unit tests. Refactor only, no logic changes.
1 parent 7df7d37 commit 0d439c7

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/blockdata/script.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,14 +499,25 @@ impl Script {
499499

500500
/// Check if this is an OP_RETURN output
501501
pub fn is_op_return (&self) -> bool {
502-
!self.0.is_empty() && (opcodes::All::from(self.0[0]) == opcodes::all::OP_RETURN)
502+
match self.0.first() {
503+
Some(b) => *b == opcodes::all::OP_RETURN.into_u8(),
504+
None => false
505+
}
503506
}
504507

505508
/// Whether a script can be proven to have no satisfying input
506509
pub fn is_provably_unspendable(&self) -> bool {
507-
!self.0.is_empty() &&
508-
(opcodes::All::from(self.0[0]).classify(opcodes::ClassifyContext::Legacy) == opcodes::Class::ReturnOp ||
509-
opcodes::All::from(self.0[0]).classify(opcodes::ClassifyContext::Legacy) == opcodes::Class::IllegalOp)
510+
use blockdata::opcodes::Class::{ReturnOp, IllegalOp};
511+
512+
match self.0.first() {
513+
Some(b) => {
514+
let first = opcodes::All::from(*b);
515+
let class = first.classify(opcodes::ClassifyContext::Legacy);
516+
517+
class == ReturnOp || class == IllegalOp
518+
},
519+
None => false,
520+
}
510521
}
511522

512523
/// Gets the minimum value an output with this script should have in order to be

0 commit comments

Comments
 (0)