Add `first_push_as_number` function to contracthash templates

This is a bit of a hack to let users of the contracthash API to determine
how many sigs are required when signing a multisig contract.
This commit is contained in:
Andrew Poelstra 2016-03-29 17:24:34 +00:00
parent dce0cc65d2
commit f906c2fddd
2 changed files with 18 additions and 1 deletions

View File

@ -1,7 +1,7 @@
[package]
name = "bitcoin"
version = "0.5.5"
version = "0.5.6"
authors = ["Andrew Poelstra <apoelstra@wpsoftware.net>"]
license = "CC0-1.0"
homepage = "https://github.com/apoelstra/rust-bitcoin/"

View File

@ -135,6 +135,23 @@ impl Template {
pub fn required_keys(&self) -> usize {
self.0.iter().filter(|e| **e == TemplateElement::Key).count()
}
/// If the first push in the template is a number, return this number. For the
/// common case of standard multisig templates, such a number will exist and
/// will represent the number of signatures that are required for the script
/// to pass.
pub fn first_push_as_number(&self) -> Option<usize> {
if !self.0.is_empty() {
if let TemplateElement::Op(op) = self.0[0] {
if let opcodes::Class::PushNum(n) = op.classify() {
if n >= 0 {
return Some(n as usize);
}
}
}
}
None
}
}
impl<'a> From<&'a [u8]> for Template {