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:
parent
dce0cc65d2
commit
f906c2fddd
|
@ -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/"
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue