Skip to content

Commit

Permalink
Implement Segwit addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
tamasblummer committed Mar 20, 2018
1 parent b15438b commit 1a87244
Show file tree
Hide file tree
Showing 6 changed files with 355 additions and 172 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,5 @@ See Transaction::verify and Script::verify methods.

* Add bech32 support

* Support segwit address types

16 changes: 16 additions & 0 deletions src/blockdata/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,14 @@ impl Script {
self.0[24] == opcodes::All::OP_CHECKSIG as u8
}

/// Checks whether a script pubkey is a p2pkh output
#[inline]
pub fn is_p2pk(&self) -> bool {
self.0.len() == 67 &&
self.0[0] == opcodes::All::OP_PUSHBYTES_65 as u8 &&
self.0[66] == opcodes::All::OP_CHECKSIG as u8
}

/// Checks whether a script pubkey is a p2wsh output
#[inline]
pub fn is_v0_p2wsh(&self) -> bool {
Expand All @@ -336,6 +344,14 @@ impl Script {
self.0[1] == opcodes::All::OP_PUSHBYTES_32 as u8
}

/// Checks whether a script pubkey is a p2wpkh output
#[inline]
pub fn is_v0_p2wpkh(&self) -> bool {
self.0.len() == 22 &&
self.0[0] == opcodes::All::OP_PUSHBYTES_0 as u8 &&
self.0[1] == opcodes::All::OP_PUSHBYTES_20 as u8
}

/// 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
Loading

0 comments on commit 1a87244

Please sign in to comment.