Skip to content

Commit

Permalink
check if output is OP_RETURN
Browse files Browse the repository at this point in the history
  • Loading branch information
tamasblummer committed Jun 23, 2018
1 parent 2ff5f8e commit caeadb4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/blockdata/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ impl Script {
self.0[1] == opcodes::All::OP_PUSHBYTES_20 as u8
}

/// Check if this is an OP_RETURN output
pub fn is_op_return (&self) -> bool {
!self.0.is_empty() && (opcodes::All::from(self.0[0]) == opcodes::All::OP_RETURN)
}

/// Whether a script can be proven to have no satisfying input
pub fn is_provably_unspendable(&self) -> bool {
!self.0.is_empty() && (opcodes::All::from(self.0[0]).classify() == opcodes::Class::ReturnOp ||
Expand Down Expand Up @@ -691,6 +696,13 @@ mod test {
assert_eq!(hex_script!("6aa9149eb21980dc9d413d8eac27314938b9da920ee53e87").is_provably_unspendable(), true);
}

#[test]
fn op_return_test() {
assert_eq!(hex_script!("6aa9149eb21980dc9d413d8eac27314938b9da920ee53e87").is_op_return(), true);
assert_eq!(hex_script!("76a914ee61d57ab51b9d212335b1dba62794ac20d2bcf988ac").is_op_return(), false);
assert_eq!(hex_script!("").is_op_return(), false);
}

#[test]
fn script_json_serialize() {
use strason;
Expand Down

0 comments on commit caeadb4

Please sign in to comment.